mirror of
https://github.com/discourse/discourse.git
synced 2025-08-21 19:11:18 +08:00
FIX: details tags broke excerpts
This commit is contained in:
parent
c1716d41c7
commit
b3fda0ea86
5 changed files with 31 additions and 1 deletions
|
@ -18,6 +18,7 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
|
|||
@keep_onebox_source = options[:keep_onebox_source] == true
|
||||
@remap_emoji = options[:remap_emoji] == true
|
||||
@start_excerpt = false
|
||||
@summary_contents = ""
|
||||
end
|
||||
|
||||
def self.get_excerpt(html, length, options)
|
||||
|
@ -108,6 +109,10 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
|
|||
include_tag("span", attributes)
|
||||
@in_spoiler = true
|
||||
end
|
||||
when "details"
|
||||
@in_details = true
|
||||
when "summary"
|
||||
@in_summary = true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -126,6 +131,14 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
|
|||
end
|
||||
when "aside"
|
||||
@in_quote = false
|
||||
when "details"
|
||||
@in_details = false
|
||||
when "summary"
|
||||
@in_summary = false
|
||||
if @summary_contents.present?
|
||||
@excerpt << "<details class='disabled'><summary>#{@summary_contents[0..@length]}</summary></details>"
|
||||
end
|
||||
@summary_contents = ""
|
||||
when "div", "span"
|
||||
throw :done if @start_excerpt
|
||||
characters("</span>", false, false, false) if @in_spoiler
|
||||
|
@ -135,8 +148,15 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
|
|||
|
||||
def characters(string, truncate = true, count_it = true, encode = true)
|
||||
return if @in_quote
|
||||
|
||||
# we call length on this so might as well ensure we have a string
|
||||
string = string.to_s
|
||||
if @in_details
|
||||
if @in_summary
|
||||
@summary_contents << string
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
encode = encode ? lambda { |s| ERB::Util.html_escape(s) } : lambda { |s| s }
|
||||
if count_it && @current_length + string.length > @length
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue