From 37304b7ebad85791010c2129fd18be1db20a1d19 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 27 Sep 2013 15:08:30 -0400 Subject: [PATCH] FIX: Too many new lines in long quotes --- .../javascripts/discourse/dialects/quote_dialect.js | 12 ++++++++++-- spec/components/pretty_text_spec.rb | 6 +++--- test/javascripts/components/bbcode_test.js | 6 +++--- test/javascripts/components/markdown_test.js | 8 ++++---- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/discourse/dialects/quote_dialect.js b/app/assets/javascripts/discourse/dialects/quote_dialect.js index 7bece862c04..aa79055e723 100644 --- a/app/assets/javascripts/discourse/dialects/quote_dialect.js +++ b/app/assets/javascripts/discourse/dialects/quote_dialect.js @@ -30,8 +30,16 @@ Discourse.Dialect.replaceBlock({ avatarImg = options.lookupAvatar(username); } - var contents = this.processInline(blockContents.join(" \n \n")); - contents.unshift('blockquote'); + var contents = ['blockquote']; + if (blockContents.length) { + var self = this; + blockContents.forEach(function (bc) { + var processed = self.processInline(bc); + if (processed.length) { + contents.push(['p'].concat(processed)); + } + }); + } return ['p', ['aside', params, ['div', {'class': 'title'}, diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index 169f6cee490..d34ccd6abb8 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -14,15 +14,15 @@ describe PrettyText do end it "produces a quote even with new lines in it" do - PrettyText.cook("[quote=\"EvilTrout, post:123, topic:456, full:true\"]ddd\n[/quote]").should match_html "

" + PrettyText.cook("[quote=\"EvilTrout, post:123, topic:456, full:true\"]ddd\n[/quote]").should match_html "

" end it "should produce a quote" do - PrettyText.cook("[quote=\"EvilTrout, post:123, topic:456, full:true\"]ddd[/quote]").should match_html "

" + PrettyText.cook("[quote=\"EvilTrout, post:123, topic:456, full:true\"]ddd[/quote]").should match_html "

" end it "trims spaces on quote params" do - PrettyText.cook("[quote=\"EvilTrout, post:555, topic: 666\"]ddd[/quote]").should match_html "

" + PrettyText.cook("[quote=\"EvilTrout, post:555, topic: 666\"]ddd[/quote]").should match_html "

" end end diff --git a/test/javascripts/components/bbcode_test.js b/test/javascripts/components/bbcode_test.js index 60112f708d0..d0b4c118fb1 100644 --- a/test/javascripts/components/bbcode_test.js +++ b/test/javascripts/components/bbcode_test.js @@ -83,17 +83,17 @@ test("quote formatting", function() { format("[quote=\"EvilTrout, post:123, topic:456, full:true\"][sam][/quote]", "", + "
EvilTrout said:

[sam]

", "it allows quotes with [] inside"); format("[quote=\"eviltrout, post:1, topic:1\"]abc[/quote]", "", + "

abc

", "renders quotes properly"); format("[quote=\"eviltrout, post:1, topic:1\"]abc[/quote]\nhello", "

\n\n

hello", + "

abc

\n\n

hello", "handles new lines properly"); }); diff --git a/test/javascripts/components/markdown_test.js b/test/javascripts/components/markdown_test.js index a27e7dca9a5..daa48b2b51f 100644 --- a/test/javascripts/components/markdown_test.js +++ b/test/javascripts/components/markdown_test.js @@ -129,22 +129,22 @@ test("simple quotes", function() { test("Quotes", function() { - cookedOptions("[quote=\"eviltrout, post: 1\"]\na quote\n\nsecond line\n[/quote]", + cookedOptions("[quote=\"eviltrout, post: 1\"]\na quote\n\nsecond line\n\nthird line[/quote]", { topicId: 2 }, "

", + "

a quote

second line

third line

", "works with multiple lines"); cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2", { topicId: 2, lookupAvatar: function(name) { return "" + name; } }, "

1

\n\n

\n\n

2

", + "bob said:

my quote

\n\n

2

", "handles quotes properly"); cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2", { topicId: 2, lookupAvatar: function(name) { } }, "

1

\n\n

\n\n

2

", + "

my quote

\n\n

2

", "includes no avatar if none is found"); });