mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-16 03:30:05 -05:00
Preserve spoiler tags in post excerpts.
This commit is contained in:
parent
ac8203b601
commit
e781a758ad
2 changed files with 15 additions and 0 deletions
|
@ -49,8 +49,16 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
|
||||||
include_tag(name, attributes)
|
include_tag(name, attributes)
|
||||||
@in_a = true
|
@in_a = true
|
||||||
end
|
end
|
||||||
|
|
||||||
when "aside"
|
when "aside"
|
||||||
@in_quote = true
|
@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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -65,6 +73,9 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
|
||||||
characters(" ")
|
characters(" ")
|
||||||
when "aside"
|
when "aside"
|
||||||
@in_quote = false
|
@in_quote = false
|
||||||
|
when "div", "span"
|
||||||
|
characters("</span>", false, false, false) if @in_spoiler
|
||||||
|
@in_spoiler = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -92,6 +92,10 @@ describe PrettyText do
|
||||||
PrettyText.excerpt("<img src='http://cnn.com/a.gif' title='car'>", 100, markdown_images: true).should == "![car](http://cnn.com/a.gif)"
|
PrettyText.excerpt("<img src='http://cnn.com/a.gif' title='car'>", 100, markdown_images: true).should == "![car](http://cnn.com/a.gif)"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should keep spoilers" do
|
||||||
|
PrettyText.excerpt("<div class='spoiler'><img src='http://cnn.com/a.gif'></div>", 100).should == "<span class='spoiler'>[image]</span>"
|
||||||
|
PrettyText.excerpt("<span class='spoiler'>spoiler</div>", 100).should == "<span class='spoiler'>spoiler</span>"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should have an option to strip links" do
|
it "should have an option to strip links" do
|
||||||
|
|
Loading…
Reference in a new issue