Tables: Fold-aware Markdown table rendering#
The upstream tables renderer sizes a column from its serialized Markdown. That makes a
link destination, image URL, or other typically-hidden inline material widen every other cell.
This module keeps table serialization untouched while sizing cells from a view that folds only
that hidden material – destinations, targets, and escapes; rendered markup (emphasis, code,
math, HTML) still counts at its serialized width. CellFolder is deliberately a small
registry alongside the parser, renderer, and postprocessor registries: dialects can teach table
layout about a new hidden token without adding conditionals to the table renderer.
Fold-aware Markdown table rendering.
The upstream tables renderer sizes a column from its serialized Markdown. That makes a
link destination, image URL, or other typically-hidden inline material widen every other cell.
This module keeps table serialization untouched while sizing cells from a view that folds only
that hidden material – destinations, targets, and escapes; rendered markup (emphasis, code,
math, HTML) still counts at its serialized width. CellFolder is deliberately a small
registry alongside the parser, renderer, and postprocessor registries: dialects can teach table
layout about a new hidden token without adding conditionals to the table renderer.
- myform.Tables.render_table_cell(node: mdformat.renderer.RenderTreeNode, context: mdformat.renderer.RenderContext) str#
Render and pipe-escape one cell, preserving mdformat-tables’ serialization contract.
- myform.Tables.postprocess_table_escapes(text: str, _: mdformat.renderer.RenderTreeNode, __: mdformat.renderer.RenderContext) str#
Escape delimiter-shaped paragraph lines, preserving mdformat-tables’ fixed-point guard.
- myform.Tables.parse_conserving_table(state: StateBlock, start_line: int, end_line: int, silent: bool) bool#
Carry a table whose rows overflow its header exactly as written.
The upstream rule discards the cells beyond the header’s width. Let it decide table boundaries, containers and escaped-pipe grammar, then inspect only the rows it consumed. A table with an overflowing row becomes one
VERBATIMblock of its own source, so no cell is lost and no geometry is inferred; every other table is formatted as before, and underfull rows keep the upstream empty-cell behavior.
- class myform.Tables.CellFolder#
Registry that hides typically-hidden inline syntax from a table cell’s measured width.
- static register(fn: Folder, name: str = '') Folder#
Register one token folder, inferring its token name from
fold_<name>when omitted.
- classmethod fold(node: mdformat.renderer.RenderTreeNode, context: mdformat.renderer.RenderContext) str#
Return the cell’s measured text, keeping rendered markup and unknown tokens as-is.
- classmethod children(node: mdformat.renderer.RenderTreeNode, context: mdformat.renderer.RenderContext) str#
Fold and concatenate a node’s children.
- classmethod width(node: mdformat.renderer.RenderTreeNode, context: mdformat.renderer.RenderContext) int#
Return the terminal-cell width of a folded node, treating unprintable spans as empty.
- myform.Tables.fold_inline(node: mdformat.renderer.RenderTreeNode, context: mdformat.renderer.RenderContext) str#
Fold an ordinary inline container through its children.
- myform.Tables.fold_td(node: mdformat.renderer.RenderTreeNode, context: mdformat.renderer.RenderContext) str#
Fold one table data cell through its inline child.
- myform.Tables.fold_th(node: mdformat.renderer.RenderTreeNode, context: mdformat.renderer.RenderContext) str#
Fold one table header cell through its inline child.
- myform.Tables.fold_text(node: mdformat.renderer.RenderTreeNode, _: mdformat.renderer.RenderContext) str#
Use decoded text rather than the Markdown escapes required to serialize it.
mdformat’s text renderer turns tabs into spaces and collapses each run of spaces to one, so the measured width has to as well: a cell that is padded for the wider run is misaligned.
- myform.Tables.fold_link(node: mdformat.renderer.RenderTreeNode, context: mdformat.renderer.RenderContext) str#
Hide link syntax and destinations, retaining the rendered link label.
- myform.Tables.fold_image(node: mdformat.renderer.RenderTreeNode, context: mdformat.renderer.RenderContext) str#
Hide image syntax and URLs, retaining its visible alt label as the textual fallback.
- myform.Tables.fold_myst_role(node: mdformat.renderer.RenderTreeNode, context: mdformat.renderer.RenderContext) str#
Hide a MyST role’s wrapper and explicit
label <target>reference target.
- myform.Tables.source_cell_width(value: str) int#
Measure source markup by the same folding rules as the table formatter.