fix(custom-tags): restructure inline content with newlines to prevent ATX heading block splitting#481
Open
sleitor wants to merge 1 commit intovercel:mainfrom
Open
fix(custom-tags): restructure inline content with newlines to prevent ATX heading block splitting#481sleitor wants to merge 1 commit intovercel:mainfrom
sleitor wants to merge 1 commit intovercel:mainfrom
Conversation
… ATX heading block splitting Custom tags with content inline on the opening tag line and a newline inside would be prematurely closed by the CommonMark parser when the newline was followed by a block-level element like an ATX heading (# title). Example: <ai-thinking> hi # yes</ai-thinking> The marked Lexer parsed this as: - paragraph: '<ai-thinking> hi\n' - heading: '# yes</ai-thinking>' The preprocessor already handled blank lines (\n\n) by restructuring the tag to block-level HTML. Extend the condition to also restructure when content is inline (doesn't start with \n) and contains any newline, since any newline in inline content can introduce block-starting sequences. Tags where content already starts on its own line (\nContent\n) are unaffected — they're correctly parsed as block-level HTML even with headings inside. Fixes vercel#477
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
Custom tags with multiline content are prematurely closed by the CommonMark parser when the content starts inline (on the same line as the opening tag) and contains a newline followed by a block-level element like an ATX heading.
Minimal reproduction:
The
markedLexer splits this as:paragraph:<ai-thinking> hi\nheading:# yes</ai-thinking>Root Cause
preprocess-custom-tags.tsonly restructures tags to block-level HTML when there are blank lines (\n\n) in the content. However, a single newline inside inline content is sufficient to introduce block-starting sequences (ATX headings, thematic breaks, list items, etc.) that break the parser.Content that already starts on its own line (
\nContent\n) is correctly parsed as a block-level HTML element by the Lexer — even with headings inside — because the opening tag is on its own line.Fix
Extend the restructuring condition to also apply when:
\n), ANDTags where content already starts on its own line (block-level) are unaffected. Single-line tags without newlines are also unaffected.
Fixes #477
Related: #478 (same root cause)