Subramanya Sastry has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/302860

Change subject: migrateTrailingNLs: Move nested functions to the top level
......................................................................

migrateTrailingNLs: Move nested functions to the top level

Change-Id: Ib23d50294b2c2d1307365fd2405091c94533cd0c
---
M lib/wt2html/pp/processors/migrateTrailingNLs.js
1 file changed, 42 insertions(+), 43 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid 
refs/changes/60/302860/1

diff --git a/lib/wt2html/pp/processors/migrateTrailingNLs.js 
b/lib/wt2html/pp/processors/migrateTrailingNLs.js
index b1f0350..e311fcf 100644
--- a/lib/wt2html/pp/processors/migrateTrailingNLs.js
+++ b/lib/wt2html/pp/processors/migrateTrailingNLs.js
@@ -3,7 +3,6 @@
 
 var DU = require('../../../utils/DOMUtils.js').DOMUtils;
 
-
 // These nodes either end a line in wikitext (tr, li, dd, ol, ul, dl, caption,
 // p) or have implicit closing tags that can leak newlines to those that end a
 // line (th, td)
@@ -25,49 +24,49 @@
        return node.nodeName === 'TABLE' ? node : null;
 }
 
+// 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)
+// (2) The node has an auto-closed end-tag (wikitext-generated or literal html 
tag)
+//     and hasn't been fostered out of a table.
+// (3) It is the rightmost node in the DOM subtree rooted at a node
+//     that ends a line in wikitext
+function canMigrateNLOutOfNode(node) {
+       if (!node || node.nodeName === 'TABLE') {
+               return false;
+       }
+
+       // 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;
+       }
+
+       var dp = DU.getDataParsoid(node);
+       return nodeEndsLineInWT(node, dp) ||
+               (DU.isElt(node) && dp.autoInsertedEnd && !dp.fostered) ||
+               (!node.nextSibling && canMigrateNLOutOfNode(node.parentNode));
+}
+
+// A node has zero wt width if:
+// - tsr[0] == tsr[1]
+// - only has children with zero wt width
+function hasZeroWidthWT(node) {
+       var tsr = DU.getDataParsoid(node).tsr;
+       if (!tsr || tsr[0] === null || tsr[0] !== tsr[1]) {
+               return false;
+       }
+
+       var c = node.firstChild;
+       while (c && DU.isElt(c) && hasZeroWidthWT(c)) {
+               c = c.nextSibling;
+       }
+
+       return c === 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)
-       // (2) The node has an auto-closed end-tag (wikitext-generated or 
literal html tag)
-       //     and hasn't been fostered out of a table.
-       // (3) It is the rightmost node in the DOM subtree rooted at a node
-       //     that ends a line in wikitext
-       function canMigrateNLOutOfNode(node) {
-               if (!node || node.nodeName === 'TABLE') {
-                       return false;
-               }
-
-               // 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;
-               }
-
-               var dp = DU.getDataParsoid(node);
-               return nodeEndsLineInWT(node, dp) ||
-                       (DU.isElt(node) && dp.autoInsertedEnd && !dp.fostered) 
||
-                       (!node.nextSibling && 
canMigrateNLOutOfNode(node.parentNode));
-       }
-
-       // A node has zero wt width if:
-       // - tsr[0] == tsr[1]
-       // - only has children with zero wt width
-       function hasZeroWidthWT(node) {
-               var tsr = DU.getDataParsoid(node).tsr;
-               if (!tsr || tsr[0] === null || tsr[0] !== tsr[1]) {
-                       return false;
-               }
-
-               var c = node.firstChild;
-               while (c && DU.isElt(c) && hasZeroWidthWT(c)) {
-                       c = c.nextSibling;
-               }
-
-               return c === null;
-       }
-
        // Nothing to do for text and comment nodes
        if (!DU.isElt(elt)) {
                return;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib23d50294b2c2d1307365fd2405091c94533cd0c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>

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

Reply via email to