Feature: allow mods to cut pinned topic excerpts

This commit is contained in:
Sam 2014-07-17 21:32:17 +10:00
parent f2093fb4de
commit de7e6a9545
3 changed files with 15 additions and 1 deletions

View file

@ -260,4 +260,7 @@ Discourse.Markdown.whiteListTag('span', 'bbcode-i');
Discourse.Markdown.whiteListTag('span', 'bbcode-u');
Discourse.Markdown.whiteListTag('span', 'bbcode-s');
// used for pinned topics
Discourse.Markdown.whiteListTag('span', 'class', 'excerpt');
Discourse.Markdown.whiteListIframe(/^(https?:)?\/\/www\.google\.com\/maps\/embed\?.+/i);

View file

@ -10,6 +10,7 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
@strip_links = options[:strip_links] == true
@text_entities = options[:text_entities] == true
@markdown_images = options[:markdown_images] == true
@start_excerpt = false
end
def self.get_excerpt(html, length, options)
@ -54,8 +55,11 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
@in_quote = true
when "div", "span"
if attributes.include?(["class", "excerpt"])
@start_excerpt = true
end
# Preserve spoilers
if attributes.any? {|x| x == ["class", "spoiler"] }
if attributes.include?(["class", "spoiler"])
include_tag("span", attributes)
@in_spoiler = true
end
@ -74,6 +78,7 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
when "aside"
@in_quote = false
when "div", "span"
throw :done if @start_excerpt
characters("</span>", false, false, false) if @in_spoiler
@in_spoiler = false
end

View file

@ -181,6 +181,12 @@ describe PrettyText do
PrettyText.excerpt(nil,100).should == ''
end
it "handles span excerpt" do
PrettyText.excerpt("<span class='excerpt'>hi</span> test",100).should == 'hi'
post = Fabricate(:post, raw: "<span class='excerpt'>hi</span> test")
post.excerpt.should == "hi"
end
end
describe "strip links" do