Class: HTML::Pipeline::Gitlab::GitlabEmojiFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/html/pipeline/gitlab/gitlab_emoji_filter.rb

Overview

HTML filter that replaces :emoji: with images.

Instance Method Summary collapse

Instance Method Details

#callObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/html/pipeline/gitlab/gitlab_emoji_filter.rb', line 11

def call
  search_text_nodes(doc).each do |node|
    content = node.to_html
    next if !content.include?(':')
    next if has_ancestor?(node, %w(pre code))
    html = emoji_image_filter(content)
    next if html == content
    node.replace(html)
  end
  doc
end

#emoji_image_filter(text) ⇒ Object

Replace :emoji: with corresponding images.

text - String text to replace :emoji: in.

Returns a String with :emoji: replaced with images.



33
34
35
36
37
38
39
40
# File 'lib/html/pipeline/gitlab/gitlab_emoji_filter.rb', line 33

def emoji_image_filter(text)
  return text unless text.include?(':')

  text.gsub(emoji_pattern) do |match|
    name = $1
    "<img class='emoji' title=':#{name}:' alt=':#{name}:' src='#{emoji_url(name)}' height='20' width='20' align='absmiddle' />"
  end
end

#validateObject

Implementation of validate hook. Errors should raise exceptions or use an existing validator.



25
26
# File 'lib/html/pipeline/gitlab/gitlab_emoji_filter.rb', line 25

def validate
end