Skip to main content
Custom converters allow you to extend MarkItDown to support additional file formats. By implementing the DocumentConverter base class, you can add conversion logic for any file type.

DocumentConverter Base Class

All converters inherit from the DocumentConverter abstract base class located in _base_converter.py:42.

Creating a Custom Converter

Complete Example

Here’s a complete example based on the plain text converter (converters/_plain_text_converter.py:33):

StreamInfo Object

The StreamInfo dataclass (_stream_info.py:6) provides metadata about the file being converted:

DocumentConverterResult

The DocumentConverterResult class (_base_converter.py:5) wraps the conversion output:

Converter Priority

When registering converters, you can specify priority to control the order they’re tried:
Priority values (_markitdown.py:54):
  • 0.0 - PRIORITY_SPECIFIC_FILE_FORMAT (specific converters like PDF, DOCX)
  • 10.0 - PRIORITY_GENERIC_FILE_FORMAT (generic converters like HTML, plain text)
Lower values are tried first. Converters with the same priority maintain registration order (most recent first).

Best Practices

Stream Position Management: Always reset file_stream position after reading in accepts(). The convert() method expects the stream to be at the original position.
Charset Detection: Use stream_info.charset when available, or employ libraries like charset_normalizer to detect encoding automatically.
Dependency Handling: For optional dependencies, catch import errors gracefully and raise MissingDependencyException during conversion if needed.

Next Steps

Plugin Development

Package your converter as a reusable plugin

Configuration

Learn about MarkItDown configuration options