Skip to main content

Module grid_layout

Module grid_layout 

Source
Expand description

Shared 2D geometry pass for grid tables.

A grid table’s logical cells are rectangles over a canonical column/row grid, and a spanning cell’s content is non-contiguous in the byte stream (a rowspan cell’s text is interleaved with other cells’ bytes and separator lines). A rowan CST node covers a single contiguous range, so the cell tiling cannot be represented as CST nodes and must be recovered by a 2D pass downstream of the parser. This module is the single home for that pass, consumed by both the pandoc-native projector (pandoc_ast::grid_table) and the formatter’s spanning-grid engine, so the geometry is computed one way.

The algorithm mirrors pandoc’s gridtables: build a padded char grid, take the canonical column boundaries as the union of + positions across every “sep-style” line and the canonical row boundaries as those lines’ indices, then detect each cell as the smallest valid bounding rectangle. Positions are character indices (matching pandoc, which lays grid tables out on the source character grid), not display columns.

Structs§

GridCellRect
One laid-out cell of a grid table over the canonical (row band × fine column) grid. content is the cell’s interior text with one leading pad space stripped per line, trailing whitespace trimmed, and leading/trailing blank lines dropped, joined with \n.
GridLayout
Canonical geometry of a grid table plus its detected cells.

Functions§

analyze_grid
Analyze a grid table’s lines into its canonical geometry and cell tiling.