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.



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

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.



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

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.



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

def self.accepted_protocols
  @@accepted_protocols
end

Instance Method Details

#clean(data, historical = false) ⇒ Object



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

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