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

Change subject: Tweaks to minimizeInlineTags to work with current HTML libs in 
Parsoid
......................................................................


Tweaks to minimizeInlineTags to work with current HTML libs in Parsoid

* Looks like the orig version was printing paths directly instead
  of collecting nodeName (not sure how that version worked). Fixed
  debugging statements to print node-names for paths.

* The orig version was, in one place, using a HTML node as an object
  property name (instead of using nodeName) which no longer worked
  with current HTML libs. Fixed that code.

  This fix now makes the algo functional again.

  Still not deployable without introducing HTML attribute checks.

Change-Id: I8ccbb66b91e5cebba1c5c7b156e848d99d9d4655
---
M js/lib/dom.minimizeTags.js
1 file changed, 18 insertions(+), 9 deletions(-)

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



diff --git a/js/lib/dom.minimizeTags.js b/js/lib/dom.minimizeTags.js
index 00fd55c..fceb2dd 100644
--- a/js/lib/dom.minimizeTags.js
+++ b/js/lib/dom.minimizeTags.js
@@ -5,6 +5,10 @@
 function minimizeInlineTags(root, rewriteable_nodes) {
        var rewriteable_node_map = null;
 
+       function printPath(p) {
+               return p.map(function(n) { return n.nodeName; }).join('|');
+       }
+
        function tail(a) {
                return a[a.length-1];
        }
@@ -24,7 +28,7 @@
        function init() {
                rewriteable_node_map = {};
                for (var i = 0, n = rewriteable_nodes.length; i < n; i++) {
-                       
rewriteable_node_map[rewriteable_nodes[i].toLowerCase()] = true;
+                       
rewriteable_node_map[rewriteable_nodes[i].toUpperCase()] = true;
                }
        }
 
@@ -63,7 +67,7 @@
                                } else {
                                        var p_tail = tail(p);
 
-                                       // console.log("llp: " + p);
+                                       // console.log("llp: " + printPath(p));
 
                                        // process subtree (depth-first)
                                        rewrite(p_tail);
@@ -75,7 +79,7 @@
                                                
new_children.push(child_nodes[j]);
                                        }
 
-                                       // console.log("Pushed: " + p + ", 
tail: " + p_tail.nodeName + "; new_children: " + new_children.length);
+                                       // console.log("Pushed: " + 
printPath(p) + ", tail: " + p_tail.nodeName + "; new_children: " + 
new_children.length);
                                        P.push({path: p, orig_parent: p_tail, 
children: new_children});
                                }
                        } else {
@@ -120,7 +124,7 @@
 
                        if (lcs.length > 0) {
                                // Connect up LCS
-                               // console.log("LCS: " + lcs);
+                               // console.log("LCS: " + printPath(lcs));
                                var prev = lcs[0];
                                for (var k = 1, lcs_len = lcs.length; k < 
lcs_len; k++) {
                                        var curr = lcs[k];
@@ -137,7 +141,7 @@
 
                        var paths     = s.paths;
                        var num_paths = paths.length;
-                       // console.log("sublist: lcs: " + lcs + ", #paths: " + 
num_paths);
+                       // console.log("sublist: lcs: " + printPath(lcs) + ", 
#paths: " + num_paths);
                        if (num_paths === 1) {
                                // Nothing more to do!  Stitch things up
                                // two possible scenarios:
@@ -165,7 +169,7 @@
        function common_path(old, new_path) {
                var hash = {};
                for (var i = 0, n = new_path.length; i < n; i++) {
-                       var e = new_path[i].nodeName.toLowerCase();
+                       var e = new_path[i].nodeName;
                        if (is_rewriteable_node(e)) {
                                hash[e] = new_path[i];
                        }
@@ -173,7 +177,7 @@
 
                var cp = [];
                for (i = 0, n = old.length; i < n; i++) {
-                       var hit = hash[old[i].nodeName.toLowerCase()];
+                       var hit = hash[old[i].nodeName];
                        // Add old path element always.  This effectively picks 
elements from the leftmost path.
                        if (hit) {
                                cp.push(old[i]);
@@ -190,16 +194,19 @@
                // Ex: <b><i><b>BIB</b></i></b> will
                // Fix this to be more robust
 
+               // console.log("Orig paths:\n-> " + paths.map(function(p) { 
return printPath(p.path); }).join("\n-> "));
+               // console.log("Stripping " + printPath(lcs));
+
                var lcs_map = {};
                for (var i = 0, n = lcs.length; i < n; i++) {
-                       lcs_map[lcs[i]] = true;
+                       lcs_map[lcs[i].nodeName] = true;
                }
 
                for (i = 0, n = paths.length; i < n; i++) {
                        var p = paths[i].path;
                        for (var j = 0, l = p.length; j < l; j++) {
                                // remove matching element
-                               if (lcs_map[p[j]]) {
+                               if (lcs_map[p[j].nodeName]) {
                                        p.splice(j, 1);
                                        l--;
                                        j--;
@@ -207,6 +214,8 @@
                        }
                }
 
+               // console.log("Stripped paths:\n-> " + paths.map(function(p) { 
return printPath(p.path); }).join("\n-> "));
+
                return paths;
        }
 

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

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

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

Reply via email to