OutputRules
in package
implements
RulesInterface
Generate the output html5 based on element rules.
Table of Contents
Interfaces
- RulesInterface
- To create a new rule set for writing output the RulesInterface needs to be implemented.
Constants
- DOCTYPE = '<!DOCTYPE html>'
- IM_IN_HTML = 1
- IM_IN_MATHML = 3
- IM_IN_SVG = 2
- NAMESPACE_HTML = 'http://www.w3.org/1999/xhtml'
- Defined in http://www.w3.org/TR/html51/infrastructure.html#html-namespace-0.
- NAMESPACE_MATHML = 'http://www.w3.org/1998/Math/MathML'
- NAMESPACE_SVG = 'http://www.w3.org/2000/svg'
- NAMESPACE_XLINK = 'http://www.w3.org/1999/xlink'
- NAMESPACE_XML = 'http://www.w3.org/XML/1998/namespace'
- NAMESPACE_XMLNS = 'http://www.w3.org/2000/xmlns/'
Properties
- $encode : mixed
- $implicitNamespaces : array<string|int, mixed>
- Holds the HTML5 element names that causes a namespace switch.
- $nonBooleanAttributes : mixed
- $out : mixed
- $outputMode : mixed
- $traverser : mixed
- $hasHTML5 : bool
- Used as cache to detect if is available ENT_HTML5.
- $xpath : mixed
Methods
- __construct() : mixed
- The class constructor.
- addRule() : mixed
- cdata() : mixed
- Write a CDATA node.
- comment() : mixed
- Write a comment node.
- document() : mixed
- Write a document element (\DOMDocument).
- element() : mixed
- Write an element.
- processorInstruction() : mixed
- Write a processor instruction.
- setTraverser() : RulesInterface
- Register the traverser used in but the rules.
- text() : mixed
- Write a text node.
- unsetTraverser() : mixed
- attrs() : mixed
- closeTag() : mixed
- Write the closing tag.
- doctype() : mixed
- enc() : string
- Encode text.
- escape() : mixed
- Escape test.
- namespaceAttrs() : mixed
- Write the namespace attributes.
- nl() : $this
- Write a new line character.
- nonBooleanAttribute() : mixed
- openTag() : mixed
- Write the opening tag.
- wr() : $this
- Write to the output.
- getXPath() : mixed
Constants
DOCTYPE
public
mixed
DOCTYPE
= '<!DOCTYPE html>'
IM_IN_HTML
public
mixed
IM_IN_HTML
= 1
IM_IN_MATHML
public
mixed
IM_IN_MATHML
= 3
IM_IN_SVG
public
mixed
IM_IN_SVG
= 2
NAMESPACE_HTML
Defined in http://www.w3.org/TR/html51/infrastructure.html#html-namespace-0.
public
mixed
NAMESPACE_HTML
= 'http://www.w3.org/1999/xhtml'
NAMESPACE_MATHML
public
mixed
NAMESPACE_MATHML
= 'http://www.w3.org/1998/Math/MathML'
NAMESPACE_SVG
public
mixed
NAMESPACE_SVG
= 'http://www.w3.org/2000/svg'
NAMESPACE_XLINK
public
mixed
NAMESPACE_XLINK
= 'http://www.w3.org/1999/xlink'
NAMESPACE_XML
public
mixed
NAMESPACE_XML
= 'http://www.w3.org/XML/1998/namespace'
NAMESPACE_XMLNS
public
mixed
NAMESPACE_XMLNS
= 'http://www.w3.org/2000/xmlns/'
Properties
$encode
protected
mixed
$encode
= false
$implicitNamespaces
Holds the HTML5 element names that causes a namespace switch.
protected
array<string|int, mixed>
$implicitNamespaces
= array(self::NAMESPACE_HTML, self::NAMESPACE_SVG, self::NAMESPACE_MATHML, self::NAMESPACE_XML, self::NAMESPACE_XMLNS)
$nonBooleanAttributes
protected
mixed
$nonBooleanAttributes
= array(
/*
array(
'nodeNamespace'=>'http://www.w3.org/1999/xhtml',
'attrNamespace'=>'http://www.w3.org/1999/xhtml',
'nodeName'=>'img', 'nodeName'=>array('img', 'a'),
'attrName'=>'alt', 'attrName'=>array('title', 'alt'),
),
*/
array('nodeNamespace' => 'http://www.w3.org/1999/xhtml', 'attrName' => array('href', 'hreflang', 'http-equiv', 'icon', 'id', 'keytype', 'kind', 'label', 'lang', 'language', 'list', 'maxlength', 'media', 'method', 'name', 'placeholder', 'rel', 'rows', 'rowspan', 'sandbox', 'spellcheck', 'scope', 'seamless', 'shape', 'size', 'sizes', 'span', 'src', 'srcdoc', 'srclang', 'srcset', 'start', 'step', 'style', 'summary', 'tabindex', 'target', 'title', 'type', 'value', 'width', 'border', 'charset', 'cite', 'class', 'code', 'codebase', 'color', 'cols', 'colspan', 'content', 'coords', 'data', 'datetime', 'default', 'dir', 'dirname', 'enctype', 'for', 'form', 'formaction', 'headers', 'height', 'accept', 'accept-charset', 'accesskey', 'action', 'align', 'alt', 'bgcolor')),
array('nodeNamespace' => 'http://www.w3.org/1999/xhtml', 'xpath' => 'starts-with(local-name(), \'data-\')'),
)
$out
protected
mixed
$out
$outputMode
protected
mixed
$outputMode
$traverser
protected
mixed
$traverser
$hasHTML5
Used as cache to detect if is available ENT_HTML5.
private
bool
$hasHTML5
= false
$xpath
private
mixed
$xpath
Methods
__construct()
The class constructor.
public
__construct(mixed $output[, mixed $options = array() ]) : mixed
Note, before the rules can be used a traverser must be registered.
Parameters
- $output : mixed
-
The output stream to write output to.
- $options : mixed = array()
-
An array of options.
addRule()
public
addRule(array<string|int, mixed> $rule) : mixed
Parameters
- $rule : array<string|int, mixed>
cdata()
Write a CDATA node.
public
cdata(mixed $ele) : mixed
Instead of returning the result write it to the output stream ($output) that was passed into the constructor.
Parameters
- $ele : mixed
comment()
Write a comment node.
public
comment(mixed $ele) : mixed
Instead of returning the result write it to the output stream ($output) that was passed into the constructor.
Parameters
- $ele : mixed
document()
Write a document element (\DOMDocument).
public
document(mixed $dom) : mixed
Instead of returning the result write it to the output stream ($output) that was passed into the constructor.
Parameters
- $dom : mixed
element()
Write an element.
public
element(DOMElement $ele) : mixed
Parameters
- $ele : DOMElement
processorInstruction()
Write a processor instruction.
public
processorInstruction(mixed $ele) : mixed
To learn about processor instructions see InstructionProcessor
Instead of returning the result write it to the output stream ($output) that was passed into the constructor.
Parameters
- $ele : mixed
setTraverser()
Register the traverser used in but the rules.
public
setTraverser(Traverser $traverser) : RulesInterface
Note, only one traverser can be used by the rules.
Parameters
- $traverser : Traverser
-
The traverser used in the rules.
Return values
RulesInterface —$this for the current object.
text()
Write a text node.
public
text(DOMText $ele) : mixed
Parameters
- $ele : DOMText
-
The text node to write.
unsetTraverser()
public
unsetTraverser() : mixed
attrs()
protected
attrs(mixed $ele) : mixed
Parameters
- $ele : mixed
closeTag()
Write the closing tag.
protected
closeTag(DOMNode $ele) : mixed
Tags for HTML, MathML, and SVG are in the local name. Otherwise, use the qualified name (8.3).
Parameters
- $ele : DOMNode
-
The element being written.
doctype()
protected
doctype() : mixed
enc()
Encode text.
protected
enc(string $text[, bool $attribute = false ]) : string
When encode is set to false, the default value, the text passed in is escaped per section 8.3 of the html5 spec. For details on how text is escaped see the escape() method.
When encoding is set to true the text is converted to named character references where appropriate. Section 8.1.4 Character references of the html5 spec refers to using named character references. This is useful for characters that can't otherwise legally be used in the text.
The named character references are listed in section 8.5.
Parameters
- $text : string
-
Text to encode.
- $attribute : bool = false
-
True if we are encoding an attrubute, false otherwise.
Tags
Return values
string —The encoded text.
escape()
Escape test.
protected
escape(string $text[, bool $attribute = false ]) : mixed
According to the html5 spec section 8.3 Serializing HTML fragments, text within tags that are not style, script, xmp, iframe, noembed, and noframes need to be properly escaped.
The & should be converted to &, no breaking space unicode characters converted to , when in attribute mode the " should be converted to ", and when not in attribute mode the < and > should be converted to < and >.
Parameters
- $text : string
-
Text to escape.
- $attribute : bool = false
-
True if we are escaping an attrubute, false otherwise.
Tags
namespaceAttrs()
Write the namespace attributes.
protected
namespaceAttrs(DOMNode $ele) : mixed
Parameters
- $ele : DOMNode
-
The element being written.
nl()
Write a new line character.
protected
nl() : $this
Return values
$thisnonBooleanAttribute()
protected
nonBooleanAttribute(DOMAttr $attr) : mixed
Parameters
- $attr : DOMAttr
openTag()
Write the opening tag.
protected
openTag(DOMNode $ele) : mixed
Tags for HTML, MathML, and SVG are in the local name. Otherwise, use the qualified name (8.3).
Parameters
- $ele : DOMNode
-
The element being written.
wr()
Write to the output.
protected
wr(string $text) : $this
Parameters
- $text : string
-
The string to put into the output
Return values
$thisgetXPath()
private
getXPath(DOMNode $node) : mixed
Parameters
- $node : DOMNode