Commit e1c95655a231e4eadfd9500c7c763c8e9d9afc57
Committed by
Joenio Costa
1 parent
1607e1bb
Exists in
staging
and in
42 other branches
Disable hard line breaks
Without this, single line breaks withing a paragraph get translated to a HTML <br/>, which is completely annoying *and* counter-intuitive in comparison with most markup languages like Textile.
Showing
2 changed files
with
7 additions
and
1 deletions
Show diff stats
app/models/textile_article.rb
| ... | ... | @@ -28,7 +28,9 @@ class TextileArticle < TextArticle |
| 28 | 28 | |
| 29 | 29 | def convert_to_html(textile) |
| 30 | 30 | @@sanitizer ||= HTML::WhiteListSanitizer.new |
| 31 | - @@sanitizer.sanitize(RedCloth.new(textile|| '').to_html) | |
| 31 | + converter = RedCloth.new(textile|| '') | |
| 32 | + converter.hard_breaks = false | |
| 33 | + @@sanitizer.sanitize(converter.to_html) | |
| 32 | 34 | end |
| 33 | 35 | |
| 34 | 36 | end | ... | ... |
test/unit/textile_article_test.rb
| ... | ... | @@ -182,6 +182,10 @@ class TextileArticleTest < Test::Unit::TestCase |
| 182 | 182 | assert_not_equal '<script>alert(1)</script>', build_article(nil, :abstract => '<script>alert(1)</script>').lead |
| 183 | 183 | end |
| 184 | 184 | |
| 185 | + should 'not add hard breaks for single line breaks' do | |
| 186 | + assert_equal "<p>one\nparagraph</p>", build_article("one\nparagraph").to_html | |
| 187 | + end | |
| 188 | + | |
| 185 | 189 | protected |
| 186 | 190 | |
| 187 | 191 | def build_article(input = nil, options = {}) | ... | ... |