Subramanya Sastry has uploaded a new change for review.

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


Change subject: Get rid of state.activeTemplateId from the serializer.
......................................................................

Get rid of state.activeTemplateId from the serializer.

* Skip over encapsulated content whenever they are encountered
  since original/edited tranclusion/extension source is emitted
  directly on hitting the first node.

* This cleans up the WTS code some more.

* No change in parser tests (as it should be).

Change-Id: Idadac148438b70019b8c9a9f345f5e1aa3c75083
---
M js/lib/mediawiki.WikitextSerializer.js
1 file changed, 31 insertions(+), 37 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid 
refs/changes/76/61776/1

diff --git a/js/lib/mediawiki.WikitextSerializer.js 
b/js/lib/mediawiki.WikitextSerializer.js
index 8ff92bf..3876863 100644
--- a/js/lib/mediawiki.WikitextSerializer.js
+++ b/js/lib/mediawiki.WikitextSerializer.js
@@ -2113,6 +2113,20 @@
        return buf.join('');
 };
 
+WSP.skipOverEncapsulatedContent = function(node) {
+       var about = node.getAttribute('about');
+       if (!about) {
+               return node;
+       }
+
+       node = node.nextSibling;
+       while (node && DU.isElt(node) && about === node.getAttribute('about')) {
+               node = node.nextSibling;
+       }
+
+       return node;
+}
+
 /**
  * Get a DOM-based handler for an element node
  */
@@ -2130,26 +2144,6 @@
                handler,
                nodeTypeOf = node.getAttribute( 'typeof' ) || '';
 
-//     if (state.activeTemplateId) {
-//             if(node.getAttribute('about') === state.activeTemplateId) {
-//                     // Skip template content
-//                     return function(){};
-//             } else {
-//                     state.activeTemplateId = null;
-//             }
-//     } else {
-//             if (nodeTypeOf && nodeTypeOf.match(/\bmw:Object(\/[^\s]+|\b)/)) 
{
-//                     state.activeTemplateId = node.getAttribute('about' || 
null);
-//
-//
-
-       // XXX: Handle siblings directly in a template content handler returning
-       // the next node?
-       if (state.activeTemplateId && node.getAttribute('about') === 
state.activeTemplateId) {
-               // Ignore subsequent template content
-               return {handle: function() {}};
-       }
-
        // XXX: Convert into separate handlers?
        if ( dp.src !== undefined ) {
                //console.log(node.parentNode.outerHTML);
@@ -2157,8 +2151,6 @@
                        // Source-based template/extension round-tripping for 
now
                        return {
                                handle: function () {
-                                       state.activeTemplateId = 
node.getAttribute('about') || null;
-
                                        // In RT-testing mode, there will not 
be any edits to tpls.
                                        // So, use original source to eliminate 
spurious diffs showing
                                        // up in RT testing results.
@@ -2175,6 +2167,7 @@
                                                }
                                        }
                                        self.emitWikitext(src, state, cb, node);
+                                       return 
self.skipOverEncapsulatedContent(node);
                                },
                                sepnls: {
                                        // XXX: This is questionable, as the 
template can expand
@@ -2853,7 +2846,7 @@
  */
 WSP._serializeNode = function( node, state, cb) {
        cb = cb || state.chunkCB;
-       var prev, next;
+       var prev, next, nextNode;
 
        // serialize this node
        switch( node.nodeType ) {
@@ -2889,12 +2882,10 @@
                        var handled = false,
                                about = node.getAttribute('about') || null;
 
-                       // We have 2 global checks here for selser-mode
-                       // 1. WTS is not in a subtree with a modification flag 
that applies to every
-                       //    node of a subtree (rather than an indication that 
some node in the
-                       //    subtree is modified).
-                       // 2. WTS not processing template content that has 
already been emitted.
-                       if (state.selserMode && !state.inModifiedContent && 
(!about || about !== state.activeTemplateId)) {
+                       // WTS should not be in a subtree with a modification 
flag that applies
+                       // to every node of a subtree (rather than an 
indication that some node
+                       // in the subtree is modified).
+                       if (state.selserMode && !state.inModifiedContent) {
                                // To serialize from source, we need 2 things 
of the node:
                                // -- it should not have a diff marker
                                // -- it should have valid, usable DSR
@@ -2940,11 +2931,10 @@
 
                                        state.sep.src = (state.sep.src || '') + 
newSep;
 
-                                       // Update active template id -- so 
following tpl-content nodes
-                                       // can be ignored, if necessary.
+                                       // Skip over encapsulated content since 
it has already been serialized
                                        var nodeTypeOf = node.getAttribute( 
'typeof' ) || '';
-                                       if (nodeTypeOf && 
nodeTypeOf.match(/\bmw:Object(\/[^\s]+|\b)/)) {
-                                               state.activeTemplateId = about;
+                                       if (about && nodeTypeOf && 
nodeTypeOf.match(/\bmw:Object(\/[^\s]+|\b)/)) {
+                                               nextNode = 
this.skipOverEncapsulatedContent(node);
                                        }
                                }
                        }
@@ -2959,9 +2949,7 @@
                                if ( domHandler && domHandler.handle ) {
                                        // DOM-based serialization
                                        try {
-                                               // XXX: use a returned node to 
support handlers consuming
-                                               // siblings too
-                                               domHandler.handle(node, state, 
cb);
+                                               nextNode = 
domHandler.handle(node, state, cb);
                                        } catch(e) {
                                                console.error(e.stack || 
e.toString());
                                                console.error(node.nodeName, 
domHandler);
@@ -3017,7 +3005,13 @@
                        break;
        }
 
-       return node;
+       // If handlers didn't provide a valid next node,
+       // default to next sibling
+       if (nextNode === undefined) {
+               nextNode = node.nextSibling;
+       }
+
+       return nextNode;
 };
 
 /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idadac148438b70019b8c9a9f345f5e1aa3c75083
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

Reply via email to