代码块中的Markdown换行符

Kar*_*arl 6 ruby markdown haml redcarpet

使用Redcarpet,当我在我的降价中包含类似下面的内容时,它不会考虑任何换行符或缩进.我在线的末尾尝试了两个空格.代码之间的额外行.似乎没什么用.

```xml
<?xml version="1.0" encoding="UTF-8"?>
<hash>
   <money>3</money>
</hash>

```
Run Code Online (Sandbox Code Playgroud)

我知道了:

<?xml version="1.0" encoding="UTF-8"?> <hash> <money>3</money> </hash>
Run Code Online (Sandbox Code Playgroud)

以下是Redcarpet设置:

Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true, :fenced_code_blocks => true, :no_intra_emphasis => true, :lax_html_blocks => true)
Run Code Online (Sandbox Code Playgroud)

我需要做些什么来使线条正确断开并保留缩进,就像在这里或在GitHub上一样?

更新 - 源代码如下:

<pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
                &lt;hash&gt;
                &lt;money&gt;3&lt;/money&gt;
                &lt;/hash&gt;  
                </code></pre>
Run Code Online (Sandbox Code Playgroud)

Rya*_*ary 5

尝试将降价结果包装在find_and_preserveHaml助手中

# Assuming a setup like this:
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
code_snippet = "    <xml>\n      <tag/>\n    </xml>"

# This should prevent undesirable spaces within code blocks:
find_and_preserve(markdown.render(code_snippet)).html_safe
Run Code Online (Sandbox Code Playgroud)

当您使用find_and_preserveHaml助手包装渲染调用时,<pre>markdown输出中标记内的所有换行都会使用等效的HTML实体进行转义,然后Haml自动缩进将忽略它们.


tih*_*ihm 0

尝试使用此脚本来隔离它是否是您的应用程序或红地毯中的内容。

我无法重现您遇到的问题(使用 redcarpet-2.1.1 gem)。将其放入文件中,然后运行它(ruby redcarpet_test.rb):

require 'rubygems'
require 'redcarpet'

md = %Q{...
```xml
<?xml version="1.0" encoding="UTF-8"?>
<hash>
   <money>3</money>
</hash>
```
...}

r = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true, :fenced_code_blocks => true, :no_intra_emphasis => true, :lax_html_blocks => true)

puts r.render md
Run Code Online (Sandbox Code Playgroud)

其结果是:

<p>...
<code>xml
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;hash&gt;
   &lt;money&gt;3&lt;/money&gt;
&lt;/hash&gt;
</code>
...</p>
Run Code Online (Sandbox Code Playgroud)