fix: Swig tag at line start breaks Markdown processing on the same line#5752
Open
KentarouTakeda wants to merge 1 commit intohexojs:masterfrom
Open
fix: Swig tag at line start breaks Markdown processing on the same line#5752KentarouTakeda wants to merge 1 commit intohexojs:masterfrom
KentarouTakeda wants to merge 1 commit intohexojs:masterfrom
Conversation
How to testgit clone -b fix/inline-swig-placeholder https://github.com/KentarouTakeda/hexojs-hexo.git
cd hexo
npm install
npm test |
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?
Problem
When a Swig/Nunjucks tag appears at the beginning of a line, Markdown syntax on the rest of that line is not processed.
Input:
{% post_link my-post 'My Post' %} and [link](https://example.com)Expected:
linkbecomes a clickable link.Actual:
[link](https://example.com)is rendered as plain text.Cause
Hexo replaces Swig tags with HTML comment placeholders (
<!--swigN-->) before Markdown rendering. When this placeholder starts a line, it triggers an HTML block (type 2) per the CommonMark spec — the entire line is treated as raw HTML and no Markdown processing occurs (see Example 177).Fix
A single placeholder format cannot satisfy both requirements:
{% blockquote %}) need the HTML comment placeholder to trigger HTML block parsing, which prevents the Markdown renderer from wrapping the output in<p>tags.{% post_link %} [link](url)) must not trigger HTML block parsing, or the rest of the line loses Markdown processing.This PR adds an inline placeholder format (
swigN) that uses U+FFFC (Object Replacement Character) as delimiters instead of HTML comments. U+FFFC is already used in the existing block placeholder format and is safe for this purpose — it has no special meaning in HTML or Markdown, does not appear in normal text, and survives Markdown rendering unchanged.The state machine in
escapeAllSwigTagslooks ahead after each closing%}/}}: if non-whitespace content follows on the same line, the inline format is used; otherwise the existing block format (<!--swigN-->) is used.Pull request tasks