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

时间:2011-06-12 23:28:53

标签: html ruby haml markdown maruku

我正在使用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输入,它按照我的预期呈现(也就是说,单个块中的两行代码都缩进到同一级别)。但是对于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!");

1 个答案:

答案 0 :(得分:7)

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

当谈到空白并保留空白时,HAML很挑剔。解决方案在渲染时需要使用= preserve @my_html_string

例如,给定layout.haml

!!! 5
%html
    %body
        = yield

index.haml

%article
    = preserve @my_html_fragment_with_pre_and_code

然后它会正确呈现给我。

相关问题