diff --git a/lib/excerpt_parser.rb b/lib/excerpt_parser.rb
index 112b3ec20c1..dbbafc33386 100644
--- a/lib/excerpt_parser.rb
+++ b/lib/excerpt_parser.rb
@@ -49,8 +49,16 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
include_tag(name, attributes)
@in_a = true
end
+
when "aside"
@in_quote = true
+
+ when "div", "span"
+ # Preserve spoilers
+ if attributes.any? {|x| x == ["class", "spoiler"] }
+ include_tag("span", attributes)
+ @in_spoiler = true
+ end
end
end
@@ -65,6 +73,9 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
characters(" ")
when "aside"
@in_quote = false
+ when "div", "span"
+ characters("", false, false, false) if @in_spoiler
+ @in_spoiler = false
end
end
diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb
index 378ef51c356..e5e4fbe28f3 100644
--- a/spec/components/pretty_text_spec.rb
+++ b/spec/components/pretty_text_spec.rb
@@ -92,6 +92,10 @@ describe PrettyText do
PrettyText.excerpt("
", 100, markdown_images: true).should == ""
end
+ it "should keep spoilers" do
+ PrettyText.excerpt("
