3 namespace RemexHtml\TreeBuilder;
4 use RemexHtml\Tokenizer\Attributes;
6 interface TreeHandler {
8 * Called when parsing starts.
10 * @param string|null $fragmentNamespace The fragment namespace, or null
11 * to run in document mode.
12 * @param string|null $fragmentName The fragment tag name, or null to run
15 function startDocument( $fragmentNamespace, $fragmentName );
18 * Called when parsing stops.
20 * @param integer $pos The input string length, i.e. the past-the-end position.
22 function endDocument( $pos );
27 * @param integer $preposition The placement of the new node with respect
28 * to $ref. May be TreeBuilder::
29 * - BEFORE: insert as a sibling before the reference element
30 * - UNDER: append as the last child of the reference element
31 * - ROOT: append as the last child of the document node
32 * @param Element|null $ref Insert before/below this element, or null if
33 * $preposition is ROOT.
34 * @param string $text The text to insert is a substring of this string,
35 * with the start and length of the substring given by $start and
36 * $length. We do it this way to avoid unnecessary copying.
37 * @param integer $start The start of the substring
38 * @param integer $length The length of the substring
39 * @param integer $sourceStart The input position. This is not necessarily
40 * accurate, particularly when the tokenizer is run without ignoreEntities,
41 * or in CDATA sections.
42 * @param integer $sourceLength The length of the input which is consumed.
43 * The same caveats apply as for $sourceStart.
45 function characters( $preposition, $ref, $text, $start, $length, $sourceStart, $sourceLength );
48 * Insert an element. The element name and attributes are given in the
49 * supplied Element object. Handlers for this event typically attach an
50 * identifier to the userData property of the Element object, to identify
51 * the element when it is used again in subsequent tree mutations.
53 * @param integer $preposition The placement of the new node with respect
54 * to $ref. May be TreeBuilder::
55 * - BEFORE: insert as a sibling before the reference element
56 * - UNDER: append as the last child of the reference element
57 * - ROOT: append as the last child of the document node
58 * @param Element|null $ref Insert before/below this element, or null if
59 * $preposition is ROOT.
60 * @param Element $element An object containing information about the new
61 * element. The same object will be used for $parent and $refNode in
62 * other calls as appropriate. The handler can set $element->userData to
63 * attach a suitable DOM object to identify the mutation target in
65 * @param bool $void True if this is a void element which cannot
66 * have any children appended to it. This is usually true if the element
67 * is closed by the same token that opened it. No endTag() event will be
68 * sent for such an element. This is only true if self-closing tags are
69 * acknowledged for this tag name, so it is a hint to the serializer that
70 * a self-closing tag is acceptable.
71 * @param integer $sourceStart The input position
72 * @param integer $sourceLength The length of the input which is consumed
74 function insertElement( $preposition, $ref, Element $element, $void,
75 $sourceStart, $sourceLength );
78 * A hint that an element was closed and was removed from the stack
79 * of open elements. It probably won't be mutated again.
81 * @param Element $element The element being ended
82 * @param integer $sourceStart The input position
83 * @param integer $sourceLength The length of the input which is consumed
85 function endTag( Element $element, $sourceStart, $sourceLength );
88 * A valid DOCTYPE token was found.
90 * @param string $name The doctype name, usually "html"
91 * @param string $public The PUBLIC identifier
92 * @param string $system The SYSTEM identifier
93 * @param integer $quirks The quirks mode implied from the doctype. One of:
94 * - TreeBuilder::NO_QUIRKS : no quirks
95 * - TreeBuilder::LIMITED_QUIRKS : limited quirks
96 * - TreeBuilder::QUIRKS : full quirks
97 * @param integer $sourceStart The input position
98 * @param integer $sourceLength The length of the input which is consumed
100 function doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength );
105 * @param integer $preposition The placement of the new node with respect
106 * to $ref. May be TreeBuilder::
107 * - BEFORE: insert as a sibling before the reference element
108 * - UNDER: append as the last child of the reference element
109 * - ROOT: append as the last child of the document node
110 * @param Element|null $ref Insert before/below this element, or null if
111 * $preposition is ROOT.
112 * @param string $text The text of the comment
113 * @param integer $sourceStart The input position
114 * @param integer $sourceLength The length of the input which is consumed
116 function comment( $preposition, $ref, $text, $sourceStart, $sourceLength );
121 * @param string $text An error message explaining in English what the
122 * author did wrong, and what the parser intends to do about the
124 * @param integer $pos The input position at which the error occurred
126 function error( $text, $pos );
129 * Add attributes to an existing element. This is used to update the
130 * attributes of the <html> or <body> elements. The event receiver
131 * should add only those attributes which the original element does not
132 * already have. It should not overwrite existing attributes.
134 * @param Element $element The element to update
135 * @param Attributes $attrs The new attributes to add
136 * @param integer $sourceStart The input position
138 function mergeAttributes( Element $element, Attributes $attrs, $sourceStart );
141 * Remove a node from the tree, and all its children. This is only done
142 * when a <frameset> element is found, which triggers removal of the
143 * partially-constructed body element.
145 * @param Element $element The element to remove
146 * @param integer $sourceStart The location in the source at which this
147 * action was triggered.
149 function removeNode( Element $element, $sourceStart );
152 * Take all children of a given parent $element, and insert them as
153 * children of $newParent, removing them from their original parent in the
154 * process. Insert $newParent as now the only child of $element.
156 * @param Element $element The old parent element
157 * @param Element $newParent The new parent element
158 * @param integer $sourceStart The location in the source at which this
159 * action was triggered.
161 function reparentChildren( Element $element, Element $newParent, $sourceStart );