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

jbr*_*nan 3 html ruby markdown haml 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!");
Run Code Online (Sandbox Code Playgroud)

所以我的第一行代码(我在我的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>
Run Code Online (Sandbox Code Playgroud)

我用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!");
Run Code Online (Sandbox Code Playgroud)

jbr*_*nan 7

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

HAML在空白和保留它时很挑剔.解决方案需要= preserve @my_html_string在渲染时使用.

例如,给定layout.haml:

!!! 5
%html
    %body
        = yield
Run Code Online (Sandbox Code Playgroud)

index.haml

%article
    = preserve @my_html_fragment_with_pre_and_code
Run Code Online (Sandbox Code Playgroud)

然后它会正确呈现给我.