Parent Directory
|
Revision Log
|
Patch
| revision 1.29 by wakaba, Mon Jun 25 11:05:57 2007 UTC | revision 1.194 by wakaba, Sat Oct 4 05:53:45 2008 UTC | |
|---|---|---|
| # | Line 1 | Line 1 |
| 1 | package Whatpm::HTML; | package Whatpm::HTML; |
| 2 | use strict; | use strict; |
| 3 | our $VERSION=do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; | our $VERSION=do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
| 4 | use Error qw(:try); | |
| 5 | ||
| 6 | ## NOTE: This module don't check all HTML5 parse errors; character | |
| 7 | ## encoding related parse errors are expected to be handled by relevant | |
| 8 | ## modules. | |
| 9 | ## Parse errors for control characters that are not allowed in HTML5 | |
| 10 | ## documents, for surrogate code points, and for noncharacter code | |
| 11 | ## points, as well as U+FFFD substitions for characters whose code points | |
| 12 | ## is higher than U+10FFFF may be detected by combining the parser with | |
| 13 | ## the checker implemented by Whatpm::Charset::UnicodeChecker (for its | |
| 14 | ## usage example, see |t/HTML-tree.t| in the Whatpm package or the | |
| 15 | ## WebHACC::Language::HTML module in the WebHACC package). | |
| 16 | ||
| 17 | ## ISSUE: | ## ISSUE: |
| 18 | ## var doc = implementation.createDocument (null, null, null); | ## var doc = implementation.createDocument (null, null, null); |
| 19 | ## doc.write (''); | ## doc.write (''); |
| 20 | ## alert (doc.compatMode); | ## alert (doc.compatMode); |
| 21 | ||
| 22 | my $permitted_slash_tag_name = { | require IO::Handle; |
| 23 | base => 1, | |
| 24 | link => 1, | my $HTML_NS = q<http://www.w3.org/1999/xhtml>; |
| 25 | meta => 1, | my $MML_NS = q<http://www.w3.org/1998/Math/MathML>; |
| 26 | hr => 1, | my $SVG_NS = q<http://www.w3.org/2000/svg>; |
| 27 | br => 1, | my $XLINK_NS = q<http://www.w3.org/1999/xlink>; |
| 28 | img=> 1, | my $XML_NS = q<http://www.w3.org/XML/1998/namespace>; |
| 29 | embed => 1, | my $XMLNS_NS = q<http://www.w3.org/2000/xmlns/>; |
| 30 | param => 1, | |
| 31 | area => 1, | sub A_EL () { 0b1 } |
| 32 | col => 1, | sub ADDRESS_EL () { 0b10 } |
| 33 | input => 1, | sub BODY_EL () { 0b100 } |
| 34 | sub BUTTON_EL () { 0b1000 } | |
| 35 | sub CAPTION_EL () { 0b10000 } | |
| 36 | sub DD_EL () { 0b100000 } | |
| 37 | sub DIV_EL () { 0b1000000 } | |
| 38 | sub DT_EL () { 0b10000000 } | |
| 39 | sub FORM_EL () { 0b100000000 } | |
| 40 | sub FORMATTING_EL () { 0b1000000000 } | |
| 41 | sub FRAMESET_EL () { 0b10000000000 } | |
| 42 | sub HEADING_EL () { 0b100000000000 } | |
| 43 | sub HTML_EL () { 0b1000000000000 } | |
| 44 | sub LI_EL () { 0b10000000000000 } | |
| 45 | sub NOBR_EL () { 0b100000000000000 } | |
| 46 | sub OPTION_EL () { 0b1000000000000000 } | |
| 47 | sub OPTGROUP_EL () { 0b10000000000000000 } | |
| 48 | sub P_EL () { 0b100000000000000000 } | |
| 49 | sub SELECT_EL () { 0b1000000000000000000 } | |
| 50 | sub TABLE_EL () { 0b10000000000000000000 } | |
| 51 | sub TABLE_CELL_EL () { 0b100000000000000000000 } | |
| 52 | sub TABLE_ROW_EL () { 0b1000000000000000000000 } | |
| 53 | sub TABLE_ROW_GROUP_EL () { 0b10000000000000000000000 } | |
| 54 | sub MISC_SCOPING_EL () { 0b100000000000000000000000 } | |
| 55 | sub MISC_SPECIAL_EL () { 0b1000000000000000000000000 } | |
| 56 | sub FOREIGN_EL () { 0b10000000000000000000000000 } | |
| 57 | sub FOREIGN_FLOW_CONTENT_EL () { 0b100000000000000000000000000 } | |
| 58 | sub MML_AXML_EL () { 0b1000000000000000000000000000 } | |
| 59 | sub RUBY_EL () { 0b10000000000000000000000000000 } | |
| 60 | sub RUBY_COMPONENT_EL () { 0b100000000000000000000000000000 } | |
| 61 | ||
| 62 | sub TABLE_ROWS_EL () { | |
| 63 | TABLE_EL | | |
| 64 | TABLE_ROW_EL | | |
| 65 | TABLE_ROW_GROUP_EL | |
| 66 | } | |
| 67 | ||
| 68 | ## NOTE: Used in "generate implied end tags" algorithm. | |
| 69 | ## NOTE: There is a code where a modified version of | |
| 70 | ## END_TAG_OPTIONAL_EL is used in "generate implied end tags" | |
| 71 | ## implementation (search for the algorithm name). | |
| 72 | sub END_TAG_OPTIONAL_EL () { | |
| 73 | DD_EL | | |
| 74 | DT_EL | | |
| 75 | LI_EL | | |
| 76 | OPTION_EL | | |
| 77 | OPTGROUP_EL | | |
| 78 | P_EL | | |
| 79 | RUBY_COMPONENT_EL | |
| 80 | } | |
| 81 | ||
| 82 | ## NOTE: Used in </body> and EOF algorithms. | |
| 83 | sub ALL_END_TAG_OPTIONAL_EL () { | |
| 84 | DD_EL | | |
| 85 | DT_EL | | |
| 86 | LI_EL | | |
| 87 | P_EL | | |
| 88 | ||
| 89 | BODY_EL | | |
| 90 | HTML_EL | | |
| 91 | TABLE_CELL_EL | | |
| 92 | TABLE_ROW_EL | | |
| 93 | TABLE_ROW_GROUP_EL | |
| 94 | } | |
| 95 | ||
| 96 | sub SCOPING_EL () { | |
| 97 | BUTTON_EL | | |
| 98 | CAPTION_EL | | |
| 99 | HTML_EL | | |
| 100 | TABLE_EL | | |
| 101 | TABLE_CELL_EL | | |
| 102 | MISC_SCOPING_EL | |
| 103 | } | |
| 104 | ||
| 105 | sub TABLE_SCOPING_EL () { | |
| 106 | HTML_EL | | |
| 107 | TABLE_EL | |
| 108 | } | |
| 109 | ||
| 110 | sub TABLE_ROWS_SCOPING_EL () { | |
| 111 | HTML_EL | | |
| 112 | TABLE_ROW_GROUP_EL | |
| 113 | } | |
| 114 | ||
| 115 | sub TABLE_ROW_SCOPING_EL () { | |
| 116 | HTML_EL | | |
| 117 | TABLE_ROW_EL | |
| 118 | } | |
| 119 | ||
| 120 | sub SPECIAL_EL () { | |
| 121 | ADDRESS_EL | | |
| 122 | BODY_EL | | |
| 123 | DIV_EL | | |
| 124 | ||
| 125 | DD_EL | | |
| 126 | DT_EL | | |
| 127 | LI_EL | | |
| 128 | P_EL | | |
| 129 | ||
| 130 | FORM_EL | | |
| 131 | FRAMESET_EL | | |
| 132 | HEADING_EL | | |
| 133 | OPTION_EL | | |
| 134 | OPTGROUP_EL | | |
| 135 | SELECT_EL | | |
| 136 | TABLE_ROW_EL | | |
| 137 | TABLE_ROW_GROUP_EL | | |
| 138 | MISC_SPECIAL_EL | |
| 139 | } | |
| 140 | ||
| 141 | my $el_category = { | |
| 142 | a => A_EL | FORMATTING_EL, | |
| 143 | address => ADDRESS_EL, | |
| 144 | applet => MISC_SCOPING_EL, | |
| 145 | area => MISC_SPECIAL_EL, | |
| 146 | article => MISC_SPECIAL_EL, | |
| 147 | aside => MISC_SPECIAL_EL, | |
| 148 | b => FORMATTING_EL, | |
| 149 | base => MISC_SPECIAL_EL, | |
| 150 | basefont => MISC_SPECIAL_EL, | |
| 151 | bgsound => MISC_SPECIAL_EL, | |
| 152 | big => FORMATTING_EL, | |
| 153 | blockquote => MISC_SPECIAL_EL, | |
| 154 | body => BODY_EL, | |
| 155 | br => MISC_SPECIAL_EL, | |
| 156 | button => BUTTON_EL, | |
| 157 | caption => CAPTION_EL, | |
| 158 | center => MISC_SPECIAL_EL, | |
| 159 | col => MISC_SPECIAL_EL, | |
| 160 | colgroup => MISC_SPECIAL_EL, | |
| 161 | command => MISC_SPECIAL_EL, | |
| 162 | datagrid => MISC_SPECIAL_EL, | |
| 163 | dd => DD_EL, | |
| 164 | details => MISC_SPECIAL_EL, | |
| 165 | dialog => MISC_SPECIAL_EL, | |
| 166 | dir => MISC_SPECIAL_EL, | |
| 167 | div => DIV_EL, | |
| 168 | dl => MISC_SPECIAL_EL, | |
| 169 | dt => DT_EL, | |
| 170 | em => FORMATTING_EL, | |
| 171 | embed => MISC_SPECIAL_EL, | |
| 172 | eventsource => MISC_SPECIAL_EL, | |
| 173 | fieldset => MISC_SPECIAL_EL, | |
| 174 | figure => MISC_SPECIAL_EL, | |
| 175 | font => FORMATTING_EL, | |
| 176 | footer => MISC_SPECIAL_EL, | |
| 177 | form => FORM_EL, | |
| 178 | frame => MISC_SPECIAL_EL, | |
| 179 | frameset => FRAMESET_EL, | |
| 180 | h1 => HEADING_EL, | |
| 181 | h2 => HEADING_EL, | |
| 182 | h3 => HEADING_EL, | |
| 183 | h4 => HEADING_EL, | |
| 184 | h5 => HEADING_EL, | |
| 185 | h6 => HEADING_EL, | |
| 186 | head => MISC_SPECIAL_EL, | |
| 187 | header => MISC_SPECIAL_EL, | |
| 188 | hr => MISC_SPECIAL_EL, | |
| 189 | html => HTML_EL, | |
| 190 | i => FORMATTING_EL, | |
| 191 |