Merge commit 'c15c8c7aa8' into kb_migration

This commit is contained in:
KMY 2023-06-01 17:30:18 +09:00
commit 093cfdbb7b
208 changed files with 2976 additions and 5888 deletions

View file

@ -12,6 +12,7 @@ class EmojiFormatter
# @param [Hash] options
# @option options [Boolean] :animate
# @option options [String] :style
# @option options [String] :raw_shortcode
def initialize(html, custom_emojis, options = {})
raise ArgumentError unless html.html_safe?
@ -43,7 +44,7 @@ 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(image_for_emoji(shortcode, emoji))
result << Nokogiri::HTML.fragment(tag_for_emoji(shortcode, emoji))
last_index = i + 1
elsif text[i] == ':' && (i.zero? || !DISALLOWED_BOUNDING_REGEX.match?(text[i - 1]))
@ -78,7 +79,9 @@ class EmojiFormatter
end
end
def image_for_emoji(shortcode, emoji)
def tag_for_emoji(shortcode, emoji)
return content_tag(:span, ":#{shortcode}:", translate: 'no') if raw_shortcode?
original_url, static_url = emoji
image_tag(
@ -106,4 +109,8 @@ class EmojiFormatter
def animate?
@options[:animate] || @options.key?(:style)
end
def raw_shortcode?
@options[:raw_shortcode]
end
end