Class: Gollum::Sanitization

Inherits:
Object
  • Object
show all
Defined in:
lib/gollum-lib/sanitization.rb

Constant Summary collapse

REMOVE_NODES =
['style', 'script']
SCRUB_REMOVE =
Loofah::Scrubber.new do |node|
  node.remove if REMOVE_NODES.include?(node.name)
end
@@accepted_protocols =
::Loofah::HTML5::SafeList::ACCEPTABLE_PROTOCOLS.to_a.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(to_xml_opts = {}) ⇒ Sanitization

Returns a new instance of Sanitization.



22
23
24
# File 'lib/gollum-lib/sanitization.rb', line 22

def initialize(to_xml_opts = {})
  @to_xml_opts = to_xml_opts
end

Instance Attribute Details

#id_prefixObject (readonly)

Returns the value of attribute id_prefix.



20
21
22
# File 'lib/gollum-lib/sanitization.rb', line 20

def id_prefix
  @id_prefix
end

Class Method Details

.accepted_protocolsObject

This class method is used in the Tag filter to determine whether a link has an acceptable URI scheme.



10
11
12
# File 'lib/gollum-lib/sanitization.rb', line 10

def self.accepted_protocols
  @@accepted_protocols
end

Instance Method Details

#clean(data, historical = false) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/gollum-lib/sanitization.rb', line 26

def clean(data, historical = false)
  doc = Loofah.fragment(data)
  doc.scrub!(SCRUB_REMOVE)
  doc.scrub!(:strip)
  doc.scrub!(:nofollow) if historical
  doc.scrub!(wiki_id_scrubber) if id_prefix
  doc.to_xml(@to_xml_opts).gsub('<p></p>', '')
end