Expand description
Markdown -> Product extraction (PORT-CONTRACT.d/03, parity landmine #2).
Bespoke CommonMark block-boundary tokenizer reproducing markdown-it-py
4.2.0’s "commonmark" preset for the consumed surface only: heading_open
(tag + 0-based start line) and inline (raw content + start line), plus
the oracle’s section-slicing walk on top (src/rac/core/markdown.py).
The bake-off of PORT-CONTRACT decision 4 resolves to bespoke: external
markdown crates are not in the dependency allowlist and the consumed
surface is block boundaries only, so the block rules of markdown-it-py
(code fence blockquote hr list reference html_block heading lheading paragraph) are ported line-by-line from the oracle venv’s source.
Python-semantics helpers (py_strip, py_casefold, py_repr_str,
Unicode \d) come from crate::pycompat per the layer-1 contract.
Structs§
- Block
Event - One consumed-surface event: a heading (tag + raw inline text) or a body inline (raw content), each with the block’s 0-based start line.
- Frontmatter
Split split_frontmatterresult (decided.core.frontmatter.FrontmatterSplit).- Issue
- Malformed
Requirement - Product
- Requirement
- Search
Section - Token
Constants§
Functions§
- consumed_
events - The exact token surface the oracle walk consumes (contract section 1).
- max_
file_ bytes - The per-file byte cap, honoring
DECIDED_MAX_FILE_BYTES(REQ-001). - max_
file_ bytes_ from max_file_bytes()computed from a raw env value (None = unset).- parse
- Parse Markdown
textinto aProduct(decided.core.markdown.parse), with the byte cap taken from the environment. - parse_
file - Read
pathand parse it (decided.core.markdown.parse_file). - parse_
file_ with_ cap parse_filewith an explicit byte cap (testing seam).- parse_
with_ cap parsewith an explicit byte cap (testing seam; the oracle reads the env).- py_
parse_ int - Python
int(str)(decimal): strips the Unicode whitespace set (which, unlikestr.strip(), excludes U+001C-U+001F — verified empirically, and it matches Ruststr::trim), accepts an optional sign, Unicode Nd digits, and single underscores strictly between digits. - split_
frontmatter - Split a leading
---frontmatter block (decided.core.frontmatter). - tokenize_
blocks - Tokenize a (frontmatter-stripped) Markdown body into the flat block-level token stream, exactly as markdown-it-py 4.2.0 “commonmark” emits it.