Skip to content

Skip tables inside fenced code blocks - #121

Open
bardrop wants to merge 1 commit into
darkriszty:mainfrom
bardrop-oss:fix/fenced-code-blocks
Open

bardrop wants to merge 1 commit into
darkriszty:mainfrom
bardrop-oss:fix/fenced-code-blocks

Conversation

@bardrop

@bardrop bardrop commented Nov 20, 2026

Copy link
Copy Markdown

Fixes #120.

TableFinder now marks the lines of fenced code blocks and skips them, the same way it skips ignore blocks. Table-shaped lines in code samples are left as they are.

Rules (GFM 4.5):

  • A fence is a line of 3 or more ` or ~ (leading spaces allowed). A backtick fence with a backtick in its info string is inline code, not a fence (```|a|```).
  • A closing fence uses the same character and is at least as long as the opening one, so is not closed by ``` ````.
  • A fence that is not closed runs to the end of the document.
  • <!-- markdown-table-prettify-ignore-start --> inside a fence (for example in a docs sample) no longer starts an ignore block.

This covers all three paths that use TableFinder: format document, format table at cursor, and the CLI / --check.

Tests:

  • 7 new TableFinder unit tests; 6 fail before the fix (the inline-code one is a guard and passes on both).
  • New system test pair fencedCodeBlocks-input.md / -expected.md; fails before.
  • npm run --silent check-md < README.md now passes (it failed before, as the issue says).

I ran the unit and CLI system tests with mocha (351 passing). The VS Code host could not start on my machine, so the vsPrettyfier system tests will run in CI.

TableFinder now marks the lines of fenced code blocks (``` and ~~~,
GFM 4.5) and skips them, so table-shaped lines in code samples are
left as they are. A closing fence must use the same character and be
at least as long as the opening one; an unclosed fence runs to the end
of the document. Ignore markers inside a fence are ignored too.

Fixes darkriszty#120
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.

Tables inside fenced code blocks are reformatted

1 participant