Skip to content

Commit dadc4b7

Browse files
committed
(Bug 63642): Cleanup treebuilder fixup of formatting elts.
* 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
1 parent c86ce0a commit dadc4b7

4 files changed

Lines changed: 76 additions & 2 deletions

File tree

lib/dom.markTreeBuilderFixups.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ function findAutoInsertedTags(env, node) {
164164
sibling, expectedName, reg;
165165

166166
while (c !== null) {
167-
168167
// Skip over template/extension content
169168
if (DU.isTplElementNode( env, node )) {
170169
var about = node.getAttribute( 'about' );
@@ -267,9 +266,41 @@ function findAutoInsertedTags(env, node) {
267266
}
268267
}
269268

269+
function cleanupFormattingTagFixup(env, node) {
270+
node = node.firstChild;
271+
while (node !== null) {
272+
if (DU.isGeneratedFigure(node)) {
273+
var c = node.firstChild;
274+
// <a> tags are formatting elts as well
275+
if (DU.isFormattingElt(c) && !DU.hasNodeName(c, "a") && !c.nextSibling) {
276+
// Fix up DOM appropriately
277+
var fig = node;
278+
var formattingElt = c;
279+
DU.migrateChildren(formattingElt, fig);
280+
var caption = fig.lastChild;
281+
DU.migrateChildren(caption, formattingElt);
282+
caption.appendChild(formattingElt);
283+
284+
// If both the start and end tags are auto-inserted,
285+
// DSR algo will automatically ignore the tag.
286+
// Otherwise, TSR needs clearing. However,
287+
// for simpler logic and code readability reasons,
288+
// we are unconditionally clearing it out.
289+
DU.getDataParsoid(formattingElt).tsr = null;
290+
}
291+
} else if (DU.isElt(node)) {
292+
cleanupFormattingTagFixup(env, node);
293+
}
294+
node = node.nextSibling;
295+
}
296+
}
297+
270298
function markTreeBuilderFixups(body, env) {
271299
findAutoInsertedTags(env, body);
272300
findDeletedStartTags(env, body);
301+
302+
// Bug 63642 and friend
303+
cleanupFormattingTagFixup(env, body);
273304
}
274305

275306
if (typeof module === "object") {

lib/mediawiki.DOMUtils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,10 @@ DOMUtils = DU = {
566566
return this.isList(n) || this.isListItem(n);
567567
},
568568

569+
isGeneratedFigure: function(n) {
570+
return this.isElt(n) && (/(^|\s)mw:Image(\s|$)/).test(n.getAttribute("typeof"));
571+
},
572+
569573
/**
570574
* Get the first preceding sibling of 'node' that is an element,
571575
* or return `null` if there is no such sibling element.

tests/parserTests-blacklist.js

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/parserTests.txt

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18038,7 +18038,7 @@ Lead
1803818038

1803918039

1804018040
###
18041-
### Parsoids-specific tests
18041+
### Parsoid-specific tests
1804218042
### Parsoid-PHP parser incompatibilities
1804318043
###
1804418044
!!test
@@ -18061,6 +18061,35 @@ parsoid=wt2html,wt2wt
1806118061
</dl>
1806218062
!!end
1806318063

18064+
#### -----------------------------------------------------------------
18065+
#### Parsoid-specific functionality tests
18066+
#### -----------------------------------------------------------------
18067+
18068+
# Bug 63642: Formatting elt fixup is cleaned up.
18069+
# We know wt2wt will fail, but we expect selser to pass.
18070+
# Due to the nature of our testing, wt2wt and selser tests will enter the
18071+
# blacklist and we'll catch selser regressions based on changes to the
18072+
# blacklist entries for selser tests.
18073+
!! test
18074+
Bad treebuilder fixup of formatting elt is cleaned up
18075+
!! options
18076+
parsoid=wt2html,wt2wt
18077+
!! wikitext
18078+
{|
18079+
|
18080+
<small>
18081+
[[Image:Foobar.jpg|right|Test]]
18082+
</small>
18083+
|}
18084+
!! html/parsoid
18085+
<table>
18086+
<tbody><tr><td>
18087+
<p><small></small></p>
18088+
<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>
18089+
<p></p></td></tr>
18090+
</tbody></table>
18091+
!! end
18092+
1806418093
#### ----------------------------------------------------------------
1806518094
#### Parsoid-only testing of Parsoid's impl of <ref> and <references>
1806618095
#### tags. Parsoid's output for these tags differs from that of the

0 commit comments

Comments
 (0)