TemplateInspector
class TemplateInspector
This class helps the RulesGenerator by analyzing a given template in order to answer questions such as "can this tag be a child/descendant of that other tag?" and others related to the HTML5 content model.
We use the HTML5 specs to determine which children or descendants should be allowed or denied based on HTML5 content models. While it does not exactly match HTML5 content models, it gets pretty close. We also use HTML5 "optional end tag" rules to create closeParent rules.
Currently, this method does not evaluate elements created with
Constants
XMLNS_XSL |
XSL namespace |
Properties
protected string[] | $allowChildBitfields | ||
protected bool | $allowsChildElements | ||
protected bool | $allowsText | ||
protected array[] | $branches | ||
protected string | $contentBitfield | ||
protected string | $defaultBranchBitfield | ||
protected string | $denyDescendantBitfield | ||
protected DOMDocument | $dom | ||
protected bool | $hasElements | ||
protected bool | $hasRootText | ||
protected bool | $isBlock | ||
protected bool | $isEmpty | ||
protected bool | $isFormattingElement | ||
protected bool | $isPassthrough | ||
protected bool | $isTransparent | ||
protected bool | $isVoid | ||
protected array | $leafNodes | ||
protected bool | $preservesNewLines | ||
protected array | $rootBitfields | ||
protected array | $rootNodes | ||
protected DOMXPath | $xpath |
Methods
Constructor
Return whether this template allows a given descendant
Return whether this template allows elements as children
Return whether this template allows text nodes as children
Return whether this template automatically closes given parent template
Return whether this template should be considered a block-level element
Return whether this template adds to the list of active formatting elements
Return whether this template uses the "empty" content model
Return whether this template lets content through via an xsl:apply-templates element
Return whether this template uses the "transparent" content model
Return whether all branches have an ancestor that is a void element
Return whether this template preserves the whitespace in its descendants
Analyses the content of the whole template and set $this->contentBitfield accordingly
Records the HTML elements (and their bitfield) rendered at the root of the template
Analyses each branch that leads to an
Test whether any branch of this template has an element that has given property
Compute the allowChildBitfields and denyDescendantBitfield properties
Compute the allowsChildElements property
Compute the allowsText property
Compute the isFormattingElement property
Compute the isEmpty property
Compute the isTransparent property
Compute the isVoid property
Compute the preservesNewLines property
Retrieve and return the inline style assigned to given element
Store the names of every leaf node
Test whether two bitfields have any bits in common
Details
at line 147
__construct(string $template)
Constructor
at line 165
bool
allowsChild(TemplateInspector $child)
Return whether this template allows a given child
at line 193
bool
allowsDescendant(TemplateInspector $descendant)
Return whether this template allows a given descendant
at line 210
bool
allowsChildElements()
Return whether this template allows elements as children
at line 220
bool
allowsText()
Return whether this template allows text nodes as children
at line 231
bool
closesParent(TemplateInspector $parent)
Return whether this template automatically closes given parent template
at line 255
mixed
evaluate(string $expr, DOMElement|null $node = null)
Evaluate an XPath expression
at line 265
bool
isBlock()
Return whether this template should be considered a block-level element
at line 275
bool
isFormattingElement()
Return whether this template adds to the list of active formatting elements
at line 285
bool
isEmpty()
Return whether this template uses the "empty" content model
at line 295
bool
isPassthrough()
Return whether this template lets content through via an xsl:apply-templates element
at line 305
bool
isTransparent()
Return whether this template uses the "transparent" content model
at line 315
bool
isVoid()
Return whether all branches have an ancestor that is a void element
at line 325
bool
preservesNewLines()
Return whether this template preserves the whitespace in its descendants
at line 333
protected
analyseContent()
Analyses the content of the whole template and set $this->contentBitfield accordingly
at line 350
protected
analyseRootNodes()
Records the HTML elements (and their bitfield) rendered at the root of the template
at line 389
protected
analyseBranches()
Analyses each branch that leads to an
at line 415
protected bool
anyBranchHasProperty(string $methodName)
Test whether any branch of this template has an element that has given property
at line 436
protected void
computeBitfields()
Compute the allowChildBitfields and denyDescendantBitfield properties
at line 481
protected void
computeAllowsChildElements()
Compute the allowsChildElements property
A template allows child Elements if it has at least one xsl:apply-templates and none of its ancestors have the text-only ("to") property
at line 493
protected void
computeAllowsText()
Compute the allowsText property
A template is said to allow text if none of the leaf elements disallow text
at line 515
protected void
computeFormattingElement()
Compute the isFormattingElement property
A template is said to be a formatting element if all (non-zero) of its branches are entirely composed of formatting elements
at line 540
protected void
computeIsEmpty()
Compute the isEmpty property
A template is said to be empty if it has no xsl:apply-templates elements or any there is a empty element ancestor to an xsl:apply-templates element
at line 553
protected void
computeIsTransparent()
Compute the isTransparent property
A template is said to be transparent if it has at least one branch and no non-transparent elements in its path
at line 578
protected void
computeIsVoid()
Compute the isVoid property
A template is said to be void if it has no xsl:apply-templates elements or any there is a void element ancestor to an xsl:apply-templates element
at line 588
protected void
computePreservesNewLines()
Compute the preservesNewLines property
at line 614
protected bool
elementIsBlock(DOMElement $element)
Test whether given element is a block-level element
at line 636
protected string
getStyle(DOMElement $node, bool $deep = false)
Retrieve and return the inline style assigned to given element
at line 664
protected bool
isFormattingSpan(DOMElement $node)
Test whether given node is a span element used for formatting
Will return TRUE if the node is a span element with a class attribute and/or a style attribute and no other attributes
at line 694
protected void
storeLeafNodes()
Store the names of every leaf node
A leaf node is defined as the closest non-XSL ancestor to an xsl:apply-templates element
at line 709
static protected bool
match(string $bitfield1, string $bitfield2)
Test whether two bitfields have any bits in common