Python-Markdown extension: expand prefixed link shorthand (e.g. youtube:VIDEO_ID, snkb:KB123, snci:sys_id) to full URLs
Project description
Markdown Link Prefix
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.
Features
- 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.
Installation
pip install markdown-link-prefix
Requires: markdown>=3.4. For loading from a YAML file: pip install "markdown-link-prefix[yaml]" (PyYAML).
Quick example
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 templates
In 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.
Documentation
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.)
License
MIT License. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file markdown_link_prefix-0.1.1.tar.gz.
File metadata
- Download URL: markdown_link_prefix-0.1.1.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3fd6fd8c4cf64864028df90c9eac521ee07e08d7110b8a32578343ee2845be3f
|
|
| MD5 |
86de8776e3528c08265e17b150105985
|
|
| BLAKE2b-256 |
31a06ed1f187c0d193d795213ae79ab00f44ada03338276edf49f8837a64121c
|
File details
Details for the file markdown_link_prefix-0.1.1-py3-none-any.whl.
File metadata
- Download URL: markdown_link_prefix-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a2fb7a36431db9ab04fc14c3ec5adbe2f06abb589a1863554f15ed346578b0c
|
|
| MD5 |
2b680fcae9d43c2b2a39961574693f24
|
|
| BLAKE2b-256 |
257f2413ae8c24515823db11acfdc2f6c1c842a4dc4bbb784c53e48a56d257a7
|