hexo-theme-fluid icon indicating copy to clipboard operation
hexo-theme-fluid copied to clipboard

对 html 中换行的错误处理

Open Sving1024 opened this issue 9 months ago • 1 comments

请确认

问题描述

tags 内的空格会消失。 例如,这段:

{% note success %}
第 1 个代码块:前 `a` 后,
第 2 个代码块:前 `ab` 后,  
第 3 个代码块:前 `abc` 后。 

第 1 个代码块:前 $a$ 后,
第 2 个代码块:前 $ab$ 后,
第 3 个代码块:前 $abc$ 后。

{% endnote %}

实际生成的 html 是这样的:

            <p>第 1 个代码块:前 <code>a</code> 后, 第 2 个代码块:前<code>ab</code> 后,<br />第 3 个代码块:前 <code>abc</code> 后。</p><p>第 1 个代码块:前 <span class="math inline">\(a\)</span> 后, 第 2个代码块:前 <span class="math inline">\(ab\)</span> 后, 第 3个代码块:前 <span class="math inline">\(abc\)</span> 后。</p>

ab 前的空格消失了,2和3后面的空格消失了。

Sving1024 avatar May 20 '25 15:05 Sving1024

https://github.com/jgm/pandoc/issues/10864

原因在 node.jsfold.js 中的这两行:

  return `<div class="note note-${args.join(' ')}">
            ${hexo.render.renderSync({ text: content, engine: 'markdown' }).split('\n').join('')}
          </div>`;

通常来说(在 white-space: normal 设置的情况下),换行与空格是等价的,因此拼接时中间应当添加空格,而不是一个空字符串,因此空格会消失。

应当直接删掉 .split('\n').join('') 或者改成 .split('\n').join(' ')

Sving1024 avatar May 24 '25 04:05 Sving1024

thx

zkqiang avatar Jul 15 '25 06:07 zkqiang