Skip to main content
The DocumentConverter class is the abstract base class for all document converters in MarkItDown. Custom converters must inherit from this class and implement the accepts() and convert() methods.

Overview

A converter’s lifecycle consists of two phases:
  1. Acceptance - The accepts() method determines if the converter can handle a given file
  2. Conversion - The convert() method performs the actual conversion to Markdown

Methods

accepts()

Determine if the converter can handle the given document.
BinaryIO
required
The file-like object to check. Must support seek(), tell(), and read() methods.
StreamInfo
required
Metadata about the file including mimetype, extension, charset, URL, and filename.
dict
Additional keyword arguments that may be used by the converter.
bool
Returns True if the converter can handle this document, False otherwise.

Important Notes

The accepts() method must NOT change the file stream position. If you need to read from the stream, save the position first and restore it before returning.

Decision Criteria

The accepts() method typically checks:
  • Extension: stream_info.extension (e.g., .pdf, .docx)
  • MIME type: stream_info.mimetype (e.g., application/pdf)
  • URL: stream_info.url (for site-specific converters like Wikipedia, YouTube)
  • Filename: stream_info.filename (for well-known files like Dockerfile, Makefile)
  • File content: Read file signature/magic bytes (with position reset)

convert()

Convert the document to Markdown.
BinaryIO
required
The file-like object to convert. Must support seek(), tell(), and read() methods.
StreamInfo
required
Metadata about the file.
dict
Additional options for the converter. Common options include:
  • llm_client: LLM client for AI-powered conversion
  • llm_model: Model name for LLM
  • exiftool_path: Path to exiftool binary
  • url: Source URL (deprecated, use stream_info.url)
  • file_extension: File extension (deprecated, use stream_info.extension)
DocumentConverterResult
The conversion result containing the Markdown text and optional metadata.

Exceptions

The convert() method may raise:
  • FileConversionException - When the converter recognizes the format but conversion fails
  • MissingDependencyException - When a required dependency is not installed
  • Other exceptions for unexpected errors

Creating a Custom Converter

Basic Example

Advanced Example with Content Inspection

URL-Based Converter

Registering Custom Converters

After creating a converter, register it with MarkItDown:

Priority Guidelines

Choose the appropriate priority for your converter:
  • PRIORITY_SPECIFIC_FILE_FORMAT (0.0) - For specific formats (.docx, .pdf) or specific sites (Wikipedia, GitHub)
  • PRIORITY_GENERIC_FILE_FORMAT (10.0) - For catch-all converters (text/*, generic HTML)
Lower priority values are tried first. Converters with the same priority are tried in reverse registration order (most recently registered first).

Best Practices

Stream Position Management

Always restore the file stream position in accepts() if you read from it.

Error Handling

Raise appropriate exceptions:

Metadata Handling

Return complete metadata when available:

See Also