gpt4 book ai didi

html - Maruku 错误地解析了第二行代码块?

转载 作者:数据小太阳 更新时间:2023-10-29 07:48:50 24 4
gpt4 key购买 nike

我正在使用 Maruku (Ruby) 来解析一些 Markdown 格式的文本。我在尝试像这样格式化一段 code 时遇到问题:

This is a normal line
# pretend this line is empty
printf("First line of code is OK");
printf("Second line of code (or any line thereafter) appears indented by an extra level, which is incorrect!");

所以我的第一行代码(我在我的 md 文件中缩进了 4 个空格(或制表符))按照我的预期呈现。但是,我的第二行代码(缩进了完全相同的数字空格)最终会在生成 HTML 时额外缩进 4 个空格。

输出看起来像这样:

This is a normal line
<pre><code>printf("First line of code is OK");
printf("Second line of code (or any line thereafter) appears indented by an extra level, which is incorrect!");</code></pre>

我已经使用 Gruber 的“Dingus”测试了我的 Markdown 输入,它的呈现方式与我预期的一样(也就是说,两行代码都在一个 block 中,都在同一级别缩进)。但对于 Maruku,它就是废话。

我也尝试过使用 RDiscount,但我得到了同样的效果。我正在使用 Maruku,因为我需要定义列表。

SO 如何格式化它:

这是一条普通的线

printf("First line of code is OK\n");
printf("Second line of code (or any line thereafter) appears indented by an extra level, which is incorrect!");

最佳答案

事实证明这不是 Maruku 问题而是 HAML 问题。

HAML 在处理空白和保留空白时非常挑剔。解决方案是在渲染时需要使用 = preserve @my_html_string

例如,给定layout.haml:

!!! 5
%html
%body
= yield

index.haml

%article
= preserve @my_html_fragment_with_pre_and_code

然后它会为我正确呈现。

关于html - Maruku 错误地解析了第二行代码块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6325416/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com