jenkins-bot has submitted this change and it was merged.

Change subject: Updated migrateStartMetas to handle migrate both start/end metas
......................................................................


Updated migrateStartMetas to handle migrate both start/end metas

* As a mirror transformation to migrateStartMetas, migrate
  template marker end-metas that are last-children to their
  parent's sibling. This has the same benefit as the former
  transformation of more accurately bounding template-generated
  content.

* One selser test fails -- but arguably, a better result given that
  the parse output is a bit broken on this test case.

Change-Id: I5ca7caf5124acd91be8c6f1d4308f85e3f5daf4f
---
D js/lib/dom.migrateStartMetas.js
A js/lib/dom.migrateTemplateMarkerMetas.js
M js/lib/mediawiki.DOMPostProcessor.js
M js/tests/parserTests-blacklist.js
4 files changed, 64 insertions(+), 40 deletions(-)

Approvals:
  GWicke: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/js/lib/dom.migrateStartMetas.js b/js/lib/dom.migrateStartMetas.js
deleted file mode 100644
index 6d90cf6..0000000
--- a/js/lib/dom.migrateStartMetas.js
+++ /dev/null
@@ -1,38 +0,0 @@
-"use strict";
-
-var DU = require('./mediawiki.DOMUtils.js').DOMUtils,
-       Consts = require('./mediawiki.wikitext.constants.js').WikitextConstants;
-
-// If the last child of a node is a start-meta, simply
-// move it up and make it the parent's sibling.
-// This will move the start-meta closest to the content
-// that the template/extension produced and improve accuracy
-// of finding dom ranges and wrapping templates.
-function migrateStartMetas( node, env ) {
-       var c = node.firstChild;
-       while (c) {
-               var sibling = c.nextSibling;
-               if (c.childNodes.length > 0) {
-                       migrateStartMetas(c, env);
-               }
-               c = sibling;
-       }
-
-       if (node.nodeName !== 'HTML') {
-               var lastChild = node.lastChild;
-               if (lastChild && DU.isTplStartMarkerMeta(lastChild)) {
-                       // console.warn("migration: " + lastChild.outerHTML);
-
-                       // We can migrate the meta-tag across this node's 
end-tag barrier only
-                       // if that end-tag is zero-width.
-                       var tagWidth = 
Consts.WT_TagWidths[node.nodeName.toLowerCase()];
-                       if (tagWidth && tagWidth[1] === 0 && 
!DU.isLiteralHTMLNode(node)) {
-                               node.parentNode.insertBefore(lastChild, 
node.nextSibling);
-                       }
-               }
-       }
-}
-
-if (typeof module === "object") {
-       module.exports.migrateStartMetas = migrateStartMetas;
-}
diff --git a/js/lib/dom.migrateTemplateMarkerMetas.js 
b/js/lib/dom.migrateTemplateMarkerMetas.js
new file mode 100644
index 0000000..c93c8c0
--- /dev/null
+++ b/js/lib/dom.migrateTemplateMarkerMetas.js
@@ -0,0 +1,58 @@
+"use strict";
+
+var DU = require('./mediawiki.DOMUtils.js').DOMUtils,
+       Consts = require('./mediawiki.wikitext.constants.js').WikitextConstants;
+
+/* -----------------------------------------------------------
+ * This will move the start/end-meta closest to the content
+ * that the template/extension produced and improve accuracy
+ * of finding dom ranges and wrapping templates.
+ *
+ * If the last child of a node is a start-meta,
+ * move it up and make it the parent's right sibling.
+ *
+ * If the first child of a node is an end-meta,
+ * move it up and make it the parent's left sibling.
+ * ----------------------------------------------------------- */
+function migrateTemplateMarkerMetas( node, env ) {
+       var tagWidth;
+
+       var c = node.firstChild;
+       while (c) {
+               var sibling = c.nextSibling;
+               if (c.childNodes.length > 0) {
+                       migrateTemplateMarkerMetas(c, env);
+               }
+               c = sibling;
+       }
+
+       if (node.nodeName !== 'HTML') {
+               var firstChild = node.firstChild;
+               if (firstChild && DU.isTplEndMarkerMeta(firstChild)) {
+                       // console.warn("migration: " + firstChild.outerHTML);
+
+                       // We can migrate the meta-tag across this node's 
end-tag barrier only
+                       // if that end-tag is zero-width.
+                       tagWidth = 
Consts.WT_TagWidths[node.nodeName.toLowerCase()];
+                       if (tagWidth && tagWidth[0] === 0 && 
!DU.isLiteralHTMLNode(node)) {
+                               node.parentNode.insertBefore(firstChild, node);
+                       }
+               }
+
+               var lastChild = node.lastChild;
+               if (lastChild && DU.isTplStartMarkerMeta(lastChild)) {
+                       // console.warn("migration: " + lastChild.outerHTML);
+
+                       // We can migrate the meta-tag across this node's 
end-tag barrier only
+                       // if that end-tag is zero-width.
+                       tagWidth = 
Consts.WT_TagWidths[node.nodeName.toLowerCase()];
+                       if (tagWidth && tagWidth[1] === 0 && 
!DU.isLiteralHTMLNode(node)) {
+                               node.parentNode.insertBefore(lastChild, 
node.nextSibling);
+                       }
+               }
+       }
+}
+
+if (typeof module === "object") {
+       module.exports.migrateTemplateMarkerMetas = migrateTemplateMarkerMetas;
+}
diff --git a/js/lib/mediawiki.DOMPostProcessor.js 
b/js/lib/mediawiki.DOMPostProcessor.js
index ca3293b..079b247 100644
--- a/js/lib/mediawiki.DOMPostProcessor.js
+++ b/js/lib/mediawiki.DOMPostProcessor.js
@@ -19,7 +19,7 @@
        handleUnbalancedTables = 
require('./dom.handleUnbalancedTables.js').handleUnbalancedTables,
        markFosteredContent = 
require('./dom.markFosteredContent.js').markFosteredContent,
        markTreeBuilderFixups = 
require('./dom.markTreeBuilderFixups.js').markTreeBuilderFixups,
-       migrateStartMetas = 
require('./dom.migrateStartMetas.js').migrateStartMetas,
+       migrateTemplateMarkerMetas = 
require('./dom.migrateTemplateMarkerMetas.js').migrateTemplateMarkerMetas,
        migrateTrailingNLs = 
require('./dom.migrateTrailingNLs.js').migrateTrailingNLs,
        TableFixups = require('./dom.t.TableFixups.js'),
        stripMarkerMetas = CleanUp.stripMarkerMetas,
@@ -150,7 +150,10 @@
                markFosteredContent,
                handleUnbalancedTables,
                markTreeBuilderFixups,
-               migrateStartMetas,
+               // Run this after 'markTreeBuilderFixups' because the 
mw:StartTag
+               // and mw:EndTag metas would otherwise interfere with the
+               // firstChild/lastChild check that this pass does.
+               migrateTemplateMarkerMetas,
                handlePres,
                migrateTrailingNLs
        ];
diff --git a/js/tests/parserTests-blacklist.js 
b/js/tests/parserTests-blacklist.js
index 76903f3..c396ec7 100644
--- a/js/tests/parserTests-blacklist.js
+++ b/js/tests/parserTests-blacklist.js
@@ -2997,6 +2997,7 @@
 add("selser", "Nested lists 7 (skip initial nesting levels) [[[[[2]]]]]", 
"**9q6447gwwogh9f6r\n* foo");
 add("selser", "Nested lists 7 (skip initial nesting levels) [[[2]]]", 
"*tg28w4nd7g0kke29\n** foo");
 add("selser", "Nested lists 7 (skip initial nesting levels) [[[[[1]]]]]", "* 
foo");
+add("selser", "2. Lists with start-of-line-transparent tokens before bullets: 
Template close [0,0,2]", "*foo {{echo|bar\n}}9uqf8ew08p2b7qfr\n*baz");
 add("selser", "List interrupted by empty line or heading [[1],0,[1],2,3,0,0]", 
"* foo\n\n* bar\n\n* Another list item");
 add("selser", "List interrupted by empty line or heading 
[[[4]],4,[[1]],0,[3],2,2]", "* foo\n\n* bar\n== A heading 
==\n1xzetsjere75jyvi\n* Another list item");
 add("selser", "Test the li-hack\n(Cannot test this with PHP parser since it 
relies on Tidy for the hack) [1,2,[3,2,[3],0]]", "* foo\n* <li>li-hack\n* 
{{echo|<li>templated li-hack}}\n* <!--foo--> <li> unsupported li-hack with 
preceding comments\n\n<ul>\n6gpem64rni3yds4i<li><li>not a 
li-hack\n</li>\n</ul>");

-- 
To view, visit https://gerrit.wikimedia.org/r/91631
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I5ca7caf5124acd91be8c6f1d4308f85e3f5daf4f
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to