Permalink
Browse files

Merge pull request #8 from entp/revert_line_break_changes_in_master

Revert line break changes
  • Loading branch information...
2 parents a42a6a1 + 73b55a2 commit e443a010ef6e79991369bf296225b98a93d11e40 @zenhob zenhob committed Mar 28, 2012
Showing with 20 additions and 3 deletions.
  1. +1 −1 Rakefile
  2. +7 −0 lib/model_formatting.rb
  3. +12 −2 test/model_formatting_test.rb
View
2 Rakefile
@@ -3,7 +3,7 @@ require 'rake/testtask'
spec = Gem::Specification.new do |s|
s.name = "model_formatting"
- s.version = "0.3.2"
+ s.version = "0.3.3"
s.author = "ENTP"
s.email = "company@entp.com"
s.homepage = "http://github.com/entp"
View
7 lib/model_formatting.rb
@@ -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
View
14 test/model_formatting_test.rb
@@ -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 e443a01

Please sign in to comment.