class Gollum::Sanitization
Constants
- REMOVE_NODES
- SCRUB_REMOVE
Attributes
id_prefix[R]
Public Class Methods
accepted_protocols()
click to toggle source
This class method is used in the Tag filter to determine whether a link has an acceptable URI scheme.
# File lib/gollum-lib/sanitization.rb, line 9 def self.accepted_protocols @@accepted_protocols end
new(to_xml_opts = {})
click to toggle source
# File lib/gollum-lib/sanitization.rb, line 21 def initialize(to_xml_opts = {}) @to_xml_opts = to_xml_opts end
Public Instance Methods
clean(data, historical = false)
click to toggle source
# 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
Private Instance Methods
wiki_id_scrubber()
click to toggle source
Returns a Loofah::Scrubber if the `id_prefix` attribute is set, or nil otherwise.
# File lib/gollum-lib/sanitization.rb, line 37 def wiki_id_scrubber @id_scrubber ||= Loofah::Scrubber.new do |node| if node.name == 'a' && val = node['href'] node['href'] = val.gsub(/\A\#(#{id_prefix})?/, '#' + id_prefix) unless node[:class] == 'internal anchorlink' # Don't prefix pure anchor links else %w(id name).each do |key| if (value = node[key]) node[key] = value.gsub(/\A(#{id_prefix})?/, id_prefix) end end end end end