fix: nunjucks/code blocks in HTML comments were incorrectly converted#5616
fix: nunjucks/code blocks in HTML comments were incorrectly converted#5616D-Sketon merged 13 commits intohexojs:masterfrom
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 18786185367Details
💛 - 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.
maybe we can solve it in backtick_code_block.ts
There was a problem hiding this comment.
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.
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.
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.
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.
Signed-off-by: D-Sketon <2055272094@qq.com>
What does it do?
fix #5433
Screenshots
Pull request tasks