Skip to content

Note 标签插件无法正确处理 } 符号,导致无法正确显示数学公式 #924

@wangjiezhe

Description

@wangjiezhe

Issue Checklist

Expected behavior

在 Note 标签插件的 summary 部分正确显示数学公式。

Actual behavior

按照下面的示例,得到的网页截图如下:

Image

这部分对应的网页源代码:

<details class="note info"><summary><p>标{题</p>
</summary>
<p>内容</p>
 
</details>
<p><details class="note info"><summary><p>标}题</p>
</summary>
<br>
内容</p>
</details>
<p><details class="note info"><summary><p>标}题</p>
</summary>
<br>
内容</p>
</details>
<details class="note danger"><summary><p>构{造:<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mstyle displaystyle="true" scriptlevel="0"><mfrac><mn>2</mn><mi>x</mi></mfrac></mstyle></mrow><annotation encoding="application/x-tex">\dfrac2x</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:2.0074em;vertical-align:-0.686em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3214em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathnormal">x</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">2</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.686em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></p>
</summary>
<p>有理数</p>
 
</details>
<p><details class="note danger"><summary><p>构}造:<span class=katex><span class=katex-mathml><math xmlns=http://www.w3.org/1998/Math/MathML><semantics><mrow><mstyle displaystyle=true scriptlevel=0><mfrac><mn>2</mn><mi>x</mi></mfrac></mstyle></mrow><annotation encoding=application/x-tex>\dfrac2x</annotation></semantics></math></span><span class=katex-html aria-hidden=true><span class=base><span class=strut style=height:2.0074em;vertical-align:-0.686em;></span><span class=mord><span class=mopen nulldelimiter></span><span class=mfrac><span class=vlist-t vlist-t2><span class=vlist-r><span class=vlist style=height:1.3214em;><span style=top:-2.314em;><span class=pstrut style=height:3em;></span><span class=mord><span class=mord mathnormal>x</span></span></span><span style=top:-3.23em;><span class=pstrut style=height:3em;></span><span class=frac-line style=border-bottom-width:0.04em;></span></span><span style=top:-3.677em;><span class=pstrut style=height:3em;></span><span class=mord><span class=mord>2</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.686em;><span></span></span></span></span></span><span class=mclose nulldelimiter></span></span></span></span></span></p>
</summary>
<br>
有理数</p>
</details>
<p><details class="note danger"><summary><p>构}造:<span class=katex><span class=katex-mathml><math xmlns=http://www.w3.org/1998/Math/MathML><semantics><mrow><mstyle displaystyle=true scriptlevel=0><mfrac><mn>2</mn><mi>x</mi></mfrac></mstyle></mrow><annotation encoding=application/x-tex>\dfrac2x</annotation></semantics></math></span><span class=katex-html aria-hidden=true><span class=base><span class=strut style=height:2.0074em;vertical-align:-0.686em;></span><span class=mord><span class=mopen nulldelimiter></span><span class=mfrac><span class=vlist-t vlist-t2><span class=vlist-r><span class=vlist style=height:1.3214em;><span style=top:-2.314em;><span class=pstrut style=height:3em;></span><span class=mord><span class=mord mathnormal>x</span></span></span><span style=top:-3.23em;><span class=pstrut style=height:3em;></span><span class=frac-line style=border-bottom-width:0.04em;></span></span><span style=top:-3.677em;><span class=pstrut style=height:3em;></span><span class=mord><span class=mord>2</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.686em;><span></span></span></span></span></span><span class=mclose nulldelimiter></span></span></span></span></span></p>
</summary>
<br>
有理数</p>
</details>

通过前三个例子对比发现,当 summary 部分有 } 字符时,会额外插入段落标记。

而当 summary 部分同时有 } 和数学公式的时候(无论 } 在公式里面还是公式外面),这就导致 katex 生成的源代码缺少引号,最终导致显示错误。

Steps to reproduce the behavior

能够复现的最小示例:

cd /tmp
hexo init hexo-test --no-install
cd hexo-test
npm install hexo-theme-next
npm uninstall hexo-theme-landscape
cp node_modules/hexo-theme-next/_config.yml _config.next.yml
sed -i "s/landscape/next/" _config.yml

## 测试文件
hexo new test
cat <<-EOF >>source/_posts/test.md

	{% note info 标{题 %}
	内容
	{% endnote %}

	{% note info 标}题 %}
	内容
	{% endnote %}

	{% note info 标\}题 %}
	内容
	{% endnote %}

EOF

## 启用数学支持
sed -i '/katex:/{n;s/enable: false/enable: true/}' _config.next.yml
sed -i 's/every_page: false/every_page: true/' _config.next.yml
npm uninstall hexo-renderer-marked
npm install hexo-renderer-markdown-it @renbaoshuo/markdown-it-katex

cat <<EOF >>_config.yml
markdown:
  render:
    html: true
    xhtmlOut: false
    breaks: true
    linkify: true
    typographer: false
    quotes: '“”‘’'
  plugins:
    - '@renbaoshuo/markdown-it-katex'
EOF

## 测试文件
cat <<-EOF >>source/_posts/test.md
	{% note danger 构{造:$\dfrac2x$。 %}
	有理数
	{% endnote %}

	{% note danger 构}造:$\dfrac2x$。 %}
	有理数
	{% endnote %}

	{% note danger 构\}造:$\dfrac2x$。 %}
	有理数
	{% endnote %}

EOF

Node.js and NPM Information

v22.13.1
10.9.2

Package dependencies Information

hexo-site@0.0.0 /tmp/hexo-test
├── @renbaoshuo/markdown-it-katex@2.0.2
├── hexo-generator-archive@2.0.0
├── hexo-generator-category@2.0.0
├── hexo-generator-index@4.0.0
├── hexo-generator-tag@2.0.0
├── hexo-renderer-ejs@2.0.0
├── hexo-renderer-markdown-it@7.1.1
├── hexo-renderer-stylus@3.0.1
├── hexo-server@3.0.0
├── hexo-theme-next@8.25.0
└── hexo@8.0.0

Hexo Configuration

# 剩余部分为 hexo init 默认生成的配置

markdown:
  render:
    html: true
    xhtmlOut: false
    breaks: true
    linkify: true
    typographer: false
    quotes: '“”‘’'
  plugins:
    - '@renbaoshuo/markdown-it-katex'

NexT Configuration

math:
  every_page: true

  mathjax:
    enable: false
    tags: none

  katex:
    enable: true
    copy_tex: false

Other Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions