Browse Source

Added TemplateElement

split-manual
Dustin Wilson 3 years ago
parent
commit
5ea14e81ca
  1. 14
      lib/DOM/Document.php
  2. 3
      lib/DOM/Element.php
  3. 12
      lib/DOM/TemplateElement.php
  4. 2
      lib/TreeBuilder.php

14
lib/DOM/Document.php

@ -63,11 +63,14 @@ class Document extends \DOMDocument {
public function createElement($name, $value = "") {
try {
$e = parent::createElement($name, $value);
if ($name === "template") {
if ($name !== 'template') {
$e = parent::createElement($name, $value);
} else {
$e = new TemplateElement($name, $value);
$this->templateElements[] = $e;
$e->content = $this->createDocumentFragment();
}
return $e;
} catch (\DOMException $e) {
// The element name is invalid for XML
@ -81,11 +84,14 @@ class Document extends \DOMDocument {
public function createElementNS($namespaceURI, $qualifiedName, $value = "") {
try {
$e = parent::createElementNS($namespaceURI, $qualifiedName, $value);
if ($qualifiedName === "template" && $namespaceURI === null) {
if ($qualifiedName !== 'template' && $namespaceURI !== null) {
$e = parent::createElementNS($namespaceURI, $qualifiedName, $value);
} else {
$e = new TemplateElement($qualifiedName, $value);
$this->templateElements[] = $e;
$e->content = $this->createDocumentFragment();
}
return $e;
} catch (\DOMException $e) {
// The element name is invalid for XML

3
lib/DOM/Element.php

@ -9,9 +9,6 @@ namespace MensBeam\HTML;
class Element extends \DOMElement {
use EscapeString, Moonwalk, Serialize, Walk;
// Used for template elements
public $content = null;
public function setAttribute($name, $value) {
try {
parent::setAttribute($name, $value);

12
lib/DOM/TemplateElement.php

@ -0,0 +1,12 @@
<?php
/** @license MIT
* Copyright 2017 , Dustin Wilson, J. King et al.
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace MensBeam\HTML;
/** Class specifically for template elements to handle its content property. */
class TemplateElement extends Element {
public $content = null;
}

2
lib/TreeBuilder.php

@ -3939,7 +3939,7 @@ class TreeBuilder {
}
public function insertStartTagToken(StartTagToken $token, \DOMNode $intendedParent = null, string $namespace = null): Element {
# When the steps below require the user agent to insert a foreign
# When the steps below require the user agent to insert a foreign
# element for a token in a given namespace, the user agent must
# run these steps:
// Doing both foreign and HTML elements here because the only

Loading…
Cancel
Save