diff --git a/app/assets/javascripts/discourse/lib/markdown.js b/app/assets/javascripts/discourse/lib/markdown.js index 66b2a7ea97d..13a5b80bbd2 100644 --- a/app/assets/javascripts/discourse/lib/markdown.js +++ b/app/assets/javascripts/discourse/lib/markdown.js @@ -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); diff --git a/lib/excerpt_parser.rb b/lib/excerpt_parser.rb index dbbafc33386..9afa2f2d991 100644 --- a/lib/excerpt_parser.rb +++ b/lib/excerpt_parser.rb @@ -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("", false, false, false) if @in_spoiler @in_spoiler = false end diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index f55219b75c7..add42031657 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -181,6 +181,12 @@ describe PrettyText do PrettyText.excerpt(nil,100).should == '' end + it "handles span excerpt" do + PrettyText.excerpt("hi test",100).should == 'hi' + post = Fabricate(:post, raw: "hi test") + post.excerpt.should == "hi" + end + end describe "strip links" do