mirror of
https://github.com/discourse/discourse.git
synced 2026-08-11 05:25:16 -05:00
FIX: Ignore max excerpt length for div excerpts too (#13058)
We support two types of custom excerpts. It can be <div class="excerpt"> or <span class="excerpt">: https://github.com/discourse/discourse/blob/b21f74060e865d809ba466cb52e6cb95c7b0cf1f/lib/excerpt_parser.rb#L120 We also ignore max excerpt length for custom excerpts. But we forgot to process div when ignoring max length.
This commit is contained in:
@@ -4,7 +4,7 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
|
||||
|
||||
attr_reader :excerpt
|
||||
|
||||
SPAN_REGEX = /<\s*span[^>]*class\s*=\s*['|"]excerpt['|"][^>]*>/
|
||||
CUSTOM_EXCERPT_REGEX = /<\s*(span|div)[^>]*class\s*=\s*['"]excerpt['"][^>]*>/
|
||||
|
||||
def initialize(length, options = nil)
|
||||
@length = length
|
||||
@@ -29,7 +29,7 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
|
||||
|
||||
def self.get_excerpt(html, length, options)
|
||||
html ||= ''
|
||||
length = html.length if html.include?('excerpt') && SPAN_REGEX === html
|
||||
length = html.length if html.include?('excerpt') && CUSTOM_EXCERPT_REGEX === html
|
||||
me = self.new(length, options)
|
||||
parser = Nokogiri::HTML::SAX::Parser.new(me)
|
||||
catch(:done) do
|
||||
|
||||
Reference in New Issue
Block a user