2015-12-23 02:04:40 +05:30
|
|
|
module Banzai
|
|
|
|
module Filter
|
2016-06-02 11:05:42 +05:30
|
|
|
# HTML Filter to modify the attributes of external links
|
2015-09-11 14:41:01 +05:30
|
|
|
class ExternalLinkFilter < HTML::Pipeline::Filter
|
|
|
|
def call
|
2016-06-22 15:30:34 +05:30
|
|
|
# Skip non-HTTP(S) links and internal links
|
|
|
|
doc.xpath("descendant-or-self::a[starts-with(@href, 'http') and not(starts-with(@href, '#{internal_url}'))]").each do |node|
|
2016-06-02 11:05:42 +05:30
|
|
|
node.set_attribute('rel', 'nofollow noreferrer')
|
2016-06-16 23:09:34 +05:30
|
|
|
node.set_attribute('target', '_blank')
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
doc
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def internal_url
|
|
|
|
@internal_url ||= Gitlab.config.gitlab.url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|