64 TokenHandler $nextHandler,
67 ?callable $attrCallback,
71 parent::__construct( $nextHandler );
73 $this->htmlsingle = $tagData[
'htmlsingle'];
74 $this->htmlsingleonly = $tagData[
'htmlsingleonly'];
75 $this->htmlelements = $tagData[
'htmlelements'];
76 $this->attrCallback = $attrCallback;
77 $this->callbackArgs = $callbackArgs ?? [];
78 $this->commentRegex = $options[
'commentRegex'] ??
null;
84 public function comment( $text, $sourceStart, $sourceLength ) {
85 if ( $this->commentRegex !==
null && preg_match( $this->commentRegex, $text ) ) {
86 $this->nextHandler->comment( $text, $sourceStart, $sourceLength );
127 public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
132 $t = strtolower( $name );
133 if ( isset( $this->htmlelements[$t] ) ) {
134 if ( $this->attrCallback ) {
135 $attrs = ( $this->attrCallback )( $attrs, ...$this->callbackArgs );
137 if ( $selfClose && !( isset( $this->htmlsingle[$t] ) || isset( $this->htmlsingleonly[$t] ) ) ) {
142 if ( !self::validateTag( $t, $attrs ) ) {
146 $attrs =
new PlainAttributes( $fixedAttrs );
148 if ( $selfClose && !isset( $this->htmlsingleonly[$t] ) ) {
152 $this->nextHandler->startTag( $name, $attrs,
false, $sourceStart, $sourceLength );
153 $this->nextHandler->endTag( $name, $sourceStart + $sourceLength, 0 );
155 $this->nextHandler->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
161 $this->nextHandler->characters( $this->source, $sourceStart, $sourceLength, $sourceStart, $sourceLength );
167 public function endTag( $name, $sourceStart, $sourceLength ) {
171 $t = strtolower( $name );
172 if ( isset( $this->htmlelements[$t] ) ) {
174 $this->nextHandler->endTag( $name, $sourceStart, $sourceLength );
177 $this->nextHandler->characters( $this->source, $sourceStart, $sourceLength, $sourceStart, $sourceLength );