【问题标题】:jekyll different line break rules for post and Staticman commentsjekyll 用于帖子和静态人评论的不同换行规则
【发布时间】:2023-12-21 11:40:01
【问题描述】:

我想对用 Markdown 编写的帖子和从 Staticman 收到的 cmets 应用不同的换行规则。

这是 ma​​rkdown 中的示例:

Test
New line without a gap

New line with a gap.

这是 Staticman json 的交付方式:

message: "Test\r\nNew line without a gap\r\n\r\nNew line with a gap."

在帖子中,我希望它呈现为:

<p>Test
New line without a gap</p>

<p>New line with a gap.</p>        

在cmets中,应该在Test之后包含&lt;br&gt;

<p>Test<br>
New line without a gap</p>

<p>New line with a gap.</p>     

我可以在_config.yml 中使用 kramdown 设置 hard_wrap 来实现这两种格式,但我不知道如何为帖子和 cmets 设置不同的设置。

也许我可以在 cmets.html 中添加一些过滤器,现在看起来如下:

{{ include.message | strip_html | markdownify html=content }}

我试过newline_to_br。这不是一种选择。它引入了太多的中断:

<p>Test<br>
New line without a gap</p><br>
<br>
<p>New line with a gap.</p><br>

【问题讨论】:

    标签: html markdown jekyll liquid


    【解决方案1】:

    作为临时解决方案,我使用white-space CSS 修复了它:

    .comment p {
      white-space: pre-line;
    }
    

    【讨论】:

      最近更新 更多