-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: nunjucks/code blocks in HTML comments were incorrectly converted #5616
base: master
Are you sure you want to change the base?
Conversation
How to testgit clone -b fix/comment https://github.com/D-Sketon/hexo.git
cd hexo
npm install
npm test |
Pull Request Test Coverage Report for Build 13330592073Details
💛 - Coveralls |
test/scripts/hexo/post.ts
Outdated
data.content.should.eql([ | ||
'<p>foo</p>', | ||
'<!--', | ||
`<hexoPostRenderCodeBlock>${highlighted}</hexoPostRenderCodeBlock>`, |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can solve it in backtick_code_block.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I forgot that the code block was processed before post render
The negative lookbehind and negative lookahead |
test/scripts/hexo/post.ts
Outdated
data.content.should.eql([ | ||
'<p>foo</p>', | ||
'<!--', | ||
`<hexoPostRenderCodeBlock>${highlighted}</hexoPostRenderCodeBlock>`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I forgot that the code block was processed before post render
restoreComments(str: string) { | ||
return str.replace(rCommentHolder, CodeBlockEscape.restoreContent(this.stored)); | ||
} | ||
|
||
escapeComments(str: string) { | ||
return str.replace(rCommentEscape, (_, content) => CodeBlockEscape.escapeContent(this.stored, 'comment', content)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks a bit weird. Your code repeatedly escape and restore comments in 'post' and 'backtick_code_block'.
Is it possible to work like 'backtick_code_block', escape comment before post render(and before 'backtick_code_block'), restore them at the end of post render.(I am assume that the comments should not be rendered at all. I am not sure if it is right.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means we need to share the escaped cache on a per-post basis between before_post_render
and post_render
(either by mounting a stored
on each post or maintaining a global map). I'm not sure if this will increase the complexity of the code, and whether holding the cache for a long time will affect garbage collection. However, regardless, I will give it a try.
What does it do?
fix #5433
Screenshots
Pull request tasks