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

Autolink all of the highlighted text at once

parent bc6e3daa
No related branches found
No related tags found
1 merge request!4121WIP: Autolink packages in dependency files like `Gemfile`
Loading
Loading
@@ -70,21 +70,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