Class: Banzai::Filter::WikiLinkFilter

Inherits:
HTML::Pipeline::Filter
  • Object
show all
Includes:
Gitlab::Utils::SanitizeNodeLink
Defined in:
lib/banzai/filter/wiki_link_filter.rb,
lib/banzai/filter/wiki_link_filter/rewriter.rb

Overview

HTML filter that “fixes” links to pages/files in a wiki. Rewrite rules are documented in the `WikiPipeline` spec.

Context options:

:wiki

Defined Under Namespace

Classes: Rewriter

Constant Summary collapse

CSS_A =
'a:not(.gfm)'
XPATH_A =
Gitlab::Utils::Nokogiri.css_to_xpath(CSS_A).freeze
CSS_VA =
'video, audio'
XPATH_VA =
Gitlab::Utils::Nokogiri.css_to_xpath(CSS_VA).freeze
CSS_IMG =
'img'
XPATH_IMG =
Gitlab::Utils::Nokogiri.css_to_xpath(CSS_IMG).freeze

Constants included from Gitlab::Utils::SanitizeNodeLink

Gitlab::Utils::SanitizeNodeLink::ATTRS_TO_SANITIZE, Gitlab::Utils::SanitizeNodeLink::UNSAFE_PROTOCOLS

Instance Method Summary collapse

Methods included from Gitlab::Utils::SanitizeNodeLink

#remove_unsafe_links, #safe_protocol?, #sanitize_unsafe_links

Instance Method Details

#callObject


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/banzai/filter/wiki_link_filter.rb', line 20

def call
  return doc unless wiki?

  doc.xpath(XPATH_A).each { |el| process_link(el.attribute('href'), el) }

  doc.xpath(XPATH_VA).each { |el| process_link(el.attribute('src'), el) }

  doc.xpath(XPATH_IMG).each do |el|
    attr = el.attribute('data-src') || el.attribute('src')

    process_link(attr, el)
  end

  doc
end