2025-04-21 07:13:19 +00:00
# MarkItUp Sample Plugin
2025-02-10 23:21:44 +00:00
2025-04-21 07:13:19 +00:00
[](https://pypi.org/project/markitup-sample-plugin/)

2025-02-10 23:21:44 +00:00
[](https://github.com/microsoft/autogen)
2025-04-21 07:13:19 +00:00
This project shows how to create a sample plugin for MarkItUp. The most important parts are as follows:
2025-02-10 23:21:44 +00:00
2025-02-10 23:24:28 +00:00
Next, implement your custom DocumentConverter:
2025-02-10 23:21:44 +00:00
```python
2025-03-06 05:16:55 +00:00
from typing import BinaryIO, Any
2025-04-21 07:13:19 +00:00
from markitup import MarkItUp, DocumentConverter, DocumentConverterResult, StreamInfo
2025-02-10 23:21:44 +00:00
class RtfConverter(DocumentConverter):
2025-03-06 05:16:55 +00:00
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()
2025-02-10 23:21:44 +00:00
```
Next, make sure your package implements and exports the following:
```python
# The version of the plugin interface that this plugin uses.
# The only supported version is 1 for now.
__plugin_interface_version__ = 1
2025-04-21 07:13:19 +00:00
# The main entrypoint for the plugin. This is called each time MarkItUp instances are created.
def register_converters(markitup: MarkItUp, **kwargs):
2025-02-10 23:21:44 +00:00
"""
2025-04-21 07:13:19 +00:00
Called during construction of MarkItUp instances to register converters provided by plugins.
2025-02-10 23:21:44 +00:00
"""
# Simply create and attach an RtfConverter instance
2025-04-21 07:13:19 +00:00
markitup.register_converter(RtfConverter())
2025-02-10 23:21:44 +00:00
```
Finally, create an entrypoint in the `pyproject.toml` file:
```toml
2025-04-21 07:13:19 +00:00
[project.entry-points."markitup.plugin"]
sample_plugin = "markitup_sample_plugin"
2025-02-10 23:21:44 +00:00
```
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
2025-04-21 07:13:19 +00:00
To use the plugin with MarkItUp, it must be installed. To install the plugin from the current directory use:
2025-02-10 23:21:44 +00:00
```bash
pip install -e .
```
2025-04-21 07:13:19 +00:00
Once the plugin package is installed, verify that it is available to MarkItUp by running:
2025-02-10 23:21:44 +00:00
```bash
2025-04-21 07:13:19 +00:00
markitup --list-plugins
2025-02-10 23:21:44 +00:00
```
2025-03-06 05:16:55 +00:00
To use the plugin for a conversion use the `--use-plugins` flag. For example, to convert an RTF file:
2025-02-10 23:21:44 +00:00
```bash
2025-04-21 07:13:19 +00:00
markitup --use-plugins path-to-file.rtf
2025-02-10 23:21:44 +00:00
```
In Python, plugins can be enabled as follows:
```python
2025-04-21 07:13:19 +00:00
from markitup import MarkItUp
2025-02-10 23:21:44 +00:00
2025-04-21 07:13:19 +00:00
md = MarkItUp(enable_plugins=True)
2025-03-06 05:16:55 +00:00
result = md.convert("path-to-file.rtf")
2025-02-10 23:21:44 +00:00
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 ](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general ).
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.