我使用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是因为我需要定义列表。
如何格式化它:
这是一条普通线路
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!");发布于 2011-06-14 02:39:03
事实证明,这不是Maruku问题,而是HAML问题。
当涉及到空白和保留空白时,HAML是挑剔的。解决方案是在渲染时使用= preserve @my_html_string。
例如,给定layout.haml
!!! 5
%html
%body
= yield和index.haml
%article
= preserve @my_html_fragment_with_pre_and_code然后它将为我正确地渲染。
https://stackoverflow.com/questions/6325416
复制相似问题