preservation: Conserve Markdown text before dependency parsers can discard it#
This token-layer policy is shared by the mdformat facade and every Markdown reader/writer.
Some constructs cannot be rewritten without losing text: a table row with more cells than its
header, and several definitions that share one label. Such a construct is never refused. The
parser hands it to the renderer as one VERBATIM block holding its source, relative to its
container, and the rest of the document is formatted as usual. Each carried construct is also
recorded under NOTICES in the parse environment, so callers can say what was left alone.
A label defined more than once keeps every definition exactly where it stands. Moving only the first would let a later duplicate win, because CommonMark keeps the first definition in document order; leaving all of them in place cannot change which one wins. Duplicate checks inspect parsed definitions, so literal examples never masquerade as definitions.
Conserve Markdown text before dependency parsers can discard it.
This token-layer policy is shared by the mdformat facade and every Markdown reader/writer.
Some constructs cannot be rewritten without losing text: a table row with more cells than its
header, and several definitions that share one label. Such a construct is never refused. The
parser hands it to the renderer as one VERBATIM block holding its source, relative to its
container, and the rest of the document is formatted as usual. Each carried construct is also
recorded under NOTICES in the parse environment, so callers can say what was left alone.
A label defined more than once keeps every definition exactly where it stands. Moving only the first would let a later duplicate win, because CommonMark keeps the first definition in document order; leaving all of them in place cannot change which one wins. Duplicate checks inspect parsed definitions, so literal examples never masquerade as definitions.
- myform.preservation.keep_orphans(options: Mapping[str, Any]) bool#
Resolve the API override, legacy footnote plugin setting, then the safe default.
- myform.preservation.source_of(state: StateBlock, start: int, end: int, *, rows: bool = False) tuple[str, int]#
Return the source of lines
[start, end), relative to the enclosing container.A container renderer re-applies its own prefix, so the content must not carry it. Trailing blank lines belong to the gap between blocks, not to the block. The one to three spaces that may indent a block’s first line are structure: formatting re-indents the blocks around it, and a carried block that kept them could be absorbed into a neighboring list item. They are removed, from every row too when
rowssays each line stands alone (a table).
- myform.preservation.verbatim_block(content: str, start: int, end: int, level: int) Token#
Build the block that
render_verbatimemits exactly as written.
- myform.preservation.note(env: MutableMapping[str, Any], kind: str, start: int, end: int, text: str) None#
Record one construct left as written, as 0-based lines
[start, end).
- myform.preservation.render_verbatim(node: mdformat.renderer.RenderTreeNode, context: mdformat.renderer.RenderContext) str#
Emit a carried block’s source untouched; the root joiner adds the surrounding blank lines.
- myform.preservation.install(mdit: MarkdownIt) None#
Install one idempotent preservation policy after the dialect’s plugins load.