This is a Python-Markdown extension for replacing .md file extensions with .html extensions in links. This is especially useful for maintaining Markdown collections that contain relative internal links, but are still parser-agnostic. There is a related GitHub issue.
The package must be available in the Python path. A setup.py script is included.
Example:
from markdown import markdown
from md2html_links import CustomLinkExtension
data = 'Some text and a [link](path/to/a/document.md).\n'
html = markdown(data, extensions=[CustomLinkExtension()])
print(f'ORIGINAL:\n{data}\n\nCONVERTED:\n{html}')
The output is as follows:
ORIGINAL:
Some text and a [link](path/to/a/document.md).
CONVERTED:
<p>Some text and a <a href="path/to/a/document.html">link</a>.</p>
This extension has been created following the guidance of the Python-Markdown extensions tutorial and the extensions API documentation.
The approach is to replace the LinkInlineProcessor inline processor with a slightly modified version of the same. It is given the same priority as the original in the Python-Markdown registry.