allow side-by-side emoji

(Let's see how this goes :woozycat:)
This commit is contained in:
hazycora 2023-12-14 00:21:22 -06:00 committed by Essem
parent dfe6628e4b
commit 2eab76cbcc
3 changed files with 3 additions and 16 deletions

View file

@ -3,8 +3,6 @@
class EmojiFormatter
include RoutingHelper
DISALLOWED_BOUNDING_REGEX = /[[:alnum:]:]/
attr_reader :html, :custom_emojis, :options
# @param [ActiveSupport::SafeBuffer] html
@ -39,15 +37,14 @@ class EmojiFormatter
if inside_shortname && text[i] == ':'
inside_shortname = false
shortcode = text[shortname_start_index + 1..i - 1]
char_after = text[i + 1]
next unless (char_after.nil? || !DISALLOWED_BOUNDING_REGEX.match?(char_after)) && (emoji = emoji_map[shortcode])
next unless (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))
last_index = i + 1
elsif text[i] == ':' && (i.zero? || !DISALLOWED_BOUNDING_REGEX.match?(text[i - 1]))
elsif text[i] == ':'
inside_shortname = true
shortname_start_index = i
end

View file

@ -29,9 +29,7 @@ class CustomEmoji < ApplicationRecord
SHORTCODE_RE_FRAGMENT = '[a-zA-Z0-9_]{2,}'
SCAN_RE = /(?<=[^[:alnum:]:]|\n|^)
:(#{SHORTCODE_RE_FRAGMENT}):
(?=[^[:alnum:]:]|$)/x
SCAN_RE = /:(#{SHORTCODE_RE_FRAGMENT}):/x
SHORTCODE_ONLY_RE = /\A#{SHORTCODE_RE_FRAGMENT}\z/
IMAGE_MIME_TYPES = %w(image/png image/gif image/webp).freeze

View file

@ -38,14 +38,6 @@ RSpec.describe EmojiFormatter do
end
end
context 'when given text with concatenated emoji shortcodes' do
let(:text) { preformat_text(':coolcat::coolcat:') }
it 'does not touch the shortcodes' do
expect(subject).to match(/:coolcat::coolcat:/)
end
end
context 'when given text with an emoji shortcode at the end' do
let(:text) { preformat_text('Beep boop :coolcat:') }