Cscott has uploaded a new change for review.
https://gerrit.wikimedia.org/r/245603
Change subject: Disable migrateTrailingNLs if table has had content fostered
out of it
......................................................................
Disable migrateTrailingNLs if table has had content fostered out of it
Test cases:
$ echo '<table><td></td><tr><!--c1-->[[Category:Foo]]<!--c2-->'| tests/parse.js
We want to ensure that the two comments stay inside the <tr>, because:
$ echo
'<table><td></td>{{echo|<tr>[[Category:Foo]]}}<!--c-->[[Category:Bar]]<!--c-->'
...here the <tr> is a template boundary, and... FIX THIS DESCRIPTION.
Change-Id: I0047a5e7ccb067b7e40d04d280bafb862abcfba5
---
M lib/dom.migrateTrailingNLs.js
M tests/parserTests-blacklist.js
M tests/parserTests.txt
3 files changed, 22 insertions(+), 6 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/03/245603/1
diff --git a/lib/dom.migrateTrailingNLs.js b/lib/dom.migrateTrailingNLs.js
index ff691aa..3eb509f 100644
--- a/lib/dom.migrateTrailingNLs.js
+++ b/lib/dom.migrateTrailingNLs.js
@@ -18,6 +18,15 @@
return nodesToMigrateFrom.has(node.nodeName) &&
!DU.isLiteralHTMLNode(node);
}
+function getTableParent(node) {
+ if (!node) { return null; }
+ if (/^(TD|TH)$/.test(node.nodeName)) { node = node.parentNode; }
+ if (node.nodeName === 'TR') { node = node.parentNode; }
+ if (/^(TBODY|THEAD|TFOOT|CAPTION)$/.test(node.nodeName)) { node =
node.parentNode; }
+ if (node.nodeName === 'TABLE') { return node; }
+ return null;
+}
+
function migrateTrailingNLs(elt, env) {
// We can migrate a newline out of a node if one of the following is
true:
// (1) The node ends a line in wikitext (=> not a literal html tag)
@@ -26,7 +35,16 @@
// (3) It is the rightmost node in the DOM subtree rooted at a node
// that ends a line in wikitext
function canMigrateNLOutOfNode(node) {
- return node && (node.nodeName !== "HTML") && (
+ // Don't allow migration out of a table if the table has had
+ // content fostered out of it.
+ var tableParent = getTableParent(node);
+ if (tableParent && DU.isElt(tableParent.previousSibling) &&
+
DU.getDataParsoid(tableParent.previousSibling).fostered) {
+ return false;
+ }
+ return node &&
+ (node.nodeName !== "HTML") &&
+ (node.nodeName !== "TABLE") && (
nodeEndsLineInWT(node) ||
(DU.isElt(node) &&
DU.getDataParsoid(node).autoInsertedEnd &&
diff --git a/tests/parserTests-blacklist.js b/tests/parserTests-blacklist.js
index dbfd93d..bdfd9c0 100644
--- a/tests/parserTests-blacklist.js
+++ b/tests/parserTests-blacklist.js
@@ -412,7 +412,6 @@
add("wt2wt", "Empty TD followed by TD with tpl-generated attribute",
"{|\n|-\n|\n| {{echo|style='color:red'}} |foo\n|}");
add("wt2wt", "Improperly nested inline or quotes tags with whitespace in
between", "<span> <s>x</span> </s>\n''' ''x'''''<nowiki/>'' ''\n");
add("wt2wt", "2. Ensure fostered text content is wrapped in element nodes
(traps regressions around fostered marker on the element getting lost)",
"<nowiki> </nowiki><nowiki>||</nowiki> <nowiki>||</nowiki>\n<table>\n<tr><td>
a\n</table>");
-add("wt2wt", "Table in fosterable position", "{{OpenTable}}\n<div>\n{|\n|}\n");
add("wt2wt", "Image: upright option is ignored on inline and frame images
(parsoid)", "[[File:Foobar.jpg|500x500px|caption]]\n");
@@ -438,7 +437,7 @@
add("html2html", "Definition lists: colon in HTML attribute", "<dl
data-parsoid='{\"dsr\":[0,12,0,0]}'><dt data-parsoid='{\"dsr\":[0,12,1,0]}'> <b
data-parsoid='{\"dsr\":[2,12,3,3]}'>bold</b></dt></dl>\n");
add("html2html", "Definition Lists: Nesting: Multi-level (Parsoid only)",
"\n<dl data-parsoid='{\"dsr\":[1,116,0,0]}'><dt
data-parsoid='{\"dsr\":[1,6,1,0]}'> t1 </dt>\n<dd
data-parsoid='{\"dsr\":[7,17,1,0]}'> d1 </dd>\n<dt
data-parsoid='{\"dsr\":[18,116,1,0]}'><dl
data-parsoid='{\"dsr\":[19,116,0,0]}'><dt data-parsoid='{\"dsr\":[19,24,1,0]}'>
t2 </dt>\n<dd data-parsoid='{\"dsr\":[25,62,2,0]}'> <span typeof=\"mw:Nowiki\"
data-parsoid='{\"dsr\":[28,48,8,9]}'>:d2</span> </dd>\n<dt
data-parsoid='{\"dsr\":[63,116,2,0]}'><dl
data-parsoid='{\"dsr\":[65,116,0,0]}'><dt data-parsoid='{\"dsr\":[65,70,1,0]}'>
t3 </dt>\n<dd data-parsoid='{\"dsr\":[71,116,3,0]}'> <span typeof=\"mw:Nowiki\"
data-parsoid='{\"dsr\":[75,96,8,9]}'>::d3</span>
</dd></dl></dt></dl></dt></dl>\n");
add("html2html", "Definition Lists: colons and tables 1", "<dl
data-parsoid='{\"dsr\":[0,26,0,0]}'><dd data-parsoid='{\"dsr\":[0,12,1,0]}'>
<table data-parsoid='{\"dsr\":[2,12,2,2]}'>\n\n<tbody
data-parsoid='{\"dsr\":[6,10,0,0]}'><tr
data-parsoid='{\"autoInsertedEnd\":true,\"autoInsertedStart\":true,\"dsr\":[6,9,0,0]}'><td
data-parsoid='{\"autoInsertedEnd\":true,\"dsr\":[6,9,1,0]}'>
x</td></tr>\n</tbody></table></dd>\n\n<dd data-parsoid='{\"dsr\":[14,26,1,0]}'>
<table data-parsoid='{\"dsr\":[16,26,2,2]}'>\n\n<tbody
data-parsoid='{\"dsr\":[20,24,0,0]}'><tr
data-parsoid='{\"autoInsertedEnd\":true,\"autoInsertedStart\":true,\"dsr\":[20,23,0,0]}'><td
data-parsoid='{\"autoInsertedEnd\":true,\"dsr\":[20,23,1,0]}'>
y</td></tr>\n</tbody></table></dd></dl>\n");
-add("html2html", "Indented table markup mixed with indented pre content
(proposed in bug 6200)", " <table
data-parsoid='{\"autoInsertedEnd\":true,\"dsr\":[1,58,2,0]}'>\n \n <tbody
data-parsoid='{\"dsr\":[7,58,0,0]}'><tr
data-parsoid='{\"autoInsertedEnd\":true,\"autoInsertedStart\":true,\"dsr\":[7,58,0,0]}'><td
data-parsoid='{\"autoInsertedEnd\":true,\"dsr\":[7,58,1,0]}'>\n<pre
data-parsoid='{\"dsr\":[9,58,1,0]}'>Text that should be rendered preformatted
\n\n|}</pre></td></tr></tbody></table>\n");
+add("html2html", "Indented table markup mixed with indented pre content
(proposed in bug 6200)", " <table
data-parsoid='{\"autoInsertedEnd\":true,\"dsr\":[1,59,2,0]}'>\n \n <tbody
data-parsoid='{\"dsr\":[7,59,0,0]}'><tr
data-parsoid='{\"autoInsertedEnd\":true,\"autoInsertedStart\":true,\"dsr\":[7,58,0,0]}'><td
data-parsoid='{\"autoInsertedEnd\":true,\"dsr\":[7,58,1,0]}'>\n<pre
data-parsoid='{\"dsr\":[9,58,1,0]}'>Text that should be rendered preformatted
\n\n|}</pre></td></tr>\n</tbody></table>");
add("html2html", "Build table with wikilink", "<table class=\"wikitable\"
data-parsoid='{\"dsr\":[0,216,20,2]}'>\n\n<tbody
data-parsoid='{\"dsr\":[22,214,0,0]}'><tr
data-parsoid='{\"autoInsertedEnd\":true,\"autoInsertedStart\":true,\"dsr\":[22,47,0,0]}'><th
data-parsoid='{\"autoInsertedEnd\":true,\"dsr\":[22,31,1,0]}'> header
</th>\n<th data-parsoid='{\"autoInsertedEnd\":true,\"dsr\":[32,47,1,0]}'>
second header</th></tr>\n\n<tr style=\"color:red;\"
data-parsoid='{\"startTagSrc\":\"|-\",\"autoInsertedEnd\":true,\"dsr\":[49,148,21,0]}'>\n<td
data-parsoid='{\"autoInsertedEnd\":true,\"dsr\":[71,106,1,0]}'> data <a
rel=\"mw:WikiLink\" href=\"./Wiki/Main_Page\" title=\"Wiki/Main Page\"
data-parsoid='{\"stx\":\"piped\",\"a\":{\"href\":\"./Wiki/Main_Page\"},\"sa\":{\"href\":\"wiki/Main
Page\"},\"dsr\":[78,105,17,2]}'>linktext</a> </td>\n<td
data-parsoid='{\"autoInsertedEnd\":true,\"dsr\":[107,148,1,0]}'> second data <a
rel=\"mw:WikiLink\" href=\"./Wiki/Main_Page\" title=\"Wiki/Main Page\"
data-parsoid='{\"stx\":\"piped\",\"a\":{\"href\":\"./Wiki/Main_Page\"},\"sa\":{\"href\":\"wiki/Main
Page\"},\"dsr\":[121,148,17,2]}'>linktext</a></td></tr>\n\n<tr
data-parsoid='{\"startTagSrc\":\"|-\",\"autoInsertedEnd\":true,\"dsr\":[150,213,2,0]}'>\n<td
data-parsoid='{\"autoInsertedEnd\":true,\"dsr\":[153,160,1,0]}'> data
</td>\n<td data-parsoid='{\"autoInsertedEnd\":true,\"dsr\":[161,213,1,0]}'>
second data <a rel=\"mw:WikiLink\" href=\"./Wiki/Main_Page\" title=\"Wiki/Main
Page\"
data-parsoid='{\"stx\":\"piped\",\"a\":{\"href\":\"./Wiki/Main_Page\"},\"sa\":{\"href\":\"wiki/Main
Page\"},\"dsr\":[175,213,17,2]}'>link|text with
pipe</a></td></tr>\n</tbody></table>\n");
add("html2html", "Plain link, capitalized", "<p
data-parsoid='{\"dsr\":[0,28,0,0]}'><a rel=\"mw:WikiLink\"
href=\"./Wiki/Main_Page\" title=\"Wiki/Main Page\"
data-parsoid='{\"stx\":\"piped\",\"a\":{\"href\":\"./Wiki/Main_Page\"},\"sa\":{\"href\":\"wiki/Main
Page\"},\"dsr\":[0,28,17,2]}'>Main Page</a></p>\n");
add("html2html", "Plain link, uncapitalized", "<p
data-parsoid='{\"dsr\":[0,28,0,0]}'><a rel=\"mw:WikiLink\"
href=\"./Wiki/Main_Page\" title=\"Wiki/Main Page\"
data-parsoid='{\"stx\":\"piped\",\"a\":{\"href\":\"./Wiki/Main_Page\"},\"sa\":{\"href\":\"wiki/Main
Page\"},\"dsr\":[0,28,17,2]}'>main Page</a></p>\n");
@@ -2422,7 +2421,6 @@
add("selser", "2. Ensure fostered text content is wrapped in element nodes
(traps regressions around fostered marker on the element getting lost)
[2,0,[0,3]]", "z8xg0t8oxy8k6gvi\n\n\n<table></table>");
add("selser", "2. Ensure fostered text content is wrapped in element nodes
(traps regressions around fostered marker on the element getting lost)
[2,2,[2,[3,2]]]",
"4p9b5ylwp6gpsyvi\n\n\n\n52u735k3ah96n7b9\n<table><!--u4n4phdgngffxbt9-->\n<!--ox538fcmtef2bj4i-->\n</table>");
add("selser", "2. Ensure fostered text content is wrapped in element nodes
(traps regressions around fostered marker on the element getting lost)
[3,4,[2,0]]", "r04d5cr392cpu8fr<table><!--nkka2k3hiqode7b9-->\n<tr> || ||\n<td>
a\n</table>");
-add("selser", "Table in fosterable position 5",
"{{OpenTable}}\n<div>\n{|\n|}\n");
add("selser", "Image: upright option is ignored on inline and frame images
(parsoid) [1]", "[[File:Foobar.jpg|500x500px|upright=0.5|caption]]");
add("selser", "Image: upright option is ignored on inline and frame images
(parsoid) [2]",
"kywu2qkfz9eh4cxr\n\n[[File:Foobar.jpg|500x500px|upright=0.5|caption]]");
add("selser", "Normalizations should be restricted to edited content
[0,4,0,3,0]", "a\n\n2hqj9fdsvwpnwmi\n\n= =\nb");
diff --git a/tests/parserTests.txt b/tests/parserTests.txt
index 5789cc7..129b41b 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -24369,7 +24369,7 @@
!!test
Table in fosterable position
!!options
-parsoid=wt2html,wt2wt
+parsoid=wt2html
!! wikitext
{{OpenTable}}
<div>
@@ -24378,7 +24378,7 @@
</div>
|}
!! html/parsoid
-<div about="#mwt1" typeof="mw:Transclusion"
data-mw='{"parts":[{"template":{"target":{"wt":"OpenTable","href":"./Template:OpenTable"},"params":{},"i":0}},"\n<div>"]}'
data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[]]}'></div><span
about="#mwt1">
+<div about="#mwt1" typeof="mw:Transclusion"
data-mw='{"parts":[{"template":{"target":{"wt":"OpenTable","href":"./Template:OpenTable"},"params":{},"i":0}},"\n<div>\n"]}'
data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[]]}'></div><span
about="#mwt1">
</span>
<table about="#mwt1" data-parsoid='{"autoInsertedEnd":true}'></table>
--
To view, visit https://gerrit.wikimedia.org/r/245603
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0047a5e7ccb067b7e40d04d280bafb862abcfba5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits