/[suikacvs]/markup/html/whatpm/Whatpm/HTML.pod
Suika

Contents of /markup/html/whatpm/Whatpm/HTML.pod

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Wed May 2 13:44:34 2007 UTC (19 years, 2 months ago) by wakaba
Branch: MAIN
Changes since 1.2: +12 -4 lines
++ ChangeLog	2 May 2007 13:37:34 -0000
2007-05-02  Wakaba  <wakaba@suika.fam.cx>

	* readme.en.html: TODO section is added.

++ whatpm/t/ChangeLog	2 May 2007 13:44:02 -0000
2007-05-02  Wakaba  <wakaba@suika.fam.cx>

	* .cvsignore: Result files are added.

	* HTML-tree.t: Support for document fragment tests.

	* Makefile: Generate test result files.

	* tokenizer-test-1.test: A new test to ensure that
	characters after end tag are preserved in RCDATA or CDATA
	case.

++ whatpm/Whatpm/ChangeLog	2 May 2007 13:42:17 -0000
2007-05-02  Wakaba  <wakaba@suika.fam.cx>

	* NanoDOM.pm (DOMImplementation): New class.
	(append_child): Weaken the |parent_node| reference.
	(create_element_ns, Element new): Set the |owner_document|
	reference.
	(implementation): New attribute.
	(owner_document, local_name, namespace_uri): New attributes.

	* HTML.pm.src (parse_string): Line and column numbers
	are now provided to error handler.
	(!!!parse-error): Short descriptions are added.
	(_construct_tree): Split into three methods; support
	for innerHTML mode.
	(set_inner_html): New method.

1 wakaba 1.1 =head1 NAME
2    
3 wakaba 1.2 Whatpm::HTML - An HTML Parser
4 wakaba 1.1
5     =head1 SYNOPSIS
6    
7 wakaba 1.2 use Whatpm::HTML;
8 wakaba 1.1
9     my $s = q<<!DOCTYPE html><html>...</html>>;
10     # $doc = an empty DOM |Document| object
11     my $on_error = sub {
12     my $error_code = shift;
13     warn $error_code, "\n";
14     };
15    
16 wakaba 1.2 Whatpm::HTML->parse_string ($s => $doc, $onerror);
17 wakaba 1.1
18     ## Then, |$doc| is the DOM representation of |$s|.
19    
20     =head1 DESCRIPTION
21    
22 wakaba 1.2 The C<Whatpm::HTML> module contains HTML parser and serializer.
23 wakaba 1.1
24     The HTML parser can be used to construct the DOM tree representation
25     from an HTML document. The parsing and tree construction are done
26     as described in the Web Application 1.0 specification.
27    
28     The HTML serializer can be used to obtain the HTML document representation
29     of a DOM tree (or a tree fragment thereof). The serialization
30     is performed as described in the Web Applications 1.0 specification
31     for C<innerHTML> DOM attribute.
32    
33 wakaba 1.2 This module is part of Whatpm - Perl Modules for
34 wakaba 1.1 Web Hypertext Application Technologies.
35    
36     =head1 METHODS
37    
38     =over 4
39    
40 wakaba 1.2 =item [I<$doc> =] Whatpm::HTML->parse_string (I<$s>, I<$doc>[, I<$onerror>]);
41 wakaba 1.1
42     Parse a string I<$s> as an HTML document.
43    
44     The first argument, I<$s>, MUST be a string. It is parsed
45     as a sequence of characters representing an HTML document.
46    
47     The second argument, I<$doc>, MUST be an empty read-write
48     DOM C<Document> object. The HTML DOM tree is constructed
49     onto this C<Document> object.
50    
51     The third argument, I<$onerror>, MUST be a reference to
52     the error handler code. Whenever a parse error is detected,
53     this code is invoked with an argument that contains a
54     useless string that might describe what is wrong.
55     The code MAY throw an exception, so that whole the parsing
56     process aborts. Otherwise, the parser will continue to
57     process the input. The code MUST NOT modify I<$s> or I<$doc>.
58     If it does, then the result is undefined.
59     This argument is optional; if missing, any
60     parse error makes that string being C<warn>ed.
61    
62 wakaba 1.3 B<NOTE>: To be a conforming user agent, the code MUST either
63     abort the processing by throwing an exception at the first
64     invocation or MUST continue the processing until the parser
65     stops.
66    
67 wakaba 1.1 The method returns the DOM C<Document> object (i.e. the second argument).
68    
69 wakaba 1.2 Note that the C<Whatpm::NanoDOM> module provides a non-conforming
70 wakaba 1.1 implementation of DOM that only implements the subset that
71 wakaba 1.2 is necessary for the purpose of C<Whatpm::HTML>'s parsing and
72 wakaba 1.1 serializing.
73     With this module, creating a new HTML C<Document> object
74 wakaba 1.3 from a string containing HTML document might be coded as:
75 wakaba 1.1
76 wakaba 1.2 use Whatpm::HTML;
77     use Whatpm::NanoDOM;
78     my $doc = Whatpm::HTML->parse_string
79     ($s => Whatpm::NanoDOM::Document->new, $onerror);
80 wakaba 1.1
81 wakaba 1.2 =item I<$s> = Whatpm::HTML->get_inner_html (I<$node>[, I<$onerror>]);
82 wakaba 1.1
83     Return the HTML serialization of a DOM node I<$node>.
84    
85     The first argument, I<$node>, MUST be a DOM C<Document>,
86     C<Node>, or C<DocumentFragment> object.
87    
88     The second argument, I<$onerror>, MUST be a reference to the
89     error handling code. This code will be invoked if a descendant
90 wakaba 1.3 of I<$node> is not of C<Element>, C<Text>, C<CDATASection>,
91 wakaba 1.1 C<Comment>, C<DocumentType>, or C<EntityReference> so
92     that C<INVALID_STATE_ERR> MUST be thrown.
93     The code will be invoked with an argument, which is the node
94     whose type is invalid.
95     This argument is optional; if missing, any such
96     node is simply ignored.
97    
98     The method returns a reference to the C<inner_html> attribute
99 wakaba 1.3 value, i.e. the HTML serialization of the I<$node>.
100 wakaba 1.1
101     =back
102    
103     =head1 TO DO
104    
105     Tokenizer should emit a sequence of character tokens as one token
106     to improve performance.
107    
108     A method that accepts a byte stream as an input.
109    
110     Charset detection algorithm.
111    
112     Setting inner_html.
113    
114     And there are many "TODO"s and "ISSUE"s in the source code.
115    
116     =head1 SEE ALSO
117    
118 wakaba 1.3 Whatpm
119     <http://suika.fam.cx/www/markup/html/whatpm/readme>
120    
121 wakaba 1.1 Web Applications 1.0 Working Draft (aka HTML5)
122     <http://whatwg.org/html5>. (Revision 792, 1 May 2007)
123    
124 wakaba 1.2 L<Whatpm::NanoDOM>
125 wakaba 1.1
126     =head1 AUTHOR
127    
128     Wakaba <[email protected]>.
129    
130     =head1 LICENSE
131    
132     Copyright 2007 Wakaba <[email protected]>
133    
134     This library is free software; you can redistribute it
135     and/or modify it under the same terms as Perl itself.
136    
137     =cut
138    
139 wakaba 1.3 # $Date: 2007/05/01 10:47:37 $

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24