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

Autolink all of the highlighted text at once

parent 1223c923
No related branches found
No related tags found
No related merge requests found
Loading
@@ -62,21 +62,8 @@ module Gitlab
Loading
@@ -62,21 +62,8 @@ module Gitlab
end end
   
def autolink_strings(highlighted_text) def autolink_strings(highlighted_text)
doc = Nokogiri::HTML::DocumentFragment.parse(highlighted_text) # TODO: Don't run pre-processing pipeline, because this may break the highlighting
Banzai.render(highlighted_text, pipeline: :autolink, autolink_emails: true).html_safe
# 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
end end
end 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