Skip to content

A Python-Markdown extension for replacing .md file extensions with .html extensions in links.

License

Notifications You must be signed in to change notification settings

ricmua/markdown-md2html_links

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Installation

The package must be available in the Python path. A setup.py script is included.

Usage

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>

Development notes

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.

An alternative approach was also suggested by @venthur.

About

A Python-Markdown extension for replacing .md file extensions with .html extensions in links.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages