diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/HTML5.php | 10 | ||||
-rw-r--r-- | src/HTML5/Parser/DOMTreeBuilder.php | 10 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/HTML5.php b/src/HTML5.php index a471c96..c9d5d57 100644 --- a/src/HTML5.php +++ b/src/HTML5.php @@ -151,6 +151,16 @@ class HTML5 { return $events->document(); } + public static function parseFragment(\HTML5\Parser\InputStream $input) { + $events = new DOMTreeBuilder(); + $scanner = new Scanner($input); + $parser = new Tokenizer($scanner, $events); + + $parser->parse(); + + return $events->fragment(); + } + /** * Get the default options. * diff --git a/src/HTML5/Parser/DOMTreeBuilder.php b/src/HTML5/Parser/DOMTreeBuilder.php index 5df4177..a5a20ba 100644 --- a/src/HTML5/Parser/DOMTreeBuilder.php +++ b/src/HTML5/Parser/DOMTreeBuilder.php @@ -81,6 +81,16 @@ class DOMTreeBuilder implements EventHandler { } /** + * Get the DOM fragment for the body. + * + * This returns a DOMNodeList because a fragment may have zero or more + * DOMNodes at its root. + */ + public function fragment() { + return $this->doc->documentElement->childNodes; + } + + /** * Provide an instruction processor. * * This is used for handling Processor Instructions as they are |