Pull in the RemexHtml library, which is an HTML 5 library I recently created. RemexCompatMunger mutates the event stream, inserting <mw:p-wrap> elements where necessary, and occasionally taking even more invasive action such as reparenting and removing nodes maintained in Serializer's tree. RemexCompatFormatter produces a MediaWiki-style serialization which is relatively compatible with existing parser tests. It also does final empty element handling, including translating <mw:p-wrap> to <p> Tests are imported from both Html5Depurate and Subbu's pwrap.js. Depends-On: I864f31d9afdffdde49bfd39f07a0fb7f4df5c5d9 Change-Id: I900155b7dd199b0ae2a3b9cdb6db5136fc4f35a8
78 lines
2 KiB
PHP
78 lines
2 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Tidy;
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
class RemexMungerData {
|
|
/**
|
|
* The Element for the mw:p-wrap which is a child of the current node. If
|
|
* this is set, inline insertions into this node will be diverted so that
|
|
* they insert into the p-wrap.
|
|
*
|
|
* @var \RemexHtml\TreeBuilder\Element|null
|
|
*/
|
|
public $childPElement;
|
|
|
|
/**
|
|
* This tracks the mw:p-wrap node in the Serializer stack which is an
|
|
* ancestor of this node. If there is no mw:p-wrap ancestor, it is null.
|
|
*
|
|
* @var \RemexHtml\Serializer\SerializerNode|null
|
|
*/
|
|
public $ancestorPNode;
|
|
|
|
/**
|
|
* The wrap base node is the body or blockquote node which is the parent
|
|
* of active p-wrappers. This is set if there is an ancestor p-wrapper,
|
|
* or if a p-wrapper was closed due to a block element being encountered
|
|
* inside it.
|
|
*
|
|
* @var \RemexHtml\Serializer\SerializerNode|null
|
|
*/
|
|
public $wrapBaseNode;
|
|
|
|
/**
|
|
* Stack splitting (essentially our idea of AFE reconstruction) can clone
|
|
* formatting elements which are split over multiple paragraphs.
|
|
* TreeBuilder is not aware of the cloning, and continues to insert into
|
|
* the original element. This is set to the newer clone if this node was
|
|
* cloned, i.e. if there is an active diversion of the insertion location.
|
|
*
|
|
* @var \RemexHtml\TreeBuilder\Element|null
|
|
*/
|
|
public $currentCloneElement;
|
|
|
|
/**
|
|
* Is the node a p-wrapper, with name mw:p-wrap?
|
|
*
|
|
* @var bool
|
|
*/
|
|
public $isPWrapper = false;
|
|
|
|
/**
|
|
* Is the node splittable, i.e. a formatting element or a node with a
|
|
* formatting element ancestor which is under an active or deactivated
|
|
* p-wrapper.
|
|
*
|
|
* @var bool
|
|
*/
|
|
public $isSplittable = false;
|
|
|
|
/**
|
|
* This is true if the node is a body or blockquote, which activates
|
|
* p-wrapping of child nodes.
|
|
*/
|
|
public $needsPWrapping = false;
|
|
|
|
/**
|
|
* The number of child nodes, not counting whitespace-only text nodes or
|
|
* comments.
|
|
*/
|
|
public $nonblankNodeCount = 0;
|
|
|
|
public function __set( $name, $value ) {
|
|
throw new \Exception( "Cannot set property \"$name\"" );
|
|
}
|
|
}
|