fix(custom-tags): render Markdown inside custom tags with multiline content#484
Open
sleitor wants to merge 1 commit intovercel:mainfrom
Open
fix(custom-tags): render Markdown inside custom tags with multiline content#484sleitor wants to merge 1 commit intovercel:mainfrom
sleitor wants to merge 1 commit intovercel:mainfrom
Conversation
…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
Contributor
|
@sleitor is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 afterrehype-rawandrehype-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
literalTagContentare excluded from re-parsing (they intentionally suppress Markdown formatting).Testing
Added test suite
__tests__/custom-tags-markdown.test.tsxcovering:literalTagContenttags still suppress Markdown ✅All 986 tests pass.