fix(post): parse nested tags with context-aware lexer - #5800
Open
stevenjoezhang wants to merge 4 commits into
Open
fix(post): parse nested tags with context-aware lexer#5800stevenjoezhang wants to merge 4 commits into
stevenjoezhang wants to merge 4 commits into
Conversation
How to testgit clone -b fix/context-aware-post-lexer https://github.com/hexojs/hexo.git
cd hexo
npm install
npm test |
2 tasks
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.
What does it do?
This replaces Hexo's separate post-render scanners with one context-aware lexer and processor for:
{% raw %}blocksThe lexer tracks these contexts in a single pass, so delimiters belonging to one syntax are not interpreted as another.
Why is it needed?
The previous post-render scanner matched a block tag with the first apparent
end<tag>. It could not correctly handle a tag nested inside another tag with the same name:The inner
endfoldingcould be mistaken for the end of the outer block. Markdown processing would then split the outer tag body before the theme plugin received it.This breaks comment-based protocols used by themes such as NexT and Volantis. HTML comments like
<!-- tab ... -->are functional input to those plugins and must remain available during tag rendering.The new lexer pairs block tags by their exact Nunjucks token name and maintains a nesting stack. Tag names are read using Nunjucks delimiter rules, including syntax such as
{% folding, ... %}.Fixes #5799 without regressing the functional HTML-comment handling required by #5433.
Implementation
Shared lexer state
post_render_lexerperforms a single context-aware scan:{% raw %}contents are opaque; only valid nestedrawandendrawboundaries are recognized.endraw.endare supported.Unified post-render processing
post_render_processorconsumes the lexer ranges to:The old
before_post_render/backtick_code_blockfilter is removed, so the document is no longer independently parsed for fenced code a second time.One observable ordering change is intentional: custom
before_post_renderfilters now receive the original Markdown, before Hexo performs built-in fenced-code highlighting.No new runtime dependency is introduced.
Tests
Added unit and integration coverage for:
foldingandtabsstructure.{% folding, ... %}syntax.end.Validation performed:
194 passing, 1 pendingin the focused post-render test suite.libandtest.origin/master.Performance
Local end-to-end
post.render()benchmarks were run with Node.js 24.15.0 after 15 warm-up iterations.mastermedianThe ordinary no-Nunjucks/no-fence path exits before lexing. Even in the deliberately fence-heavy corpus, the absolute median overhead remained approximately 1.4 ms.
Raw-block scanning is linear: a stress input containing 8,000 unmatched raw openers was scanned in approximately 2.1 ms locally.
Pull request tasks