0.3.1

Parse cache, excerpt support, examples, directive options fix

1 min read 288 words 1 day ago

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) -> Document cache. Pass cache: ParseCache | None to parse(), Markdown.parse(), and Markdown.parse_many()for faster incremental builds (undo/revert, duplicate content).
  • Excerpt supportextract_excerpt() and extract_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 inexamples/: basic, notebooks, AST (visitor, transform), directives, incremental, differ, plugins, advanced.
  • Directive fixparse() now accepts options kwarg (was opts), 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 Referenceparse(), render(), extract_excerpt(), ParseCache
  • Bengal — Static site generator with native notebook support