gpt4 book ai didi

ruby-on-rails - 无法使用 redcarpet 换行

转载 作者:数据小太阳 更新时间:2023-10-29 08:38:22 25 4
gpt4 key购买 nike

我无法获得换行符
,即使内容中有一行包含空格和换行符。有什么方法可以在 redcarpet 中启用。

http://daringfireball.net/projects/markdown/syntax#p

“当您确实想使用 Markdown 插入一个
中断标记时,您可以在一行结束时使用两个或更多空格,然后键入 return。”

为什么 redcarpet 没有检测到空白行?

Loading development environment (Rails 3.2.3)
irb(main):001:0> rendere = Redcarpet::Render::HTML.new(:hard_wrap => true)
=> #<Redcarpet::Render::HTML:0xa2cc414>
irb(main):002:0> markdown = Redcarpet::Markdown.new(rendere, :autolink => true, :space_after_headers => true)
=> #<Redcarpet::Markdown:0x98ab0c0>
irb(main):003:0> markdown.render("hi how are you doing\n \nFirst line in the next paragraph\n \nFirst line in the third paragraph\n")
=> "<p>hi how are you doing</p>\n\n<p>First line in the next paragraph</p>\n\n<p>First line in the third paragraph</p>\n"
irb(main):004:0> markdown.render("hi how are you doing\r\n \r\nFirst line in the next paragraph\r\n \r\nFirst line in the third paragraph\r\n")
=> "<p>hi how are you doing</p>\n\n<p>First line in the next paragraph</p>\n\n<p>First line in the third paragraph</p>\n"
irb(main):005:0>

最佳答案

<br>如果该行是段落中的最后一行,则不会添加元素——仅当下一行有内容时。例如这个 Markdown (所有行都有两个尾随空格):

Has trailing spaces, but no br.  

Several lines, all with trailing spaces.
All but the last have br elements at the end.
This line has spaces, but no br.

使用 Redcarpet 生成此 HTML:

<p>Has trailing spaces, but no br.  </p>

<p>Several lines, all with trailing spaces.<br>
All but the last have br elements at the end.<br>
This line has spaces, but no br. </p>

您的示例由三个单行段落组成,因此每一行都是该段落的最后一行并且没有 <br>添加。

此行为与原始 Markdown.pl 相同(基本上 - 输出不相同,但将 <br> 添加到同一行)。

关于ruby-on-rails - 无法使用 redcarpet 换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20532376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com