Parent Directory
|
Revision Log
|
Patch
| revision 1.49 by wakaba, Sat Jul 21 10:39:45 2007 UTC | revision 1.241 by wakaba, Sun Sep 6 12:53:19 2009 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 | use Whatpm::HTML::Tokenizer; | |
| 7 | ||
| 8 | ## NOTE: This module don't check all HTML5 parse errors; character | |
| 9 | ## encoding related parse errors are expected to be handled by relevant | |
| 10 | ## modules. | |
| 11 | ## Parse errors for control characters that are not allowed in HTML5 | |
| 12 | ## documents, for surrogate code points, and for noncharacter code | |
| 13 | ## points, as well as U+FFFD substitions for characters whose code points | |
| 14 | ## is higher than U+10FFFF may be detected by combining the parser with | |
| 15 | ## the checker implemented by Whatpm::Charset::UnicodeChecker (for its | |
| 16 | ## usage example, see |t/HTML-tree.t| in the Whatpm package or the | |
| 17 | ## WebHACC::Language::HTML module in the WebHACC package). | |
| 18 | ||
| 19 | ## ISSUE: | ## ISSUE: |
| 20 | ## var doc = implementation.createDocument (null, null, null); | ## var doc = implementation.createDocument (null, null, null); |
| 21 | ## doc.write (''); | ## doc.write (''); |
| 22 | ## alert (doc.compatMode); | ## alert (doc.compatMode); |
| 23 | ||
| 24 | ## ISSUE: HTML5 revision 967 says that the encoding layer MUST NOT | require IO::Handle; |
| ## strip BOM and the HTML layer MUST ignore it. Whether we can do it | ||
| ## is not yet clear. | ||
| ## "{U+FEFF}..." in UTF-16BE/UTF-16LE is three or four characters? | ||
| ## "{U+FEFF}..." in GB18030? | ||
| my $permitted_slash_tag_name = { | ||
| base => 1, | ||
| link => 1, | ||
| meta => 1, | ||
| hr => 1, | ||
| br => 1, | ||
| img=> 1, | ||
| embed => 1, | ||
| param => 1, | ||
| area => 1, | ||
| col => 1, | ||
| input => 1, | ||
| }; | ||
| 25 | ||
| 26 | my $c1_entity_char = { | ## Namespace URLs |
| 27 | 0x80 => 0x20AC, | |
| 28 | 0x81 => 0xFFFD, | my $HTML_NS = q<http://www.w3.org/1999/xhtml>; |
| 29 | 0x82 => 0x201A, | my $MML_NS = q<http://www.w3.org/1998/Math/MathML>; |
| 30 | 0x83 => 0x0192, | my $SVG_NS = q<http://www.w3.org/2000/svg>; |
| 31 | 0x84 => 0x201E, | my $XLINK_NS = q<http://www.w3.org/1999/xlink>; |
| 32 | 0x85 => 0x2026, | my $XML_NS = q<http://www.w3.org/XML/1998/namespace>; |
| 33 | 0x86 => 0x2020, | my $XMLNS_NS = q<http://www.w3.org/2000/xmlns/>; |
| 34 | 0x87 => 0x2021, | |
| 35 | 0x88 => 0x02C6, | ## Element categories |
| 36 | 0x89 => 0x2030, | |
| 37 | 0x8A => 0x0160, | ## Bits 12-15 |
| 38 | 0x8B => 0x2039, | sub SPECIAL_EL () { 0b1_000000000000000 } |
| 39 | 0x8C => 0x0152, | sub SCOPING_EL () { 0b1_00000000000000 } |
| 40 | 0x8D => 0xFFFD, | sub FORMATTING_EL () { 0b1_0000000000000 } |
| 41 | 0x8E => 0x017D, | sub PHRASING_EL () { 0b1_000000000000 } |
| 42 | 0x8F => 0xFFFD, | |
| 43 | 0x90 => 0xFFFD, | ## Bits 10-11 |
| 44 | 0x91 => 0x2018, | #sub FOREIGN_EL () { 0b1_00000000000 } # see Whatpm::HTML::Tokenizer |
| 45 | 0x92 => 0x2019, | sub FOREIGN_FLOW_CONTENT_EL () { 0b1_0000000000 } |
| 46 | 0x93 => 0x201C, | |
| 47 | 0x94 => 0x201D, | ## Bits 6-9 |
| 48 | 0x95 => 0x2022, | sub TABLE_SCOPING_EL () { 0b1_000000000 } |
| 49 | 0x96 => 0x2013, | sub TABLE_ROWS_SCOPING_EL () { 0b1_00000000 } |
| 50 | 0x97 => 0x2014, | sub TABLE_ROW_SCOPING_EL () { 0b1_0000000 } |
| 51 | 0x98 => 0x02DC, | sub TABLE_ROWS_EL () { 0b1_000000 } |
| 52 | 0x99 => 0x2122, | |
| 53 | 0x9A => 0x0161, | ## Bit 5 |
| 54 | 0x9B => 0x203A, | sub ADDRESS_DIV_P_EL () { 0b1_00000 } |
| 55 | 0x9C => 0x0153, | |
| 56 | 0x9D => 0xFFFD, | ## NOTE: Used in </body> and EOF algorithms. |
| 57 | 0x9E => 0x017E, | ## Bit 4 |
| 58 | 0x9F => 0x0178, | sub ALL_END_TAG_OPTIONAL_EL () { 0b1_0000 } |
| 59 | }; # $c1_entity_char | |
| 60 | ## NOTE: Used in "generate implied end tags" algorithm. | |
| 61 | my $special_category = { | ## NOTE: There is a code where a modified version of |
| 62 | address => 1, area => 1, base => 1, basefont => 1, bgsound => 1, | ## END_TAG_OPTIONAL_EL is used in "generate implied end tags" |
| 63 | blockquote => 1, body => 1, br => 1, center => 1, col => 1, colgroup => 1, | ## implementation (search for the algorithm name). |
| 64 | dd => 1, dir => 1, div => 1, dl => 1, dt => 1, embed => 1, fieldset => 1, | ## Bit 3 |
| 65 | form => 1, frame => 1, frameset => 1, h1 => 1, h2 => 1, h3 => 1, | sub END_TAG_OPTIONAL_EL () { 0b1_000 } |
| 66 | h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, iframe => 1, image => 1, | |
| 67 | img => 1, input => 1, isindex => 1, li => 1, link => 1, listing => 1, | ## Bits 0-2 |
| 68 | menu => 1, meta => 1, noembed => 1, noframes => 1, noscript => 1, | |
| 69 | ol => 1, optgroup => 1, option => 1, p => 1, param => 1, plaintext => 1, | sub MISC_SPECIAL_EL () { SPECIAL_EL | 0b000 } |
| 70 | pre => 1, script => 1, select => 1, spacer => 1, style => 1, tbody => 1, | sub FORM_EL () { SPECIAL_EL | 0b001 } |
| 71 | textarea => 1, tfoot => 1, thead => 1, title => 1, tr => 1, ul => 1, wbr => 1, | sub FRAMESET_EL () { SPECIAL_EL | 0b010 } |
| 72 | }; | sub HEADING_EL () { SPECIAL_EL | 0b011 } |
| 73 | my $scoping_category = { | sub SELECT_EL () { SPECIAL_EL | 0b100 } |
| 74 | button => 1, caption => 1, html => 1, marquee => 1, object => 1, | sub SCRIPT_EL () { SPECIAL_EL | 0b101 } |
| 75 | table => 1, td => 1, th => 1, | |
| 76 | sub ADDRESS_DIV_EL () { SPECIAL_EL | ADDRESS_DIV_P_EL | 0b001 } | |
| 77 | sub BODY_EL () { SPECIAL_EL | ALL_END_TAG_OPTIONAL_EL | 0b001 } | |
| 78 | ||
| 79 | sub DTDD_EL () { | |
| 80 | SPECIAL_EL | | |
| 81 | END_TAG_OPTIONAL_EL | | |
| 82 | ALL_END_TAG_OPTIONAL_EL | | |
| 83 | 0b010 | |
| 84 | } | |
| 85 | sub LI_EL () { | |
| 86 | SPECIAL_EL | | |
| 87 | END_TAG_OPTIONAL_EL | | |
| 88 | ALL_END_TAG_OPTIONAL_EL | | |
| 89 | 0b100 | |
| 90 | } | |
| 91 | sub P_EL () { | |
| 92 | SPECIAL_EL | | |
| 93 | ADDRESS_DIV_P_EL | | |
| 94 | END_TAG_OPTIONAL_EL | | |
| 95 | ALL_END_TAG_OPTIONAL_EL | | |
| 96 | 0b001 | |
| 97 | } | |
| 98 | ||
| 99 | sub TABLE_ROW_EL () { | |
| 100 | SPECIAL_EL | | |
| 101 | TABLE_ROWS_EL | | |
| 102 | TABLE_ROW_SCOPING_EL | | |
| 103 | ALL_END_TAG_OPTIONAL_EL | | |
| 104 | 0b001 | |
| 105 | } | |
| 106 | sub TABLE_ROW_GROUP_EL () { | |
| 107 | SPECIAL_EL | | |
| 108 | TABLE_ROWS_EL | | |
| 109 | TABLE_ROWS_SCOPING_EL | | |
| 110 | ALL_END_TAG_OPTIONAL_EL | | |
| 111 | 0b001 | |
| 112 | } | |
| 113 | ||
| 114 | sub MISC_SCOPING_EL () { SCOPING_EL | 0b000 } | |
| 115 | sub BUTTON_EL () { SCOPING_EL | 0b001 } | |
| 116 | sub CAPTION_EL () { SCOPING_EL | 0b010 } | |
| 117 | sub HTML_EL () { | |
| 118 | SCOPING_EL | | |
| 119 | TABLE_SCOPING_EL | | |
| 120 | TABLE_ROWS_SCOPING_EL | | |
| 121 | TABLE_ROW_SCOPING_EL | | |
| 122 | ALL_END_TAG_OPTIONAL_EL | | |
| 123 | 0b001 | |
| 124 | } | |
| 125 | sub TABLE_EL () { | |
| 126 | SCOPING_EL | | |
| 127 | TABLE_ROWS_EL | | |
| 128 | TABLE_SCOPING_EL | | |
| 129 | 0b001 | |
| 130 | } | |
| 131 | sub TABLE_CELL_EL () { | |
| 132 | SCOPING_EL | | |
| 133 | TABLE_ROW_SCOPING_EL | | |
| 134 | ALL_END_TAG_OPTIONAL_EL | | |
| 135 | 0b001 | |
| 136 | } | |
| 137 | ||
| 138 | sub MISC_FORMATTING_EL () { FORMATTING_EL | 0b000 } | |
| 139 | sub A_EL () { FORMATTING_EL | 0b001 } | |
| 140 | sub NOBR_EL () { FORMATTING_EL | 0b010 } | |
| 141 | ||
| 142 | sub RUBY_EL () { PHRASING_EL | 0b001 } | |
| 143 | ||
| 144 | ## ISSUE: ALL_END_TAG_OPTIONAL_EL? | |
| 145 | sub OPTGROUP_EL () { PHRASING_EL | END_TAG_OPTIONAL_EL | 0b001 } | |
| 146 | sub OPTION_EL () { PHRASING_EL | END_TAG_OPTIONAL_EL | 0b010 } | |
| 147 | sub RUBY_COMPONENT_EL () { PHRASING_EL | END_TAG_OPTIONAL_EL | 0b100 } | |
| 148 |