Subramanya Sastry has uploaded a new change for review.
https://gerrit.wikimedia.org/r/80149
Change subject: Cleanup and deal with tpl-boundaries in minimizeInlineTags
......................................................................
Cleanup and deal with tpl-boundaries in minimizeInlineTags
* Last cleanup for now on this old code.
TODO: Deal with HTML attr comparison.
* Will revisit this code after working on a simplified pass
for bold-italic tags.
Change-Id: Ie39022a34a1b718cab4be326926891740ae02c9d
---
M js/lib/dom.minimizeTags.js
1 file changed, 21 insertions(+), 15 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid
refs/changes/49/80149/1
diff --git a/js/lib/dom.minimizeTags.js b/js/lib/dom.minimizeTags.js
index fceb2dd..9b98821 100644
--- a/js/lib/dom.minimizeTags.js
+++ b/js/lib/dom.minimizeTags.js
@@ -1,5 +1,6 @@
"use strict";
+require('./core-upgrade.js');
var DU = require('./mediawiki.DOMUtils.js').DOMUtils;
function minimizeInlineTags(root, rewriteable_nodes) {
@@ -7,10 +8,6 @@
function printPath(p) {
return p.map(function(n) { return n.nodeName; }).join('|');
- }
-
- function tail(a) {
- return a[a.length-1];
}
function remove_all_children(node) {
@@ -58,14 +55,17 @@
var P = [];
for (var i = 0; i < n; i++) {
var s = children[i];
- if (DU.isElt(s)) {
+ if (DU.isElt(s) && DU.isEncapsulatedElt(s)) {
+ // Dont descend into template generated content
+ P.push({path: [], orig_parent: node, children:
[s]});
+ } else if (DU.isElt(s)) {
var p = longest_linear_path(s);
if (p.length === 0) {
rewrite(s);
// console.log("Pushed EMPTY with
orig_parent: " + node.nodeName);
P.push({path: [], orig_parent: node,
children: [s]});
} else {
- var p_tail = tail(p);
+ var p_tail = p.last();
// console.log("llp: " + printPath(p));
@@ -96,10 +96,11 @@
function longest_linear_path(node) {
var children, path = [];
- while (DU.isElt(node)) {
+ // Do not cross into templates
+ while (DU.isElt(node) && !DU.isEncapsulatedElt(node)) {
path.push(node);
children = node.childNodes;
- if ((children.length === 0) || (children.length > 1)) {
+ if (children.length !== 1) {
return path;
}
node = children[0];
@@ -128,9 +129,11 @@
var prev = lcs[0];
for (var k = 1, lcs_len = lcs.length; k <
lcs_len; k++) {
var curr = lcs[k];
- // SSS FIXME: this add/remove can be
optimized
// console.log("adding " +
curr.nodeName + " to " + prev.nodeName);
- remove_all_children(prev);
+
+ // prev will have exactly one child
+ // -- remove that child and make curr
its child
+ prev.removeChild(prev.firstChild);
prev.appendChild(curr);
prev = curr;
}
@@ -149,16 +152,16 @@
// (b) we have a non-empty path ==> attach the
children to the end of the path
var p = paths[0].path;
var children = paths[0].children;
- if (p.length > 0) {
- var p_tail = tail(p);
+ if (p.length === 0) {
+ add_children(parent_node, children);
+ } else {
+ var p_tail = p.last();
remove_all_children(p_tail);
add_children(p_tail, children);
- } else {
- add_children(parent_node, children);
}
} else {
// Process the sublist
- rewrite_paths(tail(lcs), strip_lcs(paths, lcs));
+ rewrite_paths(lcs.last(), strip_lcs(paths,
lcs));
}
// console.log("done with this sublist");
@@ -166,6 +169,9 @@
// console.log("--done all sublists--");
}
+ // SSS FIXME: Check attributes between paths here
+ // - if data-parsoid.stx.html, all attributes should match
+ // - if not data-parsoid.stx.html, can only match with non-html tags
function common_path(old, new_path) {
var hash = {};
for (var i = 0, n = new_path.length; i < n; i++) {
--
To view, visit https://gerrit.wikimedia.org/r/80149
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie39022a34a1b718cab4be326926891740ae02c9d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits