| 1 | ######################################################## | ||
| 2 | # Copyright © 2009 Six Apart, Ltd. | ||
| 3 | |||
| 4 | package HTML::Laundry::Rules; | ||
| 5 | 16 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 16 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | =head1 NAME | ||
| 9 | |||
| 10 | HTML::Laundry::Rules - base class for HTML::Laundry rulesets | ||
| 11 | |||
| 12 | =head1 VERSION | ||
| 13 | |||
| 14 | Version 0.0002 | ||
| 15 | |||
| 16 | =cut | ||
| 17 | |||
| 18 | =head1 FUNCTIONS | ||
| 19 | |||
| 20 | =head2 new | ||
| 21 | |||
| 22 | Create an HTML::Tidy::Rules object. | ||
| 23 | |||
| 24 | my $rules = HTML::Laundry::Rules::MyRules->new(); | ||
| 25 | |||
| 26 | =cut | ||
| 27 | |||
| 28 | sub new { | ||
| 29 | 27 | ▶ | my $class = shift; |
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||
| 30 | 27 | my $self = {}; | |
| 31 | 27 | bless $self, $class; | |
| 32 | 27 | return $self; | |
| 33 | } | ||
| 34 | |||
| 35 | =head2 tidy_ruleset | ||
| 36 | |||
| 37 | Return a hashref representing a ruleset for an HTML::Tidy object. | ||
| 38 | |||
| 39 | =cut | ||
| 40 | |||
| 41 | sub tidy_ruleset { | ||
| 42 | 0 | ▶ | my $self = shift; |
|
Subroutine
tidy_ruleset: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 43 | 0 | my $tidy_ruleset = { | |
| 44 | show_body_only => 1, | ||
| 45 | output_xhtml => 1, | ||
| 46 | fix_backslash => 1, | ||
| 47 | fix_uri => 1, | ||
| 48 | numeric_entities => 1, | ||
| 49 | drop_empty_paras => 0, | ||
| 50 | vertical_space => 0, | ||
| 51 | wrap => 0, | ||
| 52 | quote_marks => 1, | ||
| 53 | }; | ||
| 54 | 0 | return $tidy_ruleset; | |
| 55 | } | ||
| 56 | |||
| 57 | =head2 acceptable_a | ||
| 58 | |||
| 59 | Return a hashref representing a list of acceptable attributes | ||
| 60 | |||
| 61 | =cut | ||
| 62 | |||
| 63 | sub acceptable_a { | ||
| 64 | 22 | ▶ | my $self = shift; |
|
Subroutine
acceptable_a: called CC=1 SCAR=0.0
Pod
documented
| |||
| 65 | my @acceptable | ||
| 66 | 22 | = qw(abbr accept accept-charset accesskey action align alt axis border | |
| 67 | cellpadding cellspacing char charoff charset checked cite class clear | ||
| 68 | cols colspan color compact coords datetime dir disabled enctype for | ||
| 69 | frame headers height href hreflang hspace id ismap label lang longdesc | ||
| 70 | maxlength media method multiple name nohref noshade nowrap prompt | ||
| 71 | readonly rel rev rows rowspan rules scope selected shape size span src | ||
| 72 | start summary tabindex target title type usemap valign value vspace | ||
| 73 | width xml:lang ); | ||
| 74 | 22 | my %acceptable = map { ( $_, 1 ) } @acceptable; | |
| 75 | 22 | return \%acceptable; | |
| 76 | } | ||
| 77 | |||
| 78 | =head2 acceptable_e | ||
| 79 | |||
| 80 | Return a hashref representing a list of acceptable elements | ||
| 81 | |||
| 82 | =cut | ||
| 83 | |||
| 84 | sub acceptable_e { | ||
| 85 | 22 | ▶ | my $self = shift; |
|
Subroutine
acceptable_e: called CC=1 SCAR=0.0
Pod
documented
| |||
| 86 | 22 | my @acceptable = qw( | |
| 87 | a abbr acronym address area b bdo big blockquote | ||
| 88 | br button caption center cite code col colgroup dd | ||
| 89 | del dfn dir div dl dt em fieldset font form | ||
| 90 | h1 h2 h3 h4 h5 h6 hr i img input ins kbd | ||
| 91 | label legend li map menu ol optgroup option p | ||
| 92 | pre q s samp select small span strike strong | ||
| 93 | sub sup table tbody td textarea tfoot th thead | ||
| 94 | tr tt u ul var wbr | ||
| 95 | ); | ||
| 96 | 22 | my %acceptable = map { ( $_, 1 ) } @acceptable; | |
| 97 | 22 | return \%acceptable; | |
| 98 | } | ||
| 99 | |||
| 100 | =head2 empty_e | ||
| 101 | |||
| 102 | Return a hashref representing a list of empty elements | ||
| 103 | |||
| 104 | =cut | ||
| 105 | |||
| 106 | sub empty_e { | ||
| 107 | 25 | ▶ | my $self = shift; |
|
Subroutine
empty_e: called CC=1 SCAR=0.0
Pod
documented
| |||
| 108 | my @empty | ||
| 109 | 25 | = qw( area base basefront br col frame hr img input isindex link meta param ); | |
| 110 | 25 | my %empty = map { ( $_, 1 ) } @empty; | |
| 111 | 25 | return \%empty; | |
| 112 | } | ||
| 113 | |||
| 114 | =head2 unacceptable_e | ||
| 115 | |||
| 116 | Return a hashref representing a list of unacceptable elements | ||
| 117 | |||
| 118 | =cut | ||
| 119 | |||
| 120 | sub unacceptable_e { | ||
| 121 | 26 | ▶ | my $self = shift; |
|
Subroutine
unacceptable_e: called CC=1 SCAR=0.0
Pod
documented
| |||
| 122 | 26 | my @unacceptable = qw( applet script ); | |
| 123 | 26 | my %unacceptable = map { ( $_, 1 ) } @unacceptable; | |
| 124 | 26 | return \%unacceptable; | |
| 125 | } | ||
| 126 | |||
| 127 | =head2 uri_list | ||
| 128 | |||
| 129 | Return a hashref representing a list of elements/attribute pairs known to contain | ||
| 130 | hrefs (for rebasing and URI scheme checking) | ||
| 131 | |||
| 132 | =cut | ||
| 133 | |||
| 134 | sub uri_list { | ||
| 135 | 25 | ▶ | my $self = shift; |
|
Subroutine
uri_list: called CC=1 SCAR=0.0
Pod
documented
| |||
| 136 | return { | ||
| 137 | 25 | a => ['href'], | |
| 138 | applet => ['codebase'], | ||
| 139 | area => ['href'], | ||
| 140 | blockquote => ['cite'], | ||
| 141 | body => ['background'], | ||
| 142 | del => ['cite'], | ||
| 143 | form => ['action'], | ||
| 144 | frame => [ 'longdesc', 'src' ], | ||
| 145 | iframe => [ 'longdesc', 'src' ], | ||
| 146 | img => [ 'longdesc', 'src', 'usemap' ], | ||
| 147 | input => [ 'src', 'usemap' ], | ||
| 148 | ins => ['cite'], | ||
| 149 | link => ['href'], | ||
| 150 | object => [ 'classid', 'codebase', 'data', 'usemap' ], | ||
| 151 | q => ['cite'], | ||
| 152 | script => ['src'] | ||
| 153 | }; | ||
| 154 | } | ||
| 155 | |||
| 156 | =head2 allowed_schemes | ||
| 157 | |||
| 158 | Return an arrayref representing a list of allowed schemas | ||
| 159 | |||
| 160 | =cut | ||
| 161 | |||
| 162 | sub allowed_schemes { | ||
| 163 | 21 | ▶ | my $self = shift; |
|
Subroutine
allowed_schemes: called CC=1 SCAR=0.0
Pod
documented
| |||
| 164 | return { | ||
| 165 | 21 | http => 1, | |
| 166 | https => 1, | ||
| 167 | afs => 1, | ||
| 168 | aim => 1, | ||
| 169 | callto => 1, | ||
| 170 | #data => 1, | ||
| 171 | ed2k => 1, | ||
| 172 | feed => 1, | ||
| 173 | ftp => 1, | ||
| 174 | gopher => 1, | ||
| 175 | irc => 1, | ||
| 176 | mailto => 1, | ||
| 177 | news => 1, | ||
| 178 | nntp => 1, | ||
| 179 | rsync => 1, | ||
| 180 | rtsp => 1, | ||
| 181 | sftp => 1, | ||
| 182 | ssh => 1, | ||
| 183 | tag => 1, | ||
| 184 | tel => 1, | ||
| 185 | telnet => 1, | ||
| 186 | urn => 1, | ||
| 187 | webcal => 1, | ||
| 188 | wtai => 1, | ||
| 189 | xmpp => 1, | ||
| 190 | }; | ||
| 191 | } | ||
| 192 | |||
| 193 | =head2 finalize_initialization | ||
| 194 | |||
| 195 | Function allowing transformation of the HTML::Laundry object. | ||
| 196 | |||
| 197 | =cut | ||
| 198 | |||
| 199 | sub finalize_initialization { | ||
| 200 | 25 | ▶ | my $self = shift; |
|
Subroutine
finalize_initialization: called CC=1 SCAR=0.0
Pod
documented
| |||
| 201 | 25 | my $laundry = shift; | |
| 202 | 25 | return 1; | |
| 203 | } | ||
| 204 | |||
| 205 | 16 | 1; | |