diff --git a/app/helpers/user_notifications_helper.rb b/app/helpers/user_notifications_helper.rb
index 4389125bd1..eb0293183b 100644
--- a/app/helpers/user_notifications_helper.rb
+++ b/app/helpers/user_notifications_helper.rb
@@ -49,7 +49,7 @@ module UserNotificationsHelper
# If there is no first paragaph with text, return the first paragraph with
# something else (an image) or div (a onebox).
- doc.css('body > p, body > div').first
+ doc.css('body > p:not(:empty), body > div:not(:empty), body > p > div.lightbox-wrapper img').first
end
def email_excerpt(html_arg, post = nil)
diff --git a/spec/helpers/user_notifications_helper_spec.rb b/spec/helpers/user_notifications_helper_spec.rb
index b72dcf82c0..21e0a181fe 100644
--- a/spec/helpers/user_notifications_helper_spec.rb
+++ b/spec/helpers/user_notifications_helper_spec.rb
@@ -28,6 +28,22 @@ describe UserNotificationsHelper do
HTML
end
+ let(:image_paragraph) do
+ '

'
+ end
+
+ let(:lightbox_image) do
+ <<~HTML
+
+ HTML
+ end
+
+ let(:expected_lightbox_image) do
+ ''
+ end
+
it "can return the first paragraph" do
SiteSetting.digest_min_excerpt_length = 50
expect(helper.email_excerpt(cooked)).to eq(paragraphs[0])
@@ -71,7 +87,7 @@ describe UserNotificationsHelper do
end
it "defaults to content after post quote (image w/ no text)" do
- image_paragraph = '
'
+
cooked = <<~HTML
#{post_quote}
#{image_paragraph}
@@ -87,6 +103,23 @@ describe UserNotificationsHelper do
HTML
expect(helper.email_excerpt(cooked)).to eq(aside_onebox)
end
+
+ it "defaults to content after post quote (lightbox image w/ no text)" do
+ cooked = <<~HTML
+ #{post_quote}
+ #{lightbox_image}
+ HTML
+ expect(helper.email_excerpt(cooked)).to eq(expected_lightbox_image)
+ end
+
+ it "handles when there's only an image" do
+ image_paragraph
+ expect(helper.email_excerpt("#{image_paragraph}")).to eq(image_paragraph)
+ end
+
+ it "handles when there's only a lightboxed image" do
+ expect(helper.email_excerpt("#{lightbox_image}")).to eq(expected_lightbox_image)
+ end
end
describe '#logo_url' do