class Gollum::Sanitization

Encapsulate sanitization options.

This class does not yet support all options of Sanitize library. See github.com/rgrove/sanitize/.

Constants

ADD_ATTRIBUTES
ATTRIBUTES

Default whitelisted attributes.

ELEMENTS

Default whitelisted elements.

PROTOCOLS

Default whitelisted protocols for URLs.

REMOVE_CONTENTS

Default elements whose contents will be removed in addition to the elements themselve

TRANSFORMERS

Default transformers to force @id attributes with 'wiki-' prefix

Attributes

add_attributes[R]

Gets a Hash describing HTML attributes that Sanitize should add. Default: {}

allow_comments[W]

Sets a boolean determining whether Sanitize allows HTML comments in the output. Default: false.

attributes[R]

Gets a Hash describing which attributes are allowed in which HTML elements. Default: ATTRIBUTES.

elements[R]

Gets an Array of whitelisted HTML elements. Default: ELEMENTS.

id_prefix[RW]

Gets or sets a String prefix which is added to ID attributes. Default: ''

protocols[R]

Gets a Hash describing which URI protocols are allowed in HTML attributes. Default: PROTOCOLS

remove_contents[R]

Gets an Array of element names whose contents will be removed in addition to the elements themselves. Default: REMOVE_CONTENTS

transformers[R]

Gets a Hash describing which URI protocols are allowed in HTML attributes. Default: TRANSFORMERS

Public Class Methods

new() { |self| ... } click to toggle source
# File lib/gollum-lib/sanitization.rb, line 123
def initialize
  @elements         = ELEMENTS.dup
  @attributes       = ATTRIBUTES.dup
  @protocols        = PROTOCOLS.dup
  @transformers     = TRANSFORMERS.dup
  @add_attributes   = {}
  @remove_contents  = REMOVE_CONTENTS.dup
  @allow_comments   = false
  @id_prefix        = ''
  yield self if block_given?
end

Public Instance Methods

allow_comments?() click to toggle source

Determines if Sanitize should allow HTML comments.

Returns True if comments are allowed, or False.

# File lib/gollum-lib/sanitization.rb, line 138
def allow_comments?
  !!@allow_comments
end
history_sanitization() click to toggle source

Modifies the current Sanitization instance to sanitize older revisions of pages.

Returns a Sanitization instance.

# File lib/gollum-lib/sanitization.rb, line 146
def history_sanitization
  self.class.new do |sanitize|
    sanitize.add_attributes['a'] = {'rel' => 'nofollow'}
  end
end
to_hash() click to toggle source

Builds a Hash of options suitable for Sanitize.clean.

Returns a Hash.

# File lib/gollum-lib/sanitization.rb, line 155
def to_hash
  { :elements         => elements,
    :attributes       => attributes,
    :protocols        => protocols,
    :add_attributes   => add_attributes,
    :remove_contents  => remove_contents,
    :allow_comments   => allow_comments?,
    :transformers     => transformers,
    :id_prefix        => id_prefix
  }
end
to_sanitize() click to toggle source

Builds a Sanitize instance from the current options.

Returns a Sanitize instance.

# File lib/gollum-lib/sanitization.rb, line 170
def to_sanitize
  Sanitize.new(to_hash)
end