Skip to content

Comments

fix(markdoc): resolve custom attributes on built-in table tag#15457

Merged
matthewp merged 2 commits intowithastro:mainfrom
AhmadYasser1:fix/markdoc-table-attributes
Feb 14, 2026
Merged

fix(markdoc): resolve custom attributes on built-in table tag#15457
matthewp merged 2 commits intowithastro:mainfrom
AhmadYasser1:fix/markdoc-table-attributes

Conversation

@AhmadYasser1
Copy link
Contributor

Changes

  • Adds syncTagNodeAttributes() to packages/integrations/markdoc/src/runtime.ts that runs after config setup
  • In Markdoc, table exists as both a tag ({% table %}) and a node (the inner table structure). Attributes on the tag propagate to the child node in the AST, so both schemas must declare the same attributes for Markdoc.validate() to pass
  • When users configure custom attributes on nodes.table or tags.table, this function syncs the attribute declarations to the counterpart, preventing "Invalid attribute" validation errors
  • Only runs for names that exist in both Markdoc.tags and Markdoc.nodes (currently only table)

Testing

  • Added test/render-table-attrs.test.js with build + dev tests using a fixture that configures nodes.table with a custom background attribute
  • All 79 markdoc tests pass (77 existing + 2 new)

Docs

  • No docs changes needed. This is a bug fix that makes existing documented behavior work correctly.

Fixes #14220

…ed names

In Markdoc, `table` exists as both a tag (`{% table %}`) and a node
(the inner table structure). When users configure custom attributes on
`nodes.table` or `tags.table`, the AST propagates those attributes to
both the tag and node, but validation only checks the schema for each
type independently. This caused "Invalid attribute" errors when
attributes were declared on only one side.

Add `syncTagNodeAttributes()` to automatically merge attribute
declarations between tags and nodes that share the same name after
config setup, so users can define attributes on either side.

Fixes withastro#14220
@changeset-bot
Copy link

changeset-bot bot commented Feb 10, 2026

🦋 Changeset detected

Latest commit: cdc4074

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: integration Related to any renderer integration (scope) label Feb 10, 2026
*/
function syncTagNodeAttributes(config: MergedConfig): void {
// Use `as any` for built-in schema access since Markdoc's types don't have string index signatures
const builtinTags: Record<string, any> = Markdoc.tags;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you just omit the type here since it will be the type of the value you're assigning

function syncTagNodeAttributes(config: MergedConfig): void {
// Use `as any` for built-in schema access since Markdoc's types don't have string index signatures
const builtinTags: Record<string, any> = Markdoc.tags;
const builtinNodes: Record<string, any> = Markdoc.nodes;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

@AhmadYasser1
Copy link
Contributor Author

re the type annotations on builtinTags/builtinNodes: tried removing them but it causes TS7053 errors. Markdoc.tags and Markdoc.nodes don't have a string index signature, so indexing with a dynamic key in the loop fails without the explicit Record<string, any>. updated the comment on those lines to explain why they're needed.

@matthewp matthewp merged commit 6e8da44 into withastro:main Feb 14, 2026
21 checks passed
@AhmadYasser1 AhmadYasser1 deleted the fix/markdoc-table-attributes branch February 14, 2026 18:01
FredKSchott pushed a commit that referenced this pull request Feb 15, 2026
* fix(markdoc): sync custom attributes between tags and nodes with shared names

In Markdoc, `table` exists as both a tag (`{% table %}`) and a node
(the inner table structure). When users configure custom attributes on
`nodes.table` or `tags.table`, the AST propagates those attributes to
both the tag and node, but validation only checks the schema for each
type independently. This caused "Invalid attribute" errors when
attributes were declared on only one side.

Add `syncTagNodeAttributes()` to automatically merge attribute
declarations between tags and nodes that share the same name after
config setup, so users can define attributes on either side.

Fixes #14220

* chore: clarify why explicit types are needed on builtinTags/builtinNodes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: integration Related to any renderer integration (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Attributes on table does not work with markdoc

2 participants