| 1 | <?php |
||
| 11 | class HTML5_Parser |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * Parses a full HTML document. |
||
| 15 | * @param $text HTML text to parse |
||
| 16 | * @param $builder Custom builder implementation |
||
| 17 | * @return Parsed HTML as DOMDocument |
||
| 18 | */ |
||
| 19 | static public function parse($text, $builder = null) { |
||
| 20 | $tokenizer = new HTML5_Tokenizer($text, $builder); |
||
| 21 | $tokenizer->parse(); |
||
| 22 | return $tokenizer->save(); |
||
| 23 | } |
||
| 24 | /** |
||
| 25 | * Parses an HTML fragment. |
||
| 26 | * @param $text HTML text to parse |
||
| 27 | * @param $context String name of context element to pretend parsing is in. |
||
| 28 | * @param $builder Custom builder implementation |
||
| 29 | * @return Parsed HTML as DOMDocument |
||
| 30 | */ |
||
| 31 | static public function parseFragment($text, $context = null, $builder = null) { |
||
| 32 | $tokenizer = new HTML5_Tokenizer($text, $builder); |
||
| 33 | $tokenizer->parseFragment($context); |
||
| 34 | return $tokenizer->save(); |
||
| 35 | } |
||
| 36 | } |
||
| 37 |