58 TokenHandler $nextHandler,
61 ?callable $attrCallback,
64 parent::__construct( $nextHandler );
66 $this->htmlsingle = $tagData[
'htmlsingle'];
67 $this->htmlsingleonly = $tagData[
'htmlsingleonly'];
68 $this->htmlelements = $tagData[
'htmlelements'];
69 $this->attrCallback = $attrCallback;
70 $this->callbackArgs = $callbackArgs ?? [];
117 public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
122 $t = strtolower( $name );
123 if ( isset( $this->htmlelements[$t] ) ) {
124 if ( $this->attrCallback ) {
125 $attrs = ( $this->attrCallback )( $attrs, ...$this->callbackArgs );
127 if ( $selfClose && !( isset( $this->htmlsingle[$t] ) || isset( $this->htmlsingleonly[$t] ) ) ) {
132 if ( !self::validateTag( $t, $attrs ) ) {
136 $attrs =
new PlainAttributes( $fixedAttrs );
138 if ( $selfClose && !isset( $this->htmlsingleonly[$t] ) ) {
142 $this->nextHandler->startTag( $name, $attrs,
false, $sourceStart, $sourceLength );
143 $this->nextHandler->endTag( $name, $sourceStart + $sourceLength, 0 );
145 $this->nextHandler->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
151 $this->nextHandler->characters( $this->source, $sourceStart, $sourceLength, $sourceStart, $sourceLength );
157 public function endTag( $name, $sourceStart, $sourceLength ) {
161 $t = strtolower( $name );
162 if ( isset( $this->htmlelements[$t] ) ) {
164 $this->nextHandler->endTag( $name, $sourceStart, $sourceLength );
167 $this->nextHandler->characters( $this->source, $sourceStart, $sourceLength, $sourceStart, $sourceLength );