27 parent::__construct( $options );
29 $this->attributeEscapes[
"\u{00A0}"] =
' ';
30 $this->textEscapes[
"\u{00A0}"] =
' ';
32 $this->textEscapes[
"\u{0338}"] =
'̸';
34 unset( $this->attributeEscapes[
"&"] );
35 unset( $this->textEscapes[
"&"] );
36 $this->textProcessor = $options[
'textProcessor'] ??
null;
51 public function characters( SerializerNode $parent, $text, $start, $length ) {
52 $text = parent::characters( $parent, $text, $start, $length );
54 if ( $parent->namespace !== HTMLData::NS_HTML
55 || !isset( $this->rawTextElements[$parent->name] )
57 if ( $this->textProcessor !==
null ) {
58 $text = ( $this->textProcessor )( $text );
62 $text = Sanitizer::normalizeCharReferences( $text );
69 public function element( SerializerNode $parent, SerializerNode $node, $contents ) {
70 $data = $node->snData;
71 if ( $data && $data->isPWrapper ) {
72 if ( $data->nonblankNodeCount ) {
73 return "<p>$contents</p>";
80 $attrs = $node->attrs;
81 if ( isset( self::MARKED_EMPTY_ELEMENTS[$name] ) && $attrs->count() === 0
82 && strspn( $contents,
"\t\n\f\r " ) === strlen( $contents )
84 return "<{$name} class=\"mw-empty-elt\">$contents</{$name}>";
88 foreach ( $attrs->getValues() as $attrName => $attrValue ) {
89 $encValue = strtr( $attrValue, $this->attributeEscapes );
90 $encValue = Sanitizer::normalizeCharReferences( $encValue );
91 $s .=
" $attrName=\"$encValue\"";
93 if ( $node->namespace === HTMLData::NS_HTML && isset( $this->voidElements[$name] ) ) {
99 if ( $node->namespace === HTMLData::NS_HTML
100 && isset( $contents[0] ) && $contents[0] ===
"\n"
101 && isset( $this->prefixLfElements[$name] )
103 $s .=
"\n$contents</$name>";
105 $s .=
"$contents</$name>";