Skip to content

fix(custom-tags): render Markdown inside custom tags with multiline content#484

Open
sleitor wants to merge 1 commit intovercel:mainfrom
sleitor:fix-478
Open

fix(custom-tags): render Markdown inside custom tags with multiline content#484
sleitor wants to merge 1 commit intovercel:mainfrom
sleitor:fix-478

Conversation

@sleitor
Copy link
Copy Markdown
Contributor

@sleitor sleitor commented Mar 28, 2026

Problem

When a custom tag contains multiline content (e.g. <ai-thinking>\n**bold**</ai-thinking>), the CommonMark parser treats the entire block as an HTML block, passing the inner content through as raw text rather than parsing it as Markdown. So **bold** renders as plain text instead of <strong>bold</strong>.

Single-line content already works fine because it's parsed as inline HTML.

Fixes #478

Solution

Adds a new rehype plugin (rehypeMarkdownInCustomTags) that runs after rehype-raw and rehype-sanitize. It finds custom tag elements with text-only children that contain newlines, and re-parses the raw text as Markdown, replacing the text children with properly parsed HAST nodes.

Tags listed in literalTagContent are excluded from re-parsing (they intentionally suppress Markdown formatting).

Testing

Added test suite __tests__/custom-tags-markdown.test.tsx covering:

  • Bold inside custom tag with newline prefix ✅
  • Single-line bold (existing behavior preserved) ✅
  • Inline code inside multiline custom tag ✅
  • literalTagContent tags still suppress Markdown ✅

All 986 tests pass.

…ontent

Adds rehypeMarkdownInCustomTags rehype plugin that re-parses raw text
content of custom tag elements as Markdown. Previously, when a custom
tag contained multiline content (e.g. `<ai-thinking>\n**bold**</ai-thinking>`),
CommonMark treated the block as raw HTML, passing inner content through
as raw text instead of Markdown.

The plugin runs after rehype-raw and rehype-sanitize and only acts on
elements whose children are text-only nodes containing newlines. Tags
listed in `literalTagContent` are excluded from re-parsing.

Closes vercel#478
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 28, 2026

@sleitor is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

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.

Markdown syntax fails to render inside custom tags

1 participant