Skip to content
Snippets Groups Projects

WIP: Autolink URLs in blobs and diffs

Open Douwe Maan requested to merge dm-autolink-in-blobs into master
6 files
+ 129
11
Compare changes
  • Side-by-side
  • Inline
Files
6
@@ -26,7 +26,7 @@ module Banzai
# in the generated link.
#
# Rubular: http://rubular.com/r/cxjPyZc7Sb
LINK_PATTERN = %r{([a-z][a-z0-9\+\.-]+://\S+)(?<!,|\.)}
LINK_PATTERN = %r{([a-z][a-z0-9\+\.-]+://\S+)(?<![,."':?!&)<>])}
# Text matching LINK_PATTERN inside these elements will not be linked
IGNORE_PARENTS = %w(a code kbd pre script style).to_set
@@ -54,15 +54,13 @@ module Banzai
#
# `@doc` will be re-parsed with the HTML String from Rinku.
def rinku_parse
# Convert the options from a Hash to a String that Rinku expects
options = tag_options(link_options)
# NOTE: We don't parse email links because it will erroneously match
# external Commit and CommitRange references.
#
# The final argument tells Rinku to link short URLs that don't include a
# period (e.g., http://localhost:3000/)
rinku = Rinku.auto_link(html, :urls, options, IGNORE_PARENTS.to_a, 1)
mode = context[:autolink_emails] ? :all : :urls
rinku = Rinku.auto_link(html, mode, tag_options(link_options), IGNORE_PARENTS.to_a, 1)
return if rinku == html
@@ -111,9 +109,9 @@ module Banzai
# order to be output literally rather than escaped.
match.gsub!(/((?:&[\w#]+;)+)\z/, '')
dropped = ($1 || '').html_safe
match = ERB::Util.html_escape_once(match)
options = link_options.merge(href: match)
content_tag(:a, match, options) + dropped
%{<a href="#{match}" #{tag_options(link_options)}>#{match}</a>#{dropped}}.html_safe
end
def autolink_filter(text)
Loading