Skip to content

Add validation for invalid Markdoc table syntax - #603

Merged
yue-stripe merged 4 commits into
mainfrom
yue/valiatee-invalid-table-body-children
Mar 10, 2026
Merged

yue-stripe merged 4 commits into
mainfrom
yue/valiatee-invalid-table-body-children

Conversation

@yue-stripe

Copy link
Copy Markdown
Contributor

Summary

Markdoc supports a list-based syntax to define tables. Currently, the advanced table transform accepts invalid syntax where a non-list node is provided in place of a tr. If the node is not wrapped in a conditional row, it gets skipped, while if the node is in a conditional it gets rendered as a sibling element to the tr's.

Sandbox to demonstrate

The correct syntax would be to either make the item into a conditional row, or indent it to make it a conditional paragraph within the cell (cells 1 & 2 in the sandbox)

Motivation

tbody or thead can only contain tr elements, so the invalid syntax can produce silently broken HTML tables. This PR adds validation to prevent that. Now, Markdoc.validate() will surface invalid table syntax errors.

Tests

  • Added unit tests for invalid content (with and without conditionals), valid conditional rows, valid in-cell conditionals, hr separators, and comments.
  • Added marktest cases for valid conditional-in-cell usage and invalid escaped content.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds stricter validation for Markdoc’s advanced (list-based) table syntax so invalid non-row content inside {% table %} is surfaced via Markdoc.validate(), preventing silently broken HTML tables.

Changes:

  • Add table-syntax validation errors when non-row nodes appear at the table body row level (including within conditional wrappers).
  • Refactor table transform helpers (isConditionalTag, isComment) and introduce a shared unexpectedContentError.
  • Add Jest unit tests plus marktest fixtures covering valid/invalid conditional usage in tables.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/transforms/table.ts Implements validation during the advanced table transform and emits table-syntax errors for unexpected row-level content.
src/transforms/table.test.ts Adds unit tests for validation behavior across valid/invalid table/conditional/comment scenarios.
spec/marktest/tests.yaml Adds marktest coverage for conditional-in-cell rendering and invalid body content errors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/transforms/table.test.ts Resolved
Comment thread src/transforms/table.ts Resolved
Comment thread src/transforms/table.ts Resolved
@yue-stripe
yue-stripe marked this pull request as draft March 9, 2026 22:39
@yue-stripe
yue-stripe marked this pull request as ready for review March 9, 2026 23:07
Comment thread src/transforms/table.ts Resolved
@yue-stripe
yue-stripe merged commit 4f2a5f9 into main Mar 10, 2026
5 checks passed
@yue-stripe
yue-stripe deleted the yue/valiatee-invalid-table-body-children branch March 10, 2026 18:09
yue-stripe added a commit that referenced this pull request Mar 10, 2026
To cut a new release for #603
yue-stripe added a commit that referenced this pull request Mar 10, 2026
To cut a new release for #603
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.

3 participants