summaryrefslogtreecommitdiff
path: root/src/HTML5/Parser
diff options
context:
space:
mode:
authorJohn Slegers <[email protected]>2014-12-04 16:51:29 +0100
committerAsmir Mustafic <[email protected]>2015-02-06 22:07:21 +0100
commited7cc5f4e06eed696cdd829a3197fbe8927c0721 (patch)
tree8e065f6cf2609b5f238cc61bbfa6bc4543069de3 /src/HTML5/Parser
parentdda3253aa29800d12795c291e55578bbabbc4cb4 (diff)
Adding "disableHtmlNsInDom" and "targetDocument" options to allow more
flexible HTML DOM creation. New Options: * disableHtmlNsInDom = Allows the use of createElement instead of createElementNS for HTML elements. * targetDocument = allows an existing DOMDocument (or subclass thereof) to be passsed to the DOMTreeBuilder instead of creating a new one.
Diffstat (limited to 'src/HTML5/Parser')
-rw-r--r--src/HTML5/Parser/DOMTreeBuilder.php26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/HTML5/Parser/DOMTreeBuilder.php b/src/HTML5/Parser/DOMTreeBuilder.php
index 0349d60..da3f06b 100644
--- a/src/HTML5/Parser/DOMTreeBuilder.php
+++ b/src/HTML5/Parser/DOMTreeBuilder.php
@@ -157,13 +157,17 @@ class DOMTreeBuilder implements EventHandler
{
$this->options = $options;
- $impl = new \DOMImplementation();
- // XXX:
- // Create the doctype. For now, we are always creating HTML5
- // documents, and attempting to up-convert any older DTDs to HTML5.
- $dt = $impl->createDocumentType('html');
- // $this->doc = \DOMImplementation::createDocument(NULL, 'html', $dt);
- $this->doc = $impl->createDocument(null, null, $dt);
+ if (isset($options['targetDocument'])) {
+ $this->doc = $options['targetDocument'];
+ } else {
+ $impl = new \DOMImplementation();
+ // XXX:
+ // Create the doctype. For now, we are always creating HTML5
+ // documents, and attempting to up-convert any older DTDs to HTML5.
+ $dt = $impl->createDocumentType('html');
+ // $this->doc = \DOMImplementation::createDocument(NULL, 'html', $dt);
+ $this->doc = $impl->createDocument(null, null, $dt);
+ }
$this->errors = array();
$this->current = $this->doc; // ->documentElement;
@@ -345,10 +349,10 @@ class DOMTreeBuilder implements EventHandler
$ele = $this->doc->importNode($frag->documentElement, true);
} else {
- if (isset($this->nsStack[0][$prefix])) {
- $ele = $this->doc->createElementNS($this->nsStack[0][$prefix], $lname);
- } else {
+ if (!isset($this->nsStack[0][$prefix]) || ($prefix === "" && isset($this->options['disableHtmlNsInDom']) && $this->options['disableHtmlNsInDom'])) {
$ele = $this->doc->createElement($lname);
+ } else {
+ $ele = $this->doc->createElementNS($this->nsStack[0][$prefix], $lname);
}
}
@@ -664,4 +668,4 @@ class DOMTreeBuilder implements EventHandler
{
return $this->current->tagName == $tagname;
}
-}
+} \ No newline at end of file