mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 11:58:33 +08:00
FIX: Do not add empty use/svg tags in ExcerptParser (#19969)
There was an issue where if hashtag-cooked HTML was sent to the ExcerptParser without the keep_svg option, we would end up with empty </use> and </svg> tags on the parts of the excerpt where the hashtag was, in this case when a post push notification was sent. Fixed this, and also added a way to only display a plaintext version of the hashtag for cases like this via PrettyText#excerpt.
This commit is contained in:
@ -469,10 +469,21 @@ module PrettyText
|
||||
DiscourseEvent.trigger(:reduce_excerpt, doc, options)
|
||||
strip_image_wrapping(doc)
|
||||
strip_oneboxed_media(doc)
|
||||
|
||||
if SiteSetting.enable_experimental_hashtag_autocomplete && options[:plain_hashtags]
|
||||
convert_hashtag_links_to_plaintext(doc)
|
||||
end
|
||||
|
||||
html = doc.to_html
|
||||
ExcerptParser.get_excerpt(html, max_length, options)
|
||||
end
|
||||
|
||||
def self.convert_hashtag_links_to_plaintext(doc)
|
||||
doc
|
||||
.css("a.hashtag-cooked")
|
||||
.each { |hashtag| hashtag.replace("##{hashtag.attributes["data-slug"]}") }
|
||||
end
|
||||
|
||||
def self.strip_links(string)
|
||||
return string if string.blank?
|
||||
|
||||
|
Reference in New Issue
Block a user