mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 19:11:16 +08:00
FEATURE: Allow manual excerpt to be specified anywhere in the post and override max excerpt length
This commit is contained in:
@ -2,6 +2,8 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
|
||||
|
||||
attr_reader :excerpt
|
||||
|
||||
SPAN_REGEX = /<\s*span[^>]*class\s*=\s*['|"]excerpt['|"][^>]*>/
|
||||
|
||||
def initialize(length, options=nil)
|
||||
@length = length
|
||||
@excerpt = ""
|
||||
@ -14,10 +16,14 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
|
||||
end
|
||||
|
||||
def self.get_excerpt(html, length, options)
|
||||
me = self.new(length,options)
|
||||
html ||= ''
|
||||
if (html.include? 'excerpt') && (SPAN_REGEX === html)
|
||||
length = html.length
|
||||
end
|
||||
me = self.new(length, options)
|
||||
parser = Nokogiri::HTML::SAX::Parser.new(me)
|
||||
catch(:done) do
|
||||
parser.parse(html) unless html.nil?
|
||||
parser.parse(html)
|
||||
end
|
||||
me.excerpt.strip!
|
||||
me.excerpt
|
||||
|
Reference in New Issue
Block a user