闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
489 B

  1. # frozen_string_literal: true
  2. module EmojiHelper
  3. def emojify(text)
  4. return text if text.blank?
  5. text.gsub(emoji_pattern) do |match|
  6. emoji = Emoji.instance.unicode($1) # rubocop:disable Style/PerlBackrefs
  7. if emoji
  8. emoji
  9. else
  10. match
  11. end
  12. end
  13. end
  14. def emoji_pattern
  15. @emoji_pattern ||=
  16. /(?<=[^[:alnum:]:]|\n|^)
  17. (#{Emoji.instance.names.map { |name| Regexp.escape(name) }.join('|')})
  18. (?=[^[:alnum:]:]|$)/x
  19. end
  20. end