Commit 9dd879bc authored by Harish Ramachandran's avatar Harish Ramachandran Committed by Jan Provaznik

Wrap emojis in links when needed

parent 8dcbe92c
......@@ -51,12 +51,14 @@ module MarkupHelper
text = fragment.children[0].text
fragment.children[0].replace(link_to(text, url, html_options))
else
# Traverse the fragment's first generation of children looking for pure
# text, wrapping anything found in the requested link
# Traverse the fragment's first generation of children looking for
# either pure text or emojis, wrapping anything found in the
# requested link
fragment.children.each do |node|
next unless node.text?
next unless node.text? || node.name.match?('gl-emoji')
node.replace(link_to(node.text, url, html_options))
node.replace(link_to(node.text, url, html_options)) if node.text?
node.replace(link_to(node.to_html.html_safe, url, html_options)) if node.name.match?('gl-emoji')
end
end
......
......@@ -210,7 +210,7 @@ describe MarkupHelper do
it 'replaces commit message with emoji to link' do
actual = link_to_markdown(':book: Book', '/foo')
expect(actual)
.to eq '<gl-emoji title="open book" data-name="book" data-unicode-version="6.0">📖</gl-emoji><a href="/foo"> Book</a>'
.to eq '<a href="/foo"><gl-emoji title="open book" data-name="book" data-unicode-version="6.0">📖</gl-emoji></a><a href="/foo"> Book</a>'
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment