Subramanya Sastry has uploaded a new change for review.
https://gerrit.wikimedia.org/r/78922
Change subject: WIP: Tweak tpl-param serialization
......................................................................
WIP: Tweak tpl-param serialization
Additional fixes to be incorporated into the commit msg:
--------------------
- Also fixes serialization of {{echo|1=x}} vs. {{echo|x}}
- Also fixes bug in recording ws in postional param cases
ws was considered both a param as well as surrounding ws.
- New tests to be added for this.
- parser tests failure to be investigated.
--------------------
* Consider the following wikitext:
{{quote
|sign=
|text=This is a quote
}}
* If you edit this template in VE to add a value for the 'sign'
param to say 'bar', Parsoid would then serialize this to:
{{quote
|sign=
bar|text=This is a quote
}}
* Parsoid keeps track of original whitespace around template
param-key and param-value and uses that information to restore
whitespace. However, for empty param values, the newline
after "sign=" was treated as a newline *before* an empty value
instead of a newlined *after* an empty value. On serialization,
this led to the newline being output before "bar".
NOTE that for param-keys, the existing regexp is the right
behavior.
* This patch changes the regexp to record that newline correctly
where it belongs.
* This fixes the post-edit serialization of the above snippet.
* We have to figure out a way of testing this behavior.
Since WS-info is part of data-parsoid, we cannot test this without
adding data-parsoid to parser tests. Is this the best solution?
To be discussed.
Change-Id: I8a9609520a1af4fabe18c423378870edf2922482
---
M js/lib/ext.core.TemplateHandler.js
M js/lib/mediawiki.WikitextSerializer.js
2 files changed, 27 insertions(+), 21 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid
refs/changes/22/78922/1
diff --git a/js/lib/ext.core.TemplateHandler.js
b/js/lib/ext.core.TemplateHandler.js
index c5d3f73..9954dfa 100644
--- a/js/lib/ext.core.TemplateHandler.js
+++ b/js/lib/ext.core.TemplateHandler.js
@@ -832,17 +832,19 @@
paramInfo = {
k: k
};
- // Preserve key and value space prefix / postfix, if any
- var keySpaceMatch = kSrc.match(/^(\s*)[^]*?(\s*)$/),
- valueSpaceMatch =
vSrc.match(/^(\s*)[^]*?(\s*)$/);
- if (keySpaceMatch[1] || keySpaceMatch[2] !== ' ' ||
- // Leading space in positional
parameters is part of the
- // value, so don't need to remember it
- (!isPositional && valueSpaceMatch[1]
!== ' ') ||
- valueSpaceMatch[2]) {
- // Remember non-standard spacing
- paramInfo.spc = [keySpaceMatch[1],
keySpaceMatch[2],
- valueSpaceMatch[1], valueSpaceMatch[2]];
+ if (!isPositional) {
+ // Preserve key and value space prefix /
postfix, if any
+ var keySpaceMatch =
kSrc.match(/^(\s*)[^]*?(\s*)$/),
+ valueSpaceMatch =
vSrc.match(/^(\s*?)[^]*?(\s*)$/);
+ if (keySpaceMatch[1] || keySpaceMatch[2] !== '
' ||
+ // Leading space in positional
parameters is part of the
+ // value, so don't need to
remember it
+ (!isPositional &&
valueSpaceMatch[1] !== ' ') ||
+ valueSpaceMatch[2]) {
+ // Remember non-standard spacing
+ paramInfo.spc = [keySpaceMatch[1],
keySpaceMatch[2],
+ valueSpaceMatch[1],
valueSpaceMatch[2]];
+ }
}
paramInfos.push(paramInfo);
}
diff --git a/js/lib/mediawiki.WikitextSerializer.js
b/js/lib/mediawiki.WikitextSerializer.js
index 45bcb4d..d601e73 100644
--- a/js/lib/mediawiki.WikitextSerializer.js
+++ b/js/lib/mediawiki.WikitextSerializer.js
@@ -2969,16 +2969,27 @@
n = keys.length;
if (n > 0) {
var numericIndex = 1,
-
pushArg = function (k, paramInfo) {
var v,
// Default to ' = '
spacing. Anything that matches
// this does not
remember spc explicitly.
spc = ['', ' ', ' ',
''],
- kSrc = k;
+ kSrc = k,
+ serializeAsNamed =
false;
+
+ // NOTE: Escaping the "=" char
in the regexp because JSHint
+ // complains that it can be
confused by other developers.
+ //
http://jslinterrors.com/a-regular-expression-literal-can-be-confused-with/
+
+ // Use named serialization if
the value contains a '='
+ if (k !==
numericIndex.toString() || isTpl && (/\=/).test(tpl.params[k].wt)) {
+ serializeAsNamed = true;
+ }
+
if (paramInfo) {
if (paramInfo.spc) {
spc =
paramInfo.spc;
+
serializeAsNamed = true;
}
kSrc = spc[0] + k +
spc[1];
} //else {
@@ -2987,13 +2998,7 @@
//spc = ['', ' ', ' ',
''];
//}
- // NOTE: Escaping the "=" char
in the regexp because JSHint
- // complains that it can be
confused by other developers.
- //
http://jslinterrors.com/a-regular-expression-literal-can-be-confused-with/
- if (kSrc ===
numericIndex.toString() &&
- // Use named
serialization if the value contains a '='
- !(isTpl &&
(/\=/).test(tpl.params[k].wt)))
- {
+ if (!serializeAsNamed) {
numericIndex++;
// Escape as positional
parameter
v =
serializer.escapeTplArgWT(state,
@@ -3007,7 +3012,6 @@
} else {
argBuf.push(v +
spc[3]);
}
-
} else {
// Escape as value only
v =
serializer.escapeTplArgWT(state,
--
To view, visit https://gerrit.wikimedia.org/r/78922
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8a9609520a1af4fabe18c423378870edf2922482
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