Table reflow

Version 0.6.1 Updated Sep 29, 2026

mdtablefix reformats Markdown pipe tables so each column is aligned to a uniform width. The formatter measures each cell using Unicode display width, which means accented characters, CJK glyphs, and emoji stay visually aligned after reflow.

A row is a delimiter row only when every cell consists of an optional leading colon, one or more dashes, and an optional trailing colon. A row of pipes and spaces (| | |), a lone dash among empty cells (| | - |), | - - |, and | :- : | are therefore ordinary rows, not alignment rows. This is what keeps a table with an empty header row from being restructured, and the same rule is applied wherever the formatter looks for an alignment row.

A block that contains a line made only of pipes and spaces is left exactly as written. Such a line is an empty row in a table, and plain text in a pipe-led block that has no delimiter row; reflowing would discard it either way.

The exception is a table converted from HTML (see "HTML table conversion"). An empty <tr> becomes such a line, but the table is still aligned: the other rows are reflowed and each empty row is put back, padded to the width of the delimiter row.

Continuation rows are preserved during reflow. When a row starts with empty leading cells because its content continues from the previous row, those empty cells keep their original column positions instead of collapsing into the first non-empty cell.

When a table run is followed by a line that opens a new Markdown block — such as a bullet list item, blockquote, link reference definition, or footnote definition — mdtablefix flushes and reflows the buffered table before the new block is processed. This applies even when the block-opening line itself contains a pipe character; it is not treated as a table continuation row. For example, after a table, > quote | with pipe starts a blockquote rather than extending the table.

Pipe-looking lines indented by four or more columns are preserved as indented code blocks. For example, a source line with four leading spaces before | not | a table | is emitted verbatim rather than being table-reflowed.

Content inside fenced code blocks is treated the same way. A line beginning with | inside such a block — for example a shell pipeline continuation such as | tee /tmp/test.log — is never treated as a Markdown table row and never gains an appended trailing |.

Literal pipe characters inside cells must be written as \|. mdtablefix preserves that escaping during reflow, so a literal pipe remains part of the cell content rather than being interpreted as a column boundary.

Table-cell payloads preserve arbitrary Unicode characters, including U+001D and U+001F, during reflow.