Translate CW, poll options and media descriptions (#24175)
Co-authored-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
44cd88adc4
commit
69057467cb
25 changed files with 603 additions and 100 deletions
|
@ -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]))
|
||||
|
@ -75,7 +76,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(
|
||||
|
@ -103,4 +106,8 @@ class EmojiFormatter
|
|||
def animate?
|
||||
@options[:animate] || @options.key?(:style)
|
||||
end
|
||||
|
||||
def raw_shortcode?
|
||||
@options[:raw_shortcode]
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue