Skip to content
Snippets Groups Projects
Commit ed6cbde2 authored by Douwe Maan's avatar Douwe Maan
Browse files

Autolink all of the highlighted text at once

parent 625ce63c
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -69,21 +69,8 @@ module Gitlab
end
 
def autolink_strings(highlighted_text)
doc = Nokogiri::HTML::DocumentFragment.parse(highlighted_text)
# Files without highlighting have all text in `span.line`.
# Files with highlighting have strings and comments in `span`s with a
# `class` starting with `c` or `s`.
doc.xpath('.//span[@class="line" or starts-with(@class, "c") or starts-with(@class, "s")]/text()').each do |node|
content = node.to_html
html = Banzai.render(content, pipeline: :autolink, autolink_emails: true)
next if html == content
node.replace(html)
end
doc.to_html.html_safe
# TODO: Don't run pre-processing pipeline, because this may break the highlighting
Banzai.render(highlighted_text, pipeline: :autolink, autolink_emails: true).html_safe
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment