Methods
Constants
| DEFAULT | = | { 'allowed' => { 'a' => ['href', 'target'], 'b' => [], 'i' => [], 'ul' => [], 'ol' => [], 'li' => [], 'img' => ['src', 'width', 'height', 'alt'], 'object' => ['width', 'height'], 'param' => ['name', 'value'], 'embed' => ['src', 'type', 'wmode', 'name', 'value'], }, 'no_close' => ['img', 'br', 'hr'], 'always_close' => ['a', 'b'], 'protocol_attributes' => ['src', 'href'], 'allowed_protocols' => ['http', 'ftp', 'mailto'], 'remove_blanks' => ['a', 'b'], 'strip_comments' => true, 'always_make_tags' => true, 'allow_numbered_entities' => true, 'allowed_entities' => ['amp', 'gt', 'lt', 'quot'] |
| default settings | ||
Attributes
| [RW] | allow_numbered_entities | entity control option (true, false) |
| [RW] | allowed |
tags and attributes that are allowed
Eg.
{
'a' => ['href', 'target'],
'b' => [],
'img' => ['src', 'width', 'height', 'alt']
}
|
| [RW] | allowed_entities | entity control option (amp, gt, lt, quot, etc.) |
| [RW] | allowed_protocols | protocols which are allowed (http, ftp, mailto) |
| [RW] | always_close | tags which must always have seperate opening and closing tags (e.g. "") |
| [RW] | always_make_tags | should we try and make a b tag out of "b>" (true, false) |
| [RW] | no_close | tags which should always be self-closing (e.g. "<img />") |
| [RW] | protocol_attributes | attributes which should be checked for valid protocols (src,href) |
| [RW] | remove_blanks | tags which should be removed if they contain no content (e.g. "" or "<b />") |
| [RW] | strip_comments | should we remove comments? (true, false) |
| [R] | tag_counts | internal tag counter |
Public Class methods
new html filter
[ show source ]
# File lib/raw/util/html_filter.rb, line 99
99: def initialize( options=nil )
100: @tag_counts = {}
101:
102: (options || DEFAULT).each{ |k,v| send("#{k}=",v) }
103: end
Public Instance methods
[ show source ]
# File lib/raw/util/html_filter.rb, line 109
109: def filter(data)
110: tag_counts = []
111:
112: data = escape_comments(data)
113: data = balance_html(data)
114: data = check_tags(data)
115: data = process_remove_blanks(data)
116: data = validate_entities(data)
117:
118: return data
119: end