Parsoid
A bidirectional parser between wikitext and HTML5
Loading...
Searching...
No Matches
Wikimedia\Parsoid\Wt2Html\PP\Handlers\TableFixups Class Reference

Provides DOMTraverser visitors that fix template-induced interrupted table cell parsing by recombining table cells and/or reparsing table cell content as attributes. More...

Public Member Functions

 __construct (Env $env)
 
 stripDoubleTDs (Element $node, Frame $frame)
 DOM visitor that strips the double td for this test case:
 
 reparseTemplatedAttributes (Frame $frame, Element $cell, ?Element $templateWrapper)
 T46498, second part of T52603.
 

Detailed Description

Provides DOMTraverser visitors that fix template-induced interrupted table cell parsing by recombining table cells and/or reparsing table cell content as attributes.

  • stripDoubleTDs
  • handleTableCellTemplates

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Parsoid\Wt2Html\PP\Handlers\TableFixups::__construct ( Env  $env)

Set up some helper objects for reparseTemplatedAttributes

Actually the regular tokenizer, but we'll use tokenizeTableCellAttributes only.

Member Function Documentation

◆ reparseTemplatedAttributes()

Wikimedia\Parsoid\Wt2Html\PP\Handlers\TableFixups::reparseTemplatedAttributes ( Frame  $frame,
Element  $cell,
?Element  $templateWrapper 
)

T46498, second part of T52603.

Handle wikitext like

{|
|{{nom|Bar}}
|}

where nom expands to style="foo" class="bar"|Bar. The attributes are tokenized and stripped from the table contents.

This method works well for the templates documented in https://en.wikipedia.org/wiki/Template:Table_cell_templates/doc

Nevertheless, there are some limitations:

  • We assume that attributes don't contain wiki markup (apart from <nowiki>) and end up in text or nowiki nodes.
  • Only a single table cell is produced / opened by the template that contains the attributes. This limitation could be lifted with more aggressive re-parsing if really needed in practice.
  • There is only a single transclusion in the table cell content. This limitation can be lifted with more advanced data-mw construction.
Parameters
Frame$frame
Element$cellknown to be

/

Parameters
?Element$templateWrapper

FIXME: These checks are insufficient. Previous rounds of table fixups might have created this cell without any templated content (the while loop in handleTableCellTemplates). Till we figure out a reliable test for this, we'll reparse attributes always.

// This DOM pass is trying to bridge broken parses across // template boundaries. so, if templates aren't involved, // no reason to reparse. if ( count( $attributishContent['transclusions'] ) === 0 && !WTUtils::fromEncapsulatedContent( $cell ) ) { return; }

◆ stripDoubleTDs()

Wikimedia\Parsoid\Wt2Html\PP\Handlers\TableFixups::stripDoubleTDs ( Element  $node,
Frame  $frame 
)

DOM visitor that strips the double td for this test case:

|{{1x|{{!}} Foo}}
See also
https://phabricator.wikimedia.org/T52603
Parameters
Element$node
Frame$frame
Returns
bool|Node

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