0
0
Fork 0

Change some instances of Nokogiri HTML4 parsing to HTML5 (#31812)

This commit is contained in:
Mike Dalessio 2024-09-08 14:41:37 -04:00 committed by GitHub
parent b716248fc5
commit 10143d053a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 11 additions and 11 deletions

View file

@ -24,7 +24,7 @@ class EmojiFormatter
def to_s
return html if custom_emojis.empty? || html.blank?
tree = Nokogiri::HTML.fragment(html)
tree = Nokogiri::HTML5.fragment(html)
tree.xpath('./text()|.//text()[not(ancestor[@class="invisible"])]').to_a.each do |node|
i = -1
inside_shortname = false
@ -43,8 +43,8 @@ class EmojiFormatter
next unless (char_after.nil? || !DISALLOWED_BOUNDING_REGEX.match?(char_after)) && (emoji = emoji_map[shortcode])
result << Nokogiri::XML::Text.new(text[last_index..shortname_start_index - 1], tree.document) if shortname_start_index.positive?
result << Nokogiri::HTML.fragment(tag_for_emoji(shortcode, emoji))
result << tree.document.create_text_node(text[last_index..shortname_start_index - 1]) if shortname_start_index.positive?
result << tree.document.fragment(tag_for_emoji(shortcode, emoji))
last_index = i + 1
elsif text[i] == ':' && (i.zero? || !DISALLOWED_BOUNDING_REGEX.match?(text[i - 1]))
@ -53,7 +53,7 @@ class EmojiFormatter
end
end
result << Nokogiri::XML::Text.new(text[last_index..], tree.document)
result << tree.document.create_text_node(text[last_index..])
node.replace(result)
end