Summary
A table authored without leading and trailing pipes is written back with them, so a file using GFM's pipe-optional form comes back in the form the serializer prefers. Both forms are the same table to a GFM reader, so nothing about the document changes.
This is the half of #323 that Preserve the form a file was written in keeps rather than normalizes. Whether a table carries outer pipes is one property of the table, not a layout computed across its cells, and it survives an edit to any cell, which is what separates it from the padding that decision normalizes.
Steps to reproduce
- Open a document containing a table whose rows omit their leading and trailing pipes.
- Save it without editing.
- Read the file.
Expected behavior
A table authored without outer pipes is written back without them, and one authored with them keeps them. A table created in the editor writes the form defined as its default.
Actual behavior
Measured in #323 against 83e12b19 by driving the editor mount used by the plugin tests. From corpus/gfm/tables.md, this table:
Bed | Reading | Action
:--- | :-----: | -----:
North | 31% | Move
South | 42% | Hold
is written back with an outer pipe on both sides of every row.
Related context
Done when
Notes, logs, screenshots
Implementation direction
markdown-table already supports this through its delimiterStart and delimiterEnd options, but mdast-util-gfm-table@2.0.0 never passes them: its handleTable calls markdownTable with align, alignDelimiters, padding, and stringLength only, and exposes just tableCellPadding, tablePipeAlign, and stringLength as settings. Reaching the option therefore needs a local table handler rather than a serializer setting, and the authored form has to be carried on the table node for that handler to read. src/features/editor/plugins/tableShape.ts is the existing local seam.
The default an editor-made table writes is not defined yet. #319 settled the equivalent for a thematic break by naming *** in docs/decisions.md and docs/specification.md. The same choice is open here, and a table the editor creates carries outer pipes today because the serializer writes them for every table, not because the form was chosen.
That default is also the fallback, because omitting the outer pipes is not always safe. Measured against markdown-table@3.0.4 and micromark-extension-gfm@3.0.0 by rendering a table with delimiterStart and delimiterEnd off and reparsing the result:
- A row whose first or last cell is empty stops being a table.
| B and A | are not read back as the rows they were written from.
- A delimiter row whose first cell is a single
- stops being a table, because - opens a bullet list item where no pipe precedes it. This reaches any table whose first column is one character wide, since the delimiter cell follows the column width.
- An empty cell between two filled ones is safe.
So a recorded bare form gives way to the default wherever the first or last cell of any row is empty, or the first delimiter cell would be a single hyphen.
Out of scope
Summary
A table authored without leading and trailing pipes is written back with them, so a file using GFM's pipe-optional form comes back in the form the serializer prefers. Both forms are the same table to a GFM reader, so nothing about the document changes.
This is the half of #323 that
Preserve the form a file was written inkeeps rather than normalizes. Whether a table carries outer pipes is one property of the table, not a layout computed across its cells, and it survives an edit to any cell, which is what separates it from the padding that decision normalizes.Steps to reproduce
Expected behavior
A table authored without outer pipes is written back without them, and one authored with them keeps them. A table created in the editor writes the form defined as its default.
Actual behavior
Measured in #323 against
83e12b19by driving the editor mount used by the plugin tests. Fromcorpus/gfm/tables.md, this table:is written back with an outer pipe on both sides of every row.
Related context
Preserve the form a file was written inindocs/decisions.md;corpus/gfm/tables.md; Preserve the authored form of a Markdown file on save #251 underScope.Done when
Notes, logs, screenshots
Implementation direction
markdown-tablealready supports this through itsdelimiterStartanddelimiterEndoptions, butmdast-util-gfm-table@2.0.0never passes them: itshandleTablecallsmarkdownTablewithalign,alignDelimiters,padding, andstringLengthonly, and exposes justtableCellPadding,tablePipeAlign, andstringLengthas settings. Reaching the option therefore needs a localtablehandler rather than a serializer setting, and the authored form has to be carried on the table node for that handler to read.src/features/editor/plugins/tableShape.tsis the existing local seam.The default an editor-made table writes is not defined yet. #319 settled the equivalent for a thematic break by naming
***indocs/decisions.mdanddocs/specification.md. The same choice is open here, and a table the editor creates carries outer pipes today because the serializer writes them for every table, not because the form was chosen.That default is also the fallback, because omitting the outer pipes is not always safe. Measured against
markdown-table@3.0.4andmicromark-extension-gfm@3.0.0by rendering a table withdelimiterStartanddelimiterEndoff and reparsing the result:| BandA |are not read back as the rows they were written from.-stops being a table, because-opens a bullet list item where no pipe precedes it. This reaches any table whose first column is one character wide, since the delimiter cell follows the column width.So a recorded bare form gives way to the default wherever the first or last cell of any row is empty, or the first delimiter cell would be a single hyphen.
Out of scope
Preserve the form a file was written innormalizes all three, so they are not defects.