项目文件夹

文件
chienyuanchang 6439057593 Fix typos and formatting in comments, docstrings, and markdown files
Comment/docstring typo fixes:
- _base_converter.py: fix 'steam_info' -> 'stream_info', missing 'on',
  duplicated 'MUST be reset', 'advances' -> 'advance',
  'used to in cases' -> 'used in cases', 'charset, set' -> 'charset, etc.'
- _markitdown.py: 'legaxy' -> 'legacy', 'User' -> 'Use' in DEPRECATED
  docstring, second 'PRIORITY_SPECIFIC_FILE_FORMAT (== 10)' ->
  'PRIORITY_GENERIC_FILE_FORMAT (== 10)', 'Plugins converters' ->
  'Plugin converters'
- __main__.py: 'e.g,' -> 'e.g.,' in --charset help
- _exceptions.py: 'an a single' -> 'a single'
- _docx_converter.py, _epub_converter.py: 'e.g.m headings' ->
  'e.g., headings'
- _epub_converter.py: remove stray closing triple-quote in comment
- _outlook_msg_converter.py: 'Brue force' -> 'Brute force'
- _markdownify.py: 'Javascript' -> 'JavaScript'
- _bing_serp_converter.py: remove stray '"' in Base64URL comment
- sample plugin _plugin.py: 'RTF file to in the simplest' ->
  'RTF file in the simplest'; 'into an str using hte' ->
  'into a str using the'

Markdown formatting fixes:
- README.md: 'Youtube URLs' -> 'YouTube URLs'
- markitdown-mcp/README.md: remove trailing tab characters after
  ```bash code fences; convert tab-indented JSON array elements to
  8-space indentation for consistency
- markitdown-sample-plugin/README.md: 'Next, implement' -> 'First,
  implement' for the initial step (no prior step exists); normalize
  tab-indented lines inside Python code samples to 4/8-space
  indentation; strip trailing spaces
2026-07-14 16:25:31 -07:00

3.4 KiB

MarkItDown Sample Plugin

PyPI PyPI - Downloads Built by AutoGen Team

This project shows how to create a sample plugin for MarkItDown. The most important parts are as follows:

First, implement your custom DocumentConverter:

from typing import BinaryIO, Any
from markitdown import MarkItDown, DocumentConverter, DocumentConverterResult, StreamInfo

class RtfConverter(DocumentConverter):

    def __init__(
        self, priority: float = DocumentConverter.PRIORITY_SPECIFIC_FILE_FORMAT
    ):
        super().__init__(priority=priority)

    def accepts(
        self,
        file_stream: BinaryIO,
        stream_info: StreamInfo,
        **kwargs: Any,
    ) -> bool:

        # Implement logic to check if the file stream is an RTF file
        # ...
        raise NotImplementedError()


    def convert(
        self,
        file_stream: BinaryIO,
        stream_info: StreamInfo,
        **kwargs: Any,
    ) -> DocumentConverterResult:

        # Implement logic to convert the file stream to Markdown
        # ...
        raise NotImplementedError()

Next, make sure your package implements and exports the following:

# The version of the plugin interface that this plugin uses.
# The only supported version is 1 for now.
__plugin_interface_version__ = 1

# The main entrypoint for the plugin. This is called each time MarkItDown instances are created.
def register_converters(markitdown: MarkItDown, **kwargs):
    """
    Called during construction of MarkItDown instances to register converters provided by plugins.
    """

    # Simply create and attach an RtfConverter instance
    markitdown.register_converter(RtfConverter())

Finally, create an entrypoint in the pyproject.toml file:

[project.entry-points."markitdown.plugin"]
sample_plugin = "markitdown_sample_plugin"

Here, the value of sample_plugin can be any key, but should ideally be the name of the plugin. The value is the fully qualified name of the package implementing the plugin.

Installation

To use the plugin with MarkItDown, it must be installed. To install the plugin from the current directory use:

pip install -e .

Once the plugin package is installed, verify that it is available to MarkItDown by running:

markitdown --list-plugins

To use the plugin for a conversion use the --use-plugins flag. For example, to convert an RTF file:

markitdown --use-plugins path-to-file.rtf

In Python, plugins can be enabled as follows:

from markitdown import MarkItDown

md = MarkItDown(enable_plugins=True)
result = md.convert("path-to-file.rtf")
print(result.text_content)

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.