代码块中的Markdown换行符 [英] Markdown Line Breaks in Code Blocks
问题描述
使用Redcarpet时,当我在降价促销中加入以下内容时,它不会出现任何换行或缩进的情况.我在行尾尝试了两个空格.代码之间的多余行.似乎什么都没用.
Using Redcarpet, when I include something like the following in my markdown, it does not respect any line breaks or indention. I've tried two spaces at the end of lines. Extra lines between code. Nothing seems to work.
```xml
<?xml version="1.0" encoding="UTF-8"?>
<hash>
<money>3</money>
</hash>
```
我知道了
<?xml version="1.0" encoding="UTF-8"?> <hash> <money>3</money> </hash>
以下是红地毯"设置:
Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true, :fenced_code_blocks => true, :no_intra_emphasis => true, :lax_html_blocks => true)
我该怎么做才能使行正确断开并保留缩进,就像在这里或在GitHub上一样?
What do I need to do to make the lines break properly and preserve indention, just like here or on GitHub?
更新-来源如下:
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<hash>
<money>3</money>
</hash>
</code></pre>
推荐答案
尝试将减价结果包装在find_and_preserve
Haml helper
中
Try wrapping the markdown result in the find_and_preserve
Haml helper
# 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
当使用find_and_preserve
Haml帮助器包装渲染调用时,markdown输出中<pre>
标记内的所有换行符都将被等效的HTML实体转义,然后Haml自动缩进将忽略它们.
When you wrap the render call with the find_and_preserve
Haml helper, all newlines within <pre>
tags in the markdown output are escaped with equivalent HTML entities, and the Haml auto-indention will then ignore them.
这篇关于代码块中的Markdown换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!