Author: BarCar · Repository: github.com/barcar/markdown-link-prefix
A Python-Markdown extension that expands prefixed link shorthand into full URLs. Write [text](youtube:VIDEO_ID) or [KB](snkb:KB123); when rendered, they become normal links using URL templates you define in a YAML file or config. All prefixes come from link_prefixes.yaml (or prefixes_file) and/or the prefixes option—nothing is hard-coded. Works with Zensical, MkDocs, or any tool that uses Python-Markdown.
- Prefixed links:
[text](prefix:id)→[text](https://.../id)via a URL template with{id}. - All from config or file: define prefixes in
prefixes_file(YAML) and/orprefixes; if the file is missing or empty and no config is given, no prefixes are defined. - Optional link titles:
[text](prefix:id "title")is supported.
pip install markdown-link-prefixRequires: markdown>=3.4. For loading from a YAML file: pip install "markdown-link-prefix[yaml]" (PyYAML).
import markdown
from markdown_link_prefix import LinkPrefixExtension
text = "[Watch](youtube:dQw4w9WgXcQ) and [KB](snkb:KB0012345)"
md = markdown.Markdown(extensions=[
LinkPrefixExtension(prefixes_file="docs/link_prefixes.yaml", project_root=".")
])
html = md.convert(text) # links expanded from the YAML templatesIn Zensical or MkDocs, add link_prefix to your Markdown extensions and set prefixes_file (and optionally prefixes). See the documentation for configuration, usage, and examples.
Online: Documentation (GitHub Pages).
To build the docs locally:
pip install -e ".[docs]"
zensical serve(The Changelog page may 404 locally—it is generated from root CHANGELOG.md in CI only.)
MIT License. See LICENSE.