Skip to content

Commit

Permalink
(Bug 63642): Cleanup treebuilder fixup of formatting elts.
Browse files Browse the repository at this point in the history
* First pass refixing treebuilder-fixed DOM where formatting elts
  (<small>, <b>, etc.) wrap <figures> inside tables. This patch
  moves the formatting elt inside the caption.

* Added a test snippet that is tested in wt2html, wt2wt, and
  selser modes. wt2wt will always fail, but will enable selser
  tests (which if passing will get blacklisted since results
  will differ from wt2wt) and will let us catch regressions in
  those results.

Change-Id: Idaaf46565ad277289b84a4711da38ee79f2d483f
  • Loading branch information
subbuss committed May 1, 2014
1 parent c86ce0a commit dadc4b7
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
33 changes: 32 additions & 1 deletion lib/dom.markTreeBuilderFixups.js
Expand Up @@ -164,7 +164,6 @@ function findAutoInsertedTags(env, node) {
sibling, expectedName, reg;

while (c !== null) {

// Skip over template/extension content
if (DU.isTplElementNode( env, node )) {
var about = node.getAttribute( 'about' );
Expand Down Expand Up @@ -267,9 +266,41 @@ function findAutoInsertedTags(env, node) {
}
}

function cleanupFormattingTagFixup(env, node) {
node = node.firstChild;
while (node !== null) {
if (DU.isGeneratedFigure(node)) {
var c = node.firstChild;
// <a> tags are formatting elts as well
if (DU.isFormattingElt(c) && !DU.hasNodeName(c, "a") && !c.nextSibling) {
// Fix up DOM appropriately
var fig = node;
var formattingElt = c;
DU.migrateChildren(formattingElt, fig);
var caption = fig.lastChild;
DU.migrateChildren(caption, formattingElt);
caption.appendChild(formattingElt);

// If both the start and end tags are auto-inserted,
// DSR algo will automatically ignore the tag.
// Otherwise, TSR needs clearing. However,
// for simpler logic and code readability reasons,
// we are unconditionally clearing it out.
DU.getDataParsoid(formattingElt).tsr = null;
}
} else if (DU.isElt(node)) {
cleanupFormattingTagFixup(env, node);
}
node = node.nextSibling;
}
}

function markTreeBuilderFixups(body, env) {
findAutoInsertedTags(env, body);
findDeletedStartTags(env, body);

// Bug 63642 and friend
cleanupFormattingTagFixup(env, body);
}

if (typeof module === "object") {
Expand Down
4 changes: 4 additions & 0 deletions lib/mediawiki.DOMUtils.js
Expand Up @@ -566,6 +566,10 @@ DOMUtils = DU = {
return this.isList(n) || this.isListItem(n);
},

isGeneratedFigure: function(n) {
return this.isElt(n) && (/(^|\s)mw:Image(\s|$)/).test(n.getAttribute("typeof"));
},

/**
* Get the first preceding sibling of 'node' that is an element,
* or return `null` if there is no such sibling element.
Expand Down
10 changes: 10 additions & 0 deletions tests/parserTests-blacklist.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 30 additions & 1 deletion tests/parserTests.txt
Expand Up @@ -18038,7 +18038,7 @@ Lead


###
### Parsoids-specific tests
### Parsoid-specific tests
### Parsoid-PHP parser incompatibilities
###
!!test
Expand All @@ -18061,6 +18061,35 @@ parsoid=wt2html,wt2wt
</dl>
!!end

#### -----------------------------------------------------------------
#### Parsoid-specific functionality tests
#### -----------------------------------------------------------------

# Bug 63642: Formatting elt fixup is cleaned up.
# We know wt2wt will fail, but we expect selser to pass.
# Due to the nature of our testing, wt2wt and selser tests will enter the
# blacklist and we'll catch selser regressions based on changes to the
# blacklist entries for selser tests.
!! test
Bad treebuilder fixup of formatting elt is cleaned up
!! options
parsoid=wt2html,wt2wt
!! wikitext
{|
|
<small>
[[Image:Foobar.jpg|right|Test]]
</small>
|}
!! html/parsoid
<table>
<tbody><tr><td>
<p><small></small></p>
<figure class="mw-default-size mw-halign-right" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" height="220" width="1941"></a><figcaption><small>Test</small></figcaption></figure>
<p></p></td></tr>
</tbody></table>
!! end

#### ----------------------------------------------------------------
#### Parsoid-only testing of Parsoid's impl of <ref> and <references>
#### tags. Parsoid's output for these tags differs from that of the
Expand Down

0 comments on commit dadc4b7

Please sign in to comment.