From e781a758adfa106817daaef76d72cd14888f3489 Mon Sep 17 00:00:00 2001 From: Vikhyat Korrapati Date: Thu, 20 Feb 2014 14:18:30 +0530 Subject: [PATCH] Preserve spoiler tags in post excerpts. --- lib/excerpt_parser.rb | 11 +++++++++++ spec/components/pretty_text_spec.rb | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/lib/excerpt_parser.rb b/lib/excerpt_parser.rb index 112b3ec20..dbbafc333 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 378ef51c3..e5e4fbe28 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 == "![car](http://cnn.com/a.gif)" end + it "should keep spoilers" do + PrettyText.excerpt("
", 100).should == "[image]" + PrettyText.excerpt("spoiler", 100).should == "spoiler" + end end it "should have an option to strip links" do