Released: 2026-02-15
Parse cache for incremental builds, excerpt support, runnable examples, and a fix for custom directive registration.
Highlights
- Parse cache — Content-addressed
(content_hash, config_hash) -> Documentcache. Passcache: ParseCache | Nonetoparse(),Markdown.parse(), andMarkdown.parse_many()for faster incremental builds (undo/revert, duplicate content). - Excerpt support —
extract_excerpt()andextract_meta_description()for structurally correct excerpt extraction from AST. Stops at block boundaries; optional plain text or HTML output. Useful for list previews, meta descriptions, search snippets. - Examples — Runnable examples in
examples/: basic, notebooks, AST (visitor, transform), directives, incremental, differ, plugins, advanced. - Directive fix —
parse()now acceptsoptionskwarg (wasopts), matching parser invocation and fixing custom directive registration.
Features
Parse Cache
DictParseCache for in-memory use; hash_content() and hash_config() for key computation. Exported from patitas.cache and patitastop-level.
from patitas import parse, DictParseCache
cache = DictParseCache()
doc = parse("# Hello", cache=cache)
# Subsequent identical content hits cache
Excerpt Support
from patitas import parse, extract_excerpt, extract_meta_description
source = "# Title\n\nFirst paragraph. Second sentence."
doc = parse(source)
extract_excerpt(doc, source) # Plain text
extract_excerpt(doc, source, excerpt_as_html=True) # <p>, <div class="excerpt-heading">
extract_meta_description(doc, source) # ~160 chars at sentence boundary
Examples
Run withpython examples/basic/hello_markdown.pyetc. Covers:
- Basic (hello, Markdown class)
- Notebooks (parse_notebook)
- AST (visitor, transform)
- Directives (builtin, custom)
- Incremental, differ
- Plugins (math, tables, footnotes)
- Advanced (parallel parse, serialize)
Installation
pip install patitas>=0.3.1
pip install patitas[syntax] # Optional: syntax highlighting via Rosettes
Breaking Changes
None — all changes are backwards compatible.
Documentation
- API Reference —
parse(),render(),extract_excerpt(),ParseCache - Bengal — Static site generator with native notebook support