2013-12-11 74 views
2

即使內容中有空格和換行符,我也無法獲得換行符<br>。有沒有什麼辦法可以在redcarpet中啓用。無法使用redcarpet獲得換行符

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

「當你要插入使用降價一
休息標籤,你行尾有兩個或多個空格,然後鍵入的回報。」

爲什麼紅地毯沒有檢測到空的空間線?

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> 

回答

4

<br>元素不會添加如果行是最後一個段落 - 只有在有下一行的東西。例如,這降價(其中所有的線有兩個尾隨空格):

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. 

產生這個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> s被添加到相同行中)相同。