3 namespace MediaWiki\Tidy
;
5 use InvalidArgumentException
;
6 use Wikimedia\RemexHtml\Serializer\SerializerNode
;
7 use Wikimedia\RemexHtml\TreeBuilder\Element
;
12 class RemexMungerData
{
14 * The Element for the mw:p-wrap which is a child of the current node. If
15 * this is set, inline insertions into this node will be diverted so that
16 * they insert into the p-wrap.
20 public $childPElement;
23 * This tracks the mw:p-wrap node in the Serializer stack which is an
24 * ancestor of this node. If there is no mw:p-wrap ancestor, it is null.
26 * @var SerializerNode|null
28 public $ancestorPNode;
31 * The wrap base node is the body or blockquote node which is the parent
32 * of active p-wrappers. This is set if there is an ancestor p-wrapper,
33 * or if a p-wrapper was closed due to a block element being encountered
36 * @var SerializerNode|null
41 * Stack splitting (essentially our idea of AFE reconstruction) can clone
42 * formatting elements which are split over multiple paragraphs.
43 * TreeBuilder is not aware of the cloning, and continues to insert into
44 * the original element. This is set to the newer clone if this node was
45 * cloned, i.e. if there is an active diversion of the insertion location.
49 public $currentCloneElement;
52 * Is the node a p-wrapper, with name mw:p-wrap?
56 public $isPWrapper = false;
59 * Is the node splittable, i.e. a formatting element or a node with a
60 * formatting element ancestor which is under an active or deactivated
65 public $isSplittable = false;
68 * This is true if the node is a body or blockquote, which activates
69 * p-wrapping of child nodes.
73 public $needsPWrapping = false;
76 * The number of child nodes, not counting whitespace-only text nodes or
81 public $nonblankNodeCount = 0;
83 public function __set( $name, $value ) {
84 // @phan-suppress-previous-line PhanPluginNeverReturnMethod
85 throw new InvalidArgumentException( "Cannot set property \"$name\"" );
89 * Get a text representation of the current state of the serializer, for
94 public function dump() {
97 if ( $this->childPElement
) {
98 $parts[] = 'childPElement=' . $this->childPElement
->getDebugTag();
100 if ( $this->ancestorPNode
) {
101 $parts[] = "ancestorPNode=<{$this->ancestorPNode->name}>";
103 if ( $this->wrapBaseNode
) {
104 $parts[] = "wrapBaseNode=<{$this->wrapBaseNode->name}>";
106 if ( $this->currentCloneElement
) {
107 $parts[] = "currentCloneElement=" . $this->currentCloneElement
->getDebugTag();
109 if ( $this->isPWrapper
) {
110 $parts[] = 'isPWrapper';
112 if ( $this->isSplittable
) {
113 $parts[] = 'isSplittable';
115 if ( $this->needsPWrapping
) {
116 $parts[] = 'needsPWrapping';
118 if ( $this->nonblankNodeCount
) {
119 $parts[] = "nonblankNodeCount={$this->nonblankNodeCount}";
121 $s = "RemexMungerData {\n";
122 foreach ( $parts as $part ) {