MediaWiki REL1_35
MediaWiki\Tidy\RemexCompatMunger Class Reference
Inheritance diagram for MediaWiki\Tidy\RemexCompatMunger:
Collaboration diagram for MediaWiki\Tidy\RemexCompatMunger:

Public Member Functions

 __construct (Serializer $serializer, $trace=false)
 
 characters ( $preposition, $refElement, $text, $start, $length, $sourceStart, $sourceLength)
 
 comment ( $preposition, $refElement, $text, $sourceStart, $sourceLength)
 
 doctype ( $name, $public, $system, $quirks, $sourceStart, $sourceLength)
 
 endDocument ( $pos)
 
 endTag (Element $element, $sourceStart, $sourceLength)
 
 error ( $text, $pos)
 
 insertElement ( $preposition, $refElement, Element $element, $void, $sourceStart, $sourceLength)
 Insert or reparent an element.
 
 mergeAttributes (Element $element, Attributes $attrs, $sourceStart)
 
 removeNode (Element $element, $sourceStart)
 
 reparentChildren (Element $element, Element $newParent, $sourceStart)
 
 startDocument ( $fragmentNamespace, $fragmentName)
 

Private Member Functions

 disablePWrapper (SerializerNode $node, $sourceStart)
 Find the ancestor of $node which is a child of a p-wrapper, and reparent that node so that it is placed after the end of the p-wrapper.
 
 getParentForInsert ( $preposition, $refElement)
 
 insertPWrapper (SerializerNode $parent, $sourceStart)
 Insert a p-wrapper.
 
 splitTagStack (SerializerNode $parentNode, $inline, $pos)
 Clone nodes in a stack range and return the new parent.
 
 trace ( $msg)
 

Private Attributes

Serializer $serializer
 
bool $trace
 

Static Private Attributes

static $formattingElements
 
static array $metadataElements
 For the purposes of this class, "metadata" elements are those that should neither trigger p-wrapping nor stop an outer p-wrapping, typically those that are themselves invisible in a browser's rendering.
 
static $onlyInlineElements
 

Detailed Description

Definition at line 17 of file RemexCompatMunger.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Tidy\RemexCompatMunger::__construct ( Serializer  $serializer,
  $trace = false 
)

Member Function Documentation

◆ characters()

MediaWiki\Tidy\RemexCompatMunger::characters (   $preposition,
  $refElement,
  $text,
  $start,
  $length,
  $sourceStart,
  $sourceLength 
)

◆ comment()

MediaWiki\Tidy\RemexCompatMunger::comment (   $preposition,
  $refElement,
  $text,
  $sourceStart,
  $sourceLength 
)

◆ disablePWrapper()

MediaWiki\Tidy\RemexCompatMunger::disablePWrapper ( SerializerNode  $node,
  $sourceStart 
)
private

Find the ancestor of $node which is a child of a p-wrapper, and reparent that node so that it is placed after the end of the p-wrapper.

Parameters
SerializerNode$node
int$sourceStart

Definition at line 440 of file RemexCompatMunger.php.

Referenced by MediaWiki\Tidy\RemexCompatMunger\insertElement().

◆ doctype()

MediaWiki\Tidy\RemexCompatMunger::doctype (   $name,
  $public,
  $system,
  $quirks,
  $sourceStart,
  $sourceLength 
)

Definition at line 481 of file RemexCompatMunger.php.

◆ endDocument()

MediaWiki\Tidy\RemexCompatMunger::endDocument (   $pos)

Definition at line 129 of file RemexCompatMunger.php.

◆ endTag()

MediaWiki\Tidy\RemexCompatMunger::endTag ( Element  $element,
  $sourceStart,
  $sourceLength 
)

◆ error()

MediaWiki\Tidy\RemexCompatMunger::error (   $text,
  $pos 
)

Definition at line 491 of file RemexCompatMunger.php.

◆ getParentForInsert()

MediaWiki\Tidy\RemexCompatMunger::getParentForInsert (   $preposition,
  $refElement 
)
private

◆ insertElement()

MediaWiki\Tidy\RemexCompatMunger::insertElement (   $preposition,
  $refElement,
Element  $element,
  $void,
  $sourceStart,
  $sourceLength 
)

Insert or reparent an element.

Create p-wrappers or split the tag stack as necessary.

Consider the following insertion locations. The parent may be:

  • A: A body or blockquote (!!needsPWrapping)
  • B: A p-wrapper (!!isPWrapper)
  • C: A descendant of a p-wrapper (!!ancestorPNode)
    • CS: With splittable formatting elements in the stack region up to the p-wrapper
    • CU: With one or more unsplittable elements in the stack region up to the p-wrapper
  • D: Not a descendant of a p-wrapper (!ancestorNode)
    • DS: With splittable formatting elements in the stack region up to the body or blockquote
    • DU: With one or more unsplittable elements in the stack region up to the body or blockquote

And consider that we may insert two types of element:

  • b: block
  • i: inline

We handle the insertion as follows:

  • A/i: Create a p-wrapper, insert under it
  • A/b: Insert as normal
  • B/i: Insert as normal
  • B/b: Close the p-wrapper, insert under the body/blockquote (wrap base) instead)
  • C/i: Insert as normal
  • CS/b: Split the tag stack, insert the block under cloned formatting elements which have the wrap base (the parent of the p-wrap) as their ultimate parent.
  • CU/b: Disable the p-wrap, by reparenting the currently open child of the p-wrap under the p-wrap's parent. Then insert the block as normal.
  • D/b: Insert as normal
  • DS/i: Split the tag stack, creating a new p-wrapper as the ultimate parent of the formatting elements thus cloned. The parent of the p-wrapper is the body or blockquote.
  • DU/i: Insert as normal

FIXME: fostering ($preposition == BEFORE) is mostly done by inserting as normal, the full algorithm is not followed.

Parameters
int$preposition
Element | SerializerNode | null$refElement
Element$element
bool$void
int$sourceStart
int$sourceLength

Definition at line 268 of file RemexCompatMunger.php.

References MediaWiki\Tidy\RemexCompatMunger\disablePWrapper(), MediaWiki\Tidy\RemexCompatMunger\getParentForInsert(), MediaWiki\Tidy\RemexCompatMunger\insertPWrapper(), MediaWiki\Tidy\RemexCompatMunger\splitTagStack(), and MediaWiki\Tidy\RemexCompatMunger\trace().

Referenced by MediaWiki\Tidy\RemexCompatMunger\reparentChildren().

◆ insertPWrapper()

MediaWiki\Tidy\RemexCompatMunger::insertPWrapper ( SerializerNode  $parent,
  $sourceStart 
)
private

Insert a p-wrapper.

Parameters
SerializerNode$parent
int$sourceStart
Returns
SerializerNode

Definition at line 167 of file RemexCompatMunger.php.

Referenced by MediaWiki\Tidy\RemexCompatMunger\characters(), MediaWiki\Tidy\RemexCompatMunger\insertElement(), and MediaWiki\Tidy\RemexCompatMunger\splitTagStack().

◆ mergeAttributes()

MediaWiki\Tidy\RemexCompatMunger::mergeAttributes ( Element  $element,
Attributes  $attrs,
  $sourceStart 
)

Definition at line 495 of file RemexCompatMunger.php.

◆ removeNode()

MediaWiki\Tidy\RemexCompatMunger::removeNode ( Element  $element,
  $sourceStart 
)

Definition at line 499 of file RemexCompatMunger.php.

◆ reparentChildren()

MediaWiki\Tidy\RemexCompatMunger::reparentChildren ( Element  $element,
Element  $newParent,
  $sourceStart 
)

◆ splitTagStack()

MediaWiki\Tidy\RemexCompatMunger::splitTagStack ( SerializerNode  $parentNode,
  $inline,
  $pos 
)
private

Clone nodes in a stack range and return the new parent.

Parameters
SerializerNode$parentNode
bool$inline
int$posThe source position
Returns
SerializerNode

Definition at line 364 of file RemexCompatMunger.php.

References MediaWiki\Tidy\RemexCompatMunger\$serializer, and MediaWiki\Tidy\RemexCompatMunger\insertPWrapper().

Referenced by MediaWiki\Tidy\RemexCompatMunger\characters(), and MediaWiki\Tidy\RemexCompatMunger\insertElement().

◆ startDocument()

MediaWiki\Tidy\RemexCompatMunger::startDocument (   $fragmentNamespace,
  $fragmentName 
)

Definition at line 122 of file RemexCompatMunger.php.

◆ trace()

Member Data Documentation

◆ $formattingElements

MediaWiki\Tidy\RemexCompatMunger::$formattingElements
staticprivate
Initial value:
= [
'a' => true,
'b' => true,
'big' => true,
'code' => true,
'em' => true,
'font' => true,
'i' => true,
'nobr' => true,
's' => true,
'small' => true,
'strike' => true,
'strong' => true,
'tt' => true,
'u' => true,
]

Definition at line 90 of file RemexCompatMunger.php.

◆ $metadataElements

array MediaWiki\Tidy\RemexCompatMunger::$metadataElements
staticprivate
Initial value:
= [
'style' => true,
'script' => true,
'link' => true,
'meta' => true,
]

For the purposes of this class, "metadata" elements are those that should neither trigger p-wrapping nor stop an outer p-wrapping, typically those that are themselves invisible in a browser's rendering.

This isn't a complete list, it's just the tags that we're likely to encounter in practice.

Definition at line 83 of file RemexCompatMunger.php.

◆ $onlyInlineElements

MediaWiki\Tidy\RemexCompatMunger::$onlyInlineElements
staticprivate

Definition at line 18 of file RemexCompatMunger.php.

◆ $serializer

Serializer MediaWiki\Tidy\RemexCompatMunger::$serializer
private

◆ $trace

bool MediaWiki\Tidy\RemexCompatMunger::$trace
private

Definition at line 111 of file RemexCompatMunger.php.

Referenced by MediaWiki\Tidy\RemexCompatMunger\__construct().


The documentation for this class was generated from the following file: