Subramanya Sastry has uploaded a new change for review.

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

Change subject: WIP: Bug 46811: Quick test hack
......................................................................

WIP: Bug 46811: Quick test hack

* Dirty incomplete implementation of solution 1 in the description
  of the bug report.

* Seems to fix the rendering of en:Boeing_757 so maybe this is not
  as bad as it seems and might be workable ...

Change-Id: I7c6cb7b9740a6d10e9d9a2a71d9d262f07f29238
---
M lib/ext.core.AttributeExpander.js
1 file changed, 22 insertions(+), 9 deletions(-)


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

diff --git a/lib/ext.core.AttributeExpander.js 
b/lib/ext.core.AttributeExpander.js
index cc1bf4e..97c43c0 100644
--- a/lib/ext.core.AttributeExpander.js
+++ b/lib/ext.core.AttributeExpander.js
@@ -11,6 +11,7 @@
 // define some constructor shortcuts
 var KV = defines.KV,
     EOFTk = defines.EOFTk,
+    NlTk = defines.NlTk,
     TagTk = defines.TagTk,
     SelfclosingTagTk = defines.SelfclosingTagTk;
 
@@ -22,7 +23,9 @@
  *    and returns it.
  * ---------------------------------------------------------- */
 function stripMetaTags( tokens, wrapTemplates ) {
-       var isPushed, buf = [],
+       var isPushed,
+               buf = [],
+               preNLBuf = null,
                hasGeneratedContent = false,
                inTpl = false,
                inInclude = false;
@@ -55,12 +58,20 @@
                                // Dont strip token if it is not a meta-tag
                                buf.push(token);
                        }
+               } else if (!preNLBuf && token.constructor === NlTk) {
+                       preNLBuf = buf;
+                       buf = [token];
                } else {
                        buf.push(token);
                }
        }
 
-       return { hasGeneratedContent: hasGeneratedContent, value: buf };
+       if (!preNLBuf) {
+               preNLBuf = buf;
+               buf = null;
+       }
+
+       return { hasGeneratedContent: hasGeneratedContent, preNLBuf: preNLBuf, 
postNLBuf: buf };
 }
 
 /**
@@ -118,12 +129,12 @@
  *
  * @private
  */
-AttributeExpander.prototype._returnAttributes = function ( token, cb, newAttrs 
)
-{
+AttributeExpander.prototype._returnAttributes = function ( token, cb, newAttrs 
) {
        this.manager.env.dp( 'AttributeExpander._returnAttributes: ', newAttrs 
);
 
        var modified = false,
                metaTokens = [],
+               ret = null,
                tmpDataMW = new Map(),
                oldAttrs = token.attribs,
                a, newA, newK, i, l, updatedK, updatedV;
@@ -147,7 +158,8 @@
                        if ( Array.isArray(a.k) ) {
                                if ( newK.constructor !== String || 
!newK.match( /mw\:maybeContent/ ) ) {
                                        updatedK = stripMetaTags(newK, 
this.options.wrapTemplates);
-                                       newK = updatedK.value;
+                                       newK = updatedK.preNLBuf;
+                                       ret = updatedK.postNLBuf;
                                        if (newA.v === '') {
                                                // Some templates can return 
content that should be
                                                // interpreted as a key-value 
pair.
@@ -163,7 +175,7 @@
                                                // the '=' and update the 'k' 
and 'v' to the split values.
                                                var kArr = 
Util.tokensToString(newK, true),
                                                        kStr = 
(kArr.constructor === String) ? kArr : kArr[0],
-                                                       m    = 
kStr.match(/([^=]+)=['"]?([^'"]*)['"]?$/);
+                                                       m    = 
kStr.match(/([^=]+)=['"]?([^'"]*)['"]?/);
 
                                                if (m) {
                                                        newK = m[1];
@@ -218,8 +230,9 @@
                                        }
 
                                        if (!newK.match(/^mw:/)) {
-                                               newA.v = updatedV.value;
+                                               newA.v = updatedV.preNLBuf;
                                        }
+                                       ret = updatedV.postNLBuf;
                                }
                        } else if (newA.v !== a.v) {
                                modified = true;
@@ -262,7 +275,7 @@
                                token.addAttribute("data-mw", JSON.stringify({
                                        attribs: expandedAttrs
                                }));
-                               cb( { tokens: [token] });
+                               cb( { tokens: [token].concat(ret || []) });
                        });
 
                        return;
@@ -270,7 +283,7 @@
                // console.warn("NEW TOK: " + JSON.stringify(token));
        }
 
-       cb( { tokens: [token] } );
+       cb( { tokens: [token].concat(ret || []) } );
 };
 
 if (typeof module === "object") {

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

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