Class: Trenni::Sanitize::Fragment

Inherits:
Filter
  • Object
show all
Defined in:
lib/trenni/sanitize/fragment.rb

Constant Summary collapse

STANDARD_ATTRIBUTES =
['class', 'style'].freeze
ALLOWED_TAGS =
{
	'div' => STANDARD_ATTRIBUTES,
	'span' => STANDARD_ATTRIBUTES,
	'br' => STANDARD_ATTRIBUTES,
	'b' => STANDARD_ATTRIBUTES,
	'i' => STANDARD_ATTRIBUTES,
	'em' => STANDARD_ATTRIBUTES,
	'strong' => STANDARD_ATTRIBUTES,
	'ul' => STANDARD_ATTRIBUTES,
	'strike' => STANDARD_ATTRIBUTES,
	'h1' => STANDARD_ATTRIBUTES,
	'h2' => STANDARD_ATTRIBUTES,
	'h3' => STANDARD_ATTRIBUTES,
	'h4' => STANDARD_ATTRIBUTES,
	'h5' => STANDARD_ATTRIBUTES,
	'h6' => STANDARD_ATTRIBUTES,
	'p' => STANDARD_ATTRIBUTES,
	'img' => STANDARD_ATTRIBUTES + ['src', 'alt', 'width', 'height'],
	'image' => STANDARD_ATTRIBUTES,
	'a' => STANDARD_ATTRIBUTES + ['href', 'target']
}.freeze

Constants inherited from Filter

Trenni::Sanitize::Filter::ALL, Trenni::Sanitize::Filter::CDATA, Trenni::Sanitize::Filter::COMMENT, Trenni::Sanitize::Filter::CONTENT, Trenni::Sanitize::Filter::DOCTYPE, Trenni::Sanitize::Filter::INSTRUCTION, Trenni::Sanitize::Filter::TAG, Trenni::Sanitize::Filter::TEXT

Instance Attribute Summary

Attributes inherited from Filter

#current, #output, #stack

Instance Method Summary collapse

Methods inherited from Filter

#attribute, #cdata, #close_tag, #comment, #initialize, #open_tag_begin, #open_tag_end, parse, #parse!, #parse_begin, #parse_end, #text, #top

Constructor Details

This class inherits a constructor from Trenni::Sanitize::Filter

Instance Method Details

#doctype(string) ⇒ Object



60
61
# File 'lib/trenni/sanitize/fragment.rb', line 60

def doctype(string)
end

#filter(node) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/trenni/sanitize/fragment.rb', line 50

def filter(node)
	if attributes = ALLOWED_TAGS[node.name]
		node.tag.attributes.slice!(*attributes)
		
		node.accept!
	else
		node.skip!
	end
end

#instruction(string) ⇒ Object



63
64
# File 'lib/trenni/sanitize/fragment.rb', line 63

def instruction(string)
end