Marcoil has uploaded a new change for review.

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

Change subject: Unify transclusion clean up into a single pass
......................................................................

Unify transclusion clean up into a single pass

This combines both stripEmptyElements and removeDataParsoid into
a single method.

Change-Id: Ic42b2b029bc517aabc9cfa639aeee4068d0dbddb
---
M lib/dom.cleanUpTemplates.js
M lib/mediawiki.DOMPostProcessor.js
2 files changed, 15 insertions(+), 19 deletions(-)


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

diff --git a/lib/dom.cleanUpTemplates.js b/lib/dom.cleanUpTemplates.js
index 3bbc680..880afc0 100644
--- a/lib/dom.cleanUpTemplates.js
+++ b/lib/dom.cleanUpTemplates.js
@@ -2,33 +2,30 @@
 
 var DU = require('./mediawiki.DOMUtils.js').DOMUtils;
 
-function stripEmptyElements(node, tplInfo, env, options) {
+function cleanUpTemplates(node, tplInfo, env, options) {
        // Cannot delete the first node since that carries the transclusion
        // information (typeof, data-mw). We could delete and migrate
        // the info over, but more pain than worth it. We can reconsider if
        // this ever becomes an issue.
-       if (!node.firstChild && node.nodeName in {'TR':1, 'LI':1} && node !== 
tplInfo.first) {
-               DU.deleteNode(node);
-       }
-}
-
-function removeDataParsoid(node, tplInfo, env, options) {
        if (node !== tplInfo.first) {
+               if (!node.firstChild && node.nodeName in {'TR':1, 'LI':1}) {
+                       // Delete empty tr-rows and li-nodes from template 
content
+                       DU.deleteNode(node);
+               } else {
                // TODO: We can't remove dp from nodes with stx information
                // right now, as the serializer needs that information to know 
which
                // content model the text came from to emit the right newline 
separators.
                // For example, both "a\n\nb" and "<p>a</p><p>b/p>" both 
generate
                // identical html but serialize to different wikitext.
-               var dp = DU.getDataParsoid(node);
-               if (!dp.stx) {
-                       node.removeAttribute('data-parsoid');
+                       var dp = DU.getDataParsoid(node);
+                       if (!dp.stx) {
+                               node.removeAttribute('data-parsoid');
+                       }
                }
        }
 }
 
 if (typeof module === "object") {
-       module.exports.stripEmptyElements =
-               DU.traverseTplOrExtNodes.bind(DU, stripEmptyElements);
-       module.exports.removeDataParsoid =
-               DU.traverseTplOrExtNodes.bind(DU, removeDataParsoid);
+       module.exports.cleanUpTemplates =
+               DU.traverseTplOrExtNodes.bind(DU, cleanUpTemplates);
 }
diff --git a/lib/mediawiki.DOMPostProcessor.js 
b/lib/mediawiki.DOMPostProcessor.js
index 9ea3f57..a4d8205 100644
--- a/lib/mediawiki.DOMPostProcessor.js
+++ b/lib/mediawiki.DOMPostProcessor.js
@@ -26,7 +26,7 @@
        stripMarkerMetas = CleanUp.stripMarkerMetas,
        unpackDOMFragments = 
require('./dom.t.unpackDOMFragments.js').unpackDOMFragments,
        wrapTemplates = require('./dom.wrapTemplates.js').wrapTemplates,
-       cleanUpTemplates = require('./dom.cleanUpTemplates.js'),
+       cleanUpTemplates = 
require('./dom.cleanUpTemplates.js').cleanUpTemplates,
        lintWikitextFixup = require('./dom.linter.js').logWikitextFixups;
 
 // map from mediawiki metadata names to RDFa property names
@@ -188,8 +188,6 @@
        this.processors.push(processRefs.bind(null,
                                
env.conf.parsoid.nativeExtensions.cite.references));
 
-       // Strip empty elements from template content
-       this.processors.push(cleanUpTemplates.stripEmptyElements);
 
     if (env.conf.parsoid.linting) {
         this.processors.push(lintWikitextFixup);
@@ -210,8 +208,9 @@
        domVisitor2.addHandler( null, cleanupAndSaveDataParsoid.bind( null, env 
) );
        this.processors.push(domVisitor2.traverse.bind(domVisitor2));
 
-       // Remove data-parsoid from transcluded content
-       this.processors.push(cleanUpTemplates.removeDataParsoid);
+       // Strip empty elements from template content and remove data-parsoid 
from
+       // transcluded content
+       this.processors.push(cleanUpTemplates);
 }
 
 // Inherit from EventEmitter

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic42b2b029bc517aabc9cfa639aeee4068d0dbddb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Marcoil <marc...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to