diff --git a/CHANGELOG.md b/CHANGELOG.md index a1b78b3..5763e1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## Unreleased + +- 📚 DOCS: Explain extracting front matter and rendering HTML from one parse (#133). + ## 0.7.0 - 2026-07-19 - ✨ NEW: Add section reference plugin (`section_ref`) (#144) diff --git a/docs/index.md b/docs/index.md index 123ab6a..a8dd678 100644 --- a/docs/index.md +++ b/docs/index.md @@ -43,6 +43,50 @@ html_string = md.render("some *Markdown*") .. autofunction:: mdit_py_plugins.front_matter.front_matter_plugin ``` +### Extract metadata and render HTML + +Register the plugin, parse the source once, then render the resulting tokens: + +```python +from markdown_it import MarkdownIt +from mdit_py_plugins.front_matter import front_matter_plugin + +md = MarkdownIt("commonmark").use(front_matter_plugin) +source = "---\ntitle: Example\ndraft: false\n---\n# Welcome\n" +env = {} +tokens = md.parse(source, env) +front_matter = next( + (token.content for token in tokens if token.type == "front_matter"), None +) +html = md.renderer.render(tokens, md.options, env) + +assert front_matter == "title: Example\ndraft: false" +assert html == "\n