OLD | NEW |
1 /** | 1 /** |
2 * This library has a parser for HTML5 documents, that lets you parse HTML | 2 * This library has a parser for HTML5 documents, that lets you parse HTML |
3 * easily from a script or server side application: | 3 * easily from a script or server side application: |
4 * | 4 * |
5 * import 'package:html5lib/parser.dart' show parse; | 5 * import 'package:html5lib/parser.dart' show parse; |
6 * import 'package:html5lib/dom.dart'; | 6 * import 'package:html5lib/dom.dart'; |
7 * main() { | 7 * main() { |
8 * var document = parse( | 8 * var document = parse( |
9 * '<body>Hello world! <a href="www.html5rocks.com">HTML5 rocks!'); | 9 * '<body>Hello world! <a href="www.html5rocks.com">HTML5 rocks!'); |
10 * print(document.outerHtml); | 10 * print(document.outerHtml); |
11 * } | 11 * } |
12 * | 12 * |
13 * The resulting document you get back has a DOM-like API for easy tree | 13 * The resulting document you get back has a DOM-like API for easy tree |
14 * traversal and manipulation. | 14 * traversal and manipulation. |
15 */ | 15 */ |
16 library parser; | 16 library parser; |
17 | 17 |
18 import 'dart:collection'; | 18 import 'dart:collection'; |
19 import 'dart:math'; | 19 import 'dart:math'; |
20 import 'package:source_maps/span.dart' show Span, FileSpan; | 20 import 'package:source_maps/span.dart' show Span, FileSpan; |
21 | 21 |
22 import 'src/treebuilder.dart'; | 22 import 'src/treebuilder.dart'; |
23 import 'src/constants.dart'; | 23 import 'src/constants.dart'; |
24 import 'src/encoding_parser.dart'; | 24 import 'src/encoding_parser.dart'; |
25 import 'src/token.dart'; | 25 import 'src/token.dart'; |
26 import 'src/tokenizer.dart'; | 26 import 'src/tokenizer.dart'; |
27 import 'src/utils.dart'; | 27 import 'src/utils.dart'; |
28 import 'dom.dart'; | 28 import 'dom.dart'; |
29 import 'dom_parsing.dart'; | |
30 | 29 |
31 /** | 30 /** |
32 * Parse the [input] html5 document into a tree. The [input] can be | 31 * Parse the [input] html5 document into a tree. The [input] can be |
33 * a [String], [List<int>] of bytes or an [HtmlTokenizer]. | 32 * a [String], [List<int>] of bytes or an [HtmlTokenizer]. |
34 * | 33 * |
35 * If [input] is not a [HtmlTokenizer], you can optionally specify the file's | 34 * If [input] is not a [HtmlTokenizer], you can optionally specify the file's |
36 * [encoding], which must be a string. If specified, that encoding will be used, | 35 * [encoding], which must be a string. If specified, that encoding will be used, |
37 * regardless of any BOM or later declaration (such as in a meta element). | 36 * regardless of any BOM or later declaration (such as in a meta element). |
38 * | 37 * |
39 * Set [generateSpans] if you want to generate [Span]s, otherwise the | 38 * Set [generateSpans] if you want to generate [Span]s, otherwise the |
(...skipping 3296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3336 * [span.getLocationMessage] will not show any source url information, but | 3335 * [span.getLocationMessage] will not show any source url information, but |
3337 * [toString] will include 'ParserError:' as a prefix. | 3336 * [toString] will include 'ParserError:' as a prefix. |
3338 */ | 3337 */ |
3339 String get message => formatStr(errorMessages[errorCode], data); | 3338 String get message => formatStr(errorMessages[errorCode], data); |
3340 | 3339 |
3341 String toString() { | 3340 String toString() { |
3342 var res = span.getLocationMessage(message); | 3341 var res = span.getLocationMessage(message); |
3343 return span.sourceUrl == null ? 'ParserError$res' : res; | 3342 return span.sourceUrl == null ? 'ParserError$res' : res; |
3344 } | 3343 } |
3345 } | 3344 } |
OLD | NEW |