Skip to content

A platform for community discussion. Free, open, simple.

FIX: allow user quotes in HTML digest emails

Régis Hanol9d9332d8c969
diff --git a/app/helpers/user_notifications_helper.rb b/app/helpers/user_notifications_helper.rb
index dd57d457943..b284f69c611 100644
--- a/app/helpers/user_notifications_helper.rb
+++ b/app/helpers/user_notifications_helper.rb
@@ -37,13 +37,15 @@ module UserNotificationsHelper
result = ""
length = 0
- doc.css('body > p, aside.onebox, body > ul').each do |node|
+
+ doc.css('body > p, aside.onebox, body > ul, body > blockquote').each do |node|
if node.text.present?
result << node.to_s
length += node.inner_text.length
return result if length >= SiteSetting.digest_min_excerpt_length
end
end
+
return result unless result.blank?
# If there is no first paragaph, return the first div (onebox)
diff --git a/spec/helpers/user_notifications_helper_spec.rb b/spec/helpers/user_notifications_helper_spec.rb
index dcd5cdcfce0..32e1f140809 100644
--- a/spec/helpers/user_notifications_helper_spec.rb
+++ b/spec/helpers/user_notifications_helper_spec.rb
@@ -34,5 +34,23 @@ describe UserNotificationsHelper do
SiteSetting.digest_min_excerpt_length = 50
expect(helper.email_excerpt(arg)).to eq([with_link, paragraphs[0]].join)
end
+
+ it "uses user quotes but not post quotes" do
+ cooked = <<~HTML
+ <p>BEFORE</p>
+ <blockquote>
+ <p>This is a user quote</p>
+ </blockquote>
+ <aside class="quote" data-post="3" data-topic="87369">
+ <div class="title">A Title</div>
+ <blockquote>
+ <p>This is a post quote</p>
+ </blockquote>
+ </aside>
+ <p>AFTER</p>
+ HTML
+
+ expect(helper.email_excerpt(cooked)).to eq "<p>BEFORE</p><blockquote>\n <p>This is a user quote</p>\n</blockquote><p>AFTER</p>"
+ end
end
end