Parsoid
A bidirectional parser between wikitext and HTML5
Loading...
Searching...
No Matches
Wikimedia\Parsoid\Wt2Html\DOM\Processors\AnnotationDOMRangeBuilder Class Reference

The handling of annotation ranges and transclusion ranges are somewhat different for a number of reasons. More...

+ Inheritance diagram for Wikimedia\Parsoid\Wt2Html\DOM\Processors\AnnotationDOMRangeBuilder:
+ Collaboration diagram for Wikimedia\Parsoid\Wt2Html\DOM\Processors\AnnotationDOMRangeBuilder:

Public Member Functions

 __construct (Document $document, Frame $frame)
 AnnotationDOMRangeBuilder constructor.
 
 execute (Node $root)
 
- Public Member Functions inherited from Wikimedia\Parsoid\Wt2Html\DOM\Processors\DOMRangeBuilder
 findTopLevelNonOverlappingRanges (Node $docRoot, array $tplRanges)
 Identify the elements of $tplRanges that are non-overlapping.
 

Protected Member Functions

 matchMetaType (Element $elem)
 Returns the meta type of the element if it exists and matches the type expected by the current class, null otherwise.
 
 verifyTplInfoExpectation (?TemplateInfo $templateInfo, TempData $tmp)
 
 getRangeId (Element $node)
 Returns the range ID of a node - in the case of annotations, the "rangeId" property of its "data-mw" attribute.
 
 updateDSRForFirstRangeNode (Element $target, Element $source)
 
- Protected Member Functions inherited from Wikimedia\Parsoid\Wt2Html\DOM\Processors\DOMRangeBuilder
 getStartConsideringFosteredContent (Node $node)
 Returns the current node if it's not just after fostered content, the first node of fostered content otherwise.
 
 findWrappableMetaRanges (Node $rootNode)
 Recursively walk the DOM tree.
 
 findEnclosingRange (Element $startMeta, Element $endMeta, ?Element $endElem=null)
 Creates a range that encloses $startMeta and $endMeta.
 

Additional Inherited Members

- Protected Attributes inherited from Wikimedia\Parsoid\Wt2Html\DOM\Processors\DOMRangeBuilder
 $env
 
 $nodeRanges
 
 $traceType
 

Detailed Description

The handling of annotation ranges and transclusion ranges are somewhat different for a number of reasons.

  • Annotation ranges can be (and typically are) nested: we want to handle a <tvar> range inside a <translate> range (whereas non-top-level transclusions are ignored). That said, this only applies to annotations of different types, so finding/handling top-level ranges of a given type is useful (hence extending the DOMRangeBuilder, still.)
  • Annotation ranges are not represented in the final document in the same way as transclusions. In an ideal world, annotations are well-nested and the corresponding range is not extended; in this case, the annotation range is only delimited by a pair of <meta> tags (that can then be displayed by VE, or ignored by read-views). The annotated content stays editable; whereas editing of templated content is always prevented.
  • Relatedly: annotation meta tags are NOT removed from the output (whereas transclusion meta tags are an intermediary state). This has an impact on fostering. It is safe to bypass the fostering of meta tags in the template case, because the meta tags will disappear anyway, and their presence in a fostering position only marks the whole table as template content. Annotation tags do not benefit from the same leeway: they will need to be moved in the right place (and, for end tags, "the right place" means the end of the table, not the start of the table - which we can handle more consistently if the meta tag ends up in the FosterBox). Hence, there is little reason to not use the general fostering pass for annotation meta tags as well (except for the consistency with transclusion meta tags).

The assumptions here are consequently as follows:

  • annotation <meta> tags are not in a fosterable position (they have been moved out of it in the TreeBuilderStage)
  • during the MarkFosteredContent pass, end annotation meta tags are moved from the foster box to after the table. This should guarantee that no range is reversed (so that's a case we do not have to worry about).

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Parsoid\Wt2Html\DOM\Processors\AnnotationDOMRangeBuilder::__construct ( Document $document,
Frame $frame )

AnnotationDOMRangeBuilder constructor.

Parameters
Document$document
Frame$frame

Reimplemented from Wikimedia\Parsoid\Wt2Html\DOM\Processors\DOMRangeBuilder.

Member Function Documentation

◆ execute()

Wikimedia\Parsoid\Wt2Html\DOM\Processors\AnnotationDOMRangeBuilder::execute ( Node $root)

◆ getRangeId()

Wikimedia\Parsoid\Wt2Html\DOM\Processors\AnnotationDOMRangeBuilder::getRangeId ( Element $node)
protected

Returns the range ID of a node - in the case of annotations, the "rangeId" property of its "data-mw" attribute.

Parameters
Element$node
Returns
string

Reimplemented from Wikimedia\Parsoid\Wt2Html\DOM\Processors\DOMRangeBuilder.

◆ matchMetaType()

Wikimedia\Parsoid\Wt2Html\DOM\Processors\AnnotationDOMRangeBuilder::matchMetaType ( Element $elem)
protected

Returns the meta type of the element if it exists and matches the type expected by the current class, null otherwise.

Parameters
Element$elemthe element to check
Returns
string|null

Reimplemented from Wikimedia\Parsoid\Wt2Html\DOM\Processors\DOMRangeBuilder.

◆ updateDSRForFirstRangeNode()

Wikimedia\Parsoid\Wt2Html\DOM\Processors\AnnotationDOMRangeBuilder::updateDSRForFirstRangeNode ( Element $target,
Element $source )
protected

◆ verifyTplInfoExpectation()

Wikimedia\Parsoid\Wt2Html\DOM\Processors\AnnotationDOMRangeBuilder::verifyTplInfoExpectation ( ?TemplateInfo $templateInfo,
TempData $tmp )
protected

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