Open FZQ0003 opened 8 months ago
I have found the reason.
This issue (typing markdown fenced code blocks in html comments) only appears when I enable one of built-in syntax highlight libraries. In my old environment, I disabled them and use Prettify instead, and it worked well.
I'll use another highlighter.
By the way, I have read an article about code blocks https://hexo.io/docs/syntax-highlight.html#How-to-use-code-block-in-posts. It says code block syntax will always be available, so I did additional tests.
Syntax highlighting is disabled.
Source:
Text 1
<!--
Commented text 1
{% codeblock %}
A commented code block
{% endcodeblock %}
Commented text 2
-->
Text 2
Output:
<p>Text 1</p>
<!--
Commented text 1
<pre><code>A commented code block</code></pre>
<p>Commented text 2</p>
<p>–></p>
<p>Text 2</p>
...
</html>-->
I should edit the title.
hexo wraps the highlighting code in <! -- --> and passes it into the markdown renderer, making it difficult to deal with nested comments.
https://github.com/hexojs/hexo/blob/3c7729dbb6f758564ac1853222541ec52087c9e3/lib/hexo/post.ts#L42
Notice that the end of the comment is escaped as <p>-></p>
, causing a comment tag pairing failure.
Check List
hexo version
to check)Expected behavior
In my old blog directory (replaced theme with landscape):
Output:
Commented text 2
-->
Text 2
How to reproduce?
Write a post like this and then start the server:
Commented text 2
-->
Text 2
Your Hexo and Plugin version
Your
package.json
Your site's
_config.yml
(Optional)No response
Others
Additionally, here is a list of plugins used in my OLD environment:
When I was trying to setup a new environment, this issue appeared. I don't know why.