Python implementation of Linked Markdown, packaged for PyPI.
See the wazootech/linked-markdown repository for the specification, conformance suite, and reference documentation.
Status: All 26 conformance tests passing.
from linked_markdown import extract
result = extract(markdown)
# => ExtractResult(front_matter="...", body="...", attrs={...})Parses frontmatter from a Linked Markdown document. Supports YAML (---, ---yaml, = yaml =), JSON (---, ---json, = json =), and TOML (---toml, +++, = toml =) formats.
- Strips UTF-8 BOM and normalizes CRLF to LF before parsing.
- Returns
front_matterwith a trailing newline for non-empty frontmatter. front_matteris""for empty frontmatter (---\n---).bodyhas leading newlines stripped.
Thrown for all error conditions. Has a .code property:
| Code | When |
|---|---|
LMD_NO_FRONTMATTER |
No frontmatter delimiters found |
LMD_INVALID_FRONTMATTER |
Unknown marker, unparseable content, non-object attrs, or no closing delimiter |
try:
extract(markdown)
except LinkedMarkdownError as e:
if e.code == LMD_NO_FRONTMATTER:
...The attrs returned by extract() is valid JSON-LD, directly loadable into RDFLib:
import json
import rdflib
result = extract(markdown)
g = rdflib.Graph()
g.parse(data=json.dumps(result.attrs), format="json-ld")git submodule update --init --recursive
uv sync
uv run pytest