Skip to main content

A RTF plugin via striprtf for the "markitdown" library.

Project description

MarkItDown RTF Plugin

PyPI PyPI - Downloads Built by AutoGen Team

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

Next, 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"]
rtf_plugin = "markitdown_rtf_plugin"

Here, the value of rtf_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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

markitdown_rtf_plugin-0.1.0a1.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

markitdown_rtf_plugin-0.1.0a1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file markitdown_rtf_plugin-0.1.0a1.tar.gz.

File metadata

File hashes

Hashes for markitdown_rtf_plugin-0.1.0a1.tar.gz
Algorithm Hash digest
SHA256 9d987658ed7d084e8ede4f9cc2852a076b4fca654a42834e52f13cd175dae5b5
MD5 4c0143f89674bd21c2655cd4648a090f
BLAKE2b-256 67fb15430673af7b758dde873d20772105ce7eaf67afc150aa223e3fa7d1fde3

See more details on using hashes here.

File details

Details for the file markitdown_rtf_plugin-0.1.0a1-py3-none-any.whl.

File metadata

File hashes

Hashes for markitdown_rtf_plugin-0.1.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 28b8fb4c082316757d5dcfdbf154860c3d30fbd99f49d0b81b8c20d7bb768b5c
MD5 1bd4f71e20137e343fdc4197bc6b09d8
BLAKE2b-256 fdd0e29694dfedc918011ecee09e8df69bea22216598c1102f41b0418a67b35c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page