Permalink
Browse files

Revert line break changes

  • Loading branch information...
1 parent d0f45e7 commit 26cc2b868bc9914f2b276cad3b03432a56489fa7 @calexicoz calexicoz committed Mar 28, 2012
Showing with 19 additions and 2 deletions.
  1. +7 −0 lib/model_formatting.rb
  2. +12 −2 test/model_formatting_test.rb
View
@@ -182,6 +182,13 @@ def self.gfm(text)
text.gsub!(/(^(?! {4}|\t)\w+_\w+_\w[\w_]*)/) do |x|
x.gsub('_', '\_') if x.split('').sort.to_s[0..1] == '__'
end
+
+ # in very clear cases, let newlines become <br /> tags
+ #text.gsub!(/(\A|^$\n)(^\w[^\n]*\n)(^\w[^\n]*$)+/m) do |x|
+ # x.gsub(/^(.+)$/, "\\1 ")
+ text.gsub!(/^[\w\<][^\n]*\n+/) do |x|
+ x =~ /\n{2}/ ? x : (x.strip!; x << " \n")
+ end
end
end
@@ -88,7 +88,8 @@ class ModelFormattingTest < Test::Unit::TestCase
it "treats linebreaks correctly" do
ModelFormatting.process(:html, "Line breaks should not be treated as\nnew paragraphs. They are not paragraphs.\n\nHowever, when a line is skipped, that is a paragraph.\nGMail, and basically every comment or submission form on the \nweb work this way.").should == \
- "<div><p>Line breaks should not be treated as new paragraphs. They are\nnot paragraphs.</p>\n<p>However, when a line is skipped, that is a paragraph. GMail, and\nbasically every comment or submission form on the web work this\nway.</p></div>"
+ "<div><p>Line breaks should not be treated as<br>\nnew paragraphs. They are not paragraphs.</p>\n<p>However, when a line is skipped, that is a paragraph.<br>\nGMail, and basically every comment or submission form on the<br>\nweb work this way.</p></div>"
+
end
describe "GFM" do
@@ -107,7 +108,16 @@ class ModelFormattingTest < Test::Unit::TestCase
it "escapes two or more underscores inside words" do
assert_equal "foo\\_bar\\_baz", ModelFormatting.gfm("foo_bar_baz")
end
-
+
+ it "turns newlines into br tags in simple cases" do
+ assert_equal "foo \nbar", ModelFormatting.gfm("foo\nbar")
+ end
+
+ it "converts newlines in all groups" do
+ assert_equal "apple \npear \norange \nbanana\n\nruby \npython \nerlang \njavascript",
+ ModelFormatting.gfm("apple\npear\norange\nbanana\n\nruby\npython\nerlang\njavascript")
+ end
+
it "does not not convert newlines in lists" do
assert_equal "# foo\n# bar", ModelFormatting.gfm("# foo\n# bar")
assert_equal "* foo\n* bar", ModelFormatting.gfm("* foo\n* bar")

0 comments on commit 26cc2b8

Please sign in to comment.