OLD | NEW |
(Empty) | |
| 1 html5 parser in dart |
| 2 ==================== |
| 3 |
| 4 This is a pure [Dart][dart] [html5 parser][html5parse]. It's a port of |
| 5 [html5lib](https://github.com/html5lib/html5lib-python) from Python. Since it's
100% |
| 6 Dart you can use it safely from a script or server side app. |
| 7 |
| 8 Eventually the parse tree API will be compatible with [dart:html][d_html], so |
| 9 the same code will work on the client and the server. |
| 10 |
| 11 (Formerly known as _html5lib_.) |
| 12 |
| 13 Installation |
| 14 ------------ |
| 15 |
| 16 Add this to your `pubspec.yaml` (or create it): |
| 17 ```yaml |
| 18 dependencies: |
| 19 html: any |
| 20 ``` |
| 21 Then run the [Pub Package Manager][pub] (comes with the Dart SDK): |
| 22 |
| 23 pub install |
| 24 |
| 25 Usage |
| 26 ----- |
| 27 |
| 28 Parsing HTML is easy! |
| 29 ```dart |
| 30 import 'package:html/parser.dart' show parse; |
| 31 import 'package:html/dom.dart'; |
| 32 |
| 33 main() { |
| 34 var document = parse( |
| 35 '<body>Hello world! <a href="www.html5rocks.com">HTML5 rocks!'); |
| 36 print(document.outerHtml); |
| 37 } |
| 38 ``` |
| 39 |
| 40 You can pass a String or list of bytes to `parse`. |
| 41 There's also `parseFragment` for parsing a document fragment, and `HtmlParser` |
| 42 if you want more low level control. |
| 43 |
| 44 Running Tests |
| 45 ------------- |
| 46 |
| 47 ```bash |
| 48 ./test/run.sh |
| 49 ``` |
| 50 |
| 51 [dart]: http://www.dartlang.org/ |
| 52 [html5parse]: http://dev.w3.org/html5/spec/parsing.html |
| 53 [d_html]: http://api.dartlang.org/docs/continuous/dart_html.html |
| 54 [files]: http://html5lib.googlecode.com/hg/python/html5lib/ |
| 55 [pub]: http://www.dartlang.org/docs/pub-package-manager/ |
OLD | NEW |