Skip to content

fix(markdown-common): keep ~~ literal and escape | in table cells - #693

Open
rue19 wants to merge 1 commit into
accordproject:mainfrom
rue19:fix/strikethrough-and-table-pipes
Open

rue19 wants to merge 1 commit into
accordproject:mainfrom
rue19:fix/strikethrough-and-table-pipes

Conversation

@rue19

@rue19 rue19 commented Nov 17, 2026 •

Copy link
Copy Markdown

Closes #692

fromMarkdown no longer throws on ~~...~~, and toMarkdown escapes | inside table cells, so tables containing a pipe round-trip intact.

On main (15a54f7) and on this branch:

Input main This PR
Price is ~~$100~~ $80. (CommonMark and CiceroMark fromMarkdown) throws Unknown inline type s_open one Text node, ~~ kept, round-trips unchanged
body cell a | b toMarkdown writes | a | b | ok |, reparsed as ['a', 'b'] writes a \| b, reparsed as ['a | b', 'ok']
header cell a | b three header cells over a two-column delimiter row, so no longer a table round-trips intact
`a | b` or *a | b* in a cell cell splits round-trips intact
a | b outside a table unchanged unchanged

Changes

  • CommonMarkTransformer.toTokens, CiceroMarkTransformer.toTokens, templateToTokens: .disable('strikethrough'). The CommonMark model has no strikethrough node, so ~~ is kept as literal text, as in CommonMark 0.31.2.
  • CommonMarkUtils: adds inTableCell(parameters), which checks the block stack for TableCell/HeaderCell, and escapeTableCell().
  • fromcommonmarkrules.ts: the Text and Code rules escape | as \| only inside a cell. Emphasis, links and other inline nodes are covered because their text is rendered by Text. CiceroMark's toMarkdownCicero uses the same rules, so it's fixed too.

Flags

  • Literal ~~ vs a strikethrough node: this keeps ~~ as text and doesn't change the model. Modelling strikethrough would mean a new node in the hosted CommonMark model plus rules in every transformer, which seemed better as its own discussion. Happy to change direction if you'd prefer that.
  • Previously fromMarkdown threw on ~~, so no existing document could depend on strikethrough. No snapshots changed.

Testing

  • CommonMarkTransformer.test.ts: literal ~~ with an exact DOM and round trip; body cell, header cell, inline code and emphasis cases, each asserting the reparsed DOM equals the original; the escaped output; and | outside a table left alone.
  • CiceroMarkTransformer.test.ts: ~~ through fromMarkdownCicero/toMarkdownCicero, and a table round trip.
  • TemplateMarkTransformer.test.ts: no s_open token, and ~~ kept as text next to a {{variable}}.
  • 9 of the new tests fail on main and pass here. The tenth (| outside a table) passes on both, as intended.
  • npm test (all packages, licence check): passes, no snapshot changes. Lint is clean in all 8 packages. The Playwright e2e suite passes (10/10).

Author Checklist

  • Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit.
  • Vital features and changes captured in unit and/or integration tests
  • Commits messages follow AP format
  • Extend the documentation, if necessary (not needed)
  • Merging to main from fork:branchname

AI Assistance

AI assistance was used in preparing, reviewing, and testing this change.

markdown-it's default preset enables strikethrough, but the CommonMark
model has no node for it, so fromMarkdown threw "Unknown inline type
s_open" on any ~~...~~ span, in CommonMark and CiceroMark alike. Disable
the rule on the CommonMark, CiceroMark and TemplateMark parsers so ~~
stays literal text, as in CommonMark 0.31.2.

toMarkdown wrote | unescaped inside table cells, so a cell containing
an escaped pipe split into two on the next parse and a header row lost
its table. The Text and Code rules now escape | as \| inside TableCell
and HeaderCell, which also covers text inside emphasis, links and other
inline nodes. Text outside a table is unchanged.

Closes accordproject#692

Signed-off-by: rue19 <shrinjalik@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CommonMarkTransformer: strikethrough throws Unknown inline type s_open and table cells do not escape |

1 participant