Subramanya Sastry has uploaded a new change for review.
https://gerrit.wikimedia.org/r/90082
Change subject: Added support for {{echo|style='color:red'}} style attr.
templating
......................................................................
Added support for {{echo|style='color:red'}} style attr. templating
* Real use case on French wikipedia {{ligne grise}} found on this
page fr:Coupe_UEFA_1972-1973. I wouldn't be surprised if equivalent
templates exist on enwp and are used elsewhere. Since we had supported
this use case till now, we may not have run into production errors on
those. So, adding back the support that was dropped in 283bfd55.
* Fixes the parser tests that failed and were blacklisted in 283bfd55.
* Fixes RT errors on fr:Coupe_UEFA_1972-1973
Change-Id: I8119d753a02d10c8db48db8dfaac8c46dba981df
---
M js/lib/ext.core.AttributeExpander.js
M js/lib/mediawiki.WikitextSerializer.js
M js/tests/parserTests-blacklist.js
3 files changed, 16 insertions(+), 21 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid
refs/changes/82/90082/1
diff --git a/js/lib/ext.core.AttributeExpander.js
b/js/lib/ext.core.AttributeExpander.js
index caa921d..6fe2322 100644
--- a/js/lib/ext.core.AttributeExpander.js
+++ b/js/lib/ext.core.AttributeExpander.js
@@ -170,6 +170,8 @@
// and might be used as <div
{{GetStyle}}>foo</div> to
// generate: <div
style='color:red;'>foo</div>.
//
+ // Real use case: Template
{{ligne grise}} on frwp.
+ //
// To support this, we utilize
the following hack.
// If we got a string of the
form "k=v" and our orig-v
// was empty, then, we split
the template content around
@@ -178,10 +180,6 @@
kStr =
(kArr.constructor === String) ? kArr : kArr[0],
m =
kStr.match(/([^=]+)=['"]?([^'"]*)['"]?$/);
- // SSS FIXME: Do we continue to
support this?
- // If yes, how do we represent
this in data-mw format?
- // If no, we need to figure to
if there are templates
- // with this use-case, and how
common that is.
if (m) {
newK = m[1];
if (kArr.constructor
=== String) {
@@ -190,10 +188,18 @@
kArr[0] = m[2];
newA.v = kArr;
}
+
+ // Represent this in
data-mw by assigning the entire
+ // templated string to
the key's HTML and blanking
+ // the value's HTML.
Other way round should work as well.
+ tmpDataMW.set(newK, {
+ k: { "txt":
newK, "html": newA.k },
+ v: { "html": []
}
+ });
}
}
- if (updatedK.hasGeneratedContent) {
+ if (updatedK.hasGeneratedContent &&
!tmpDataMW.get(newK)) {
// newK can be an array
if (newK.constructor !==
String) {
var key =
Util.tokensToString(newK);
diff --git a/js/lib/mediawiki.WikitextSerializer.js
b/js/lib/mediawiki.WikitextSerializer.js
index 6ed8c0a..db4dcf6 100644
--- a/js/lib/mediawiki.WikitextSerializer.js
+++ b/js/lib/mediawiki.WikitextSerializer.js
@@ -713,7 +713,7 @@
// If this attribute's value is generated content,
// serialize HTML back to generator wikitext.
for (var i = 0; i < tplAttrs.length; i++) {
- if (tplAttrs[i][0].txt === key &&
tplAttrs[i][1].html) {
+ if (tplAttrs[i][0].txt === key &&
tplAttrs[i][1].html !== null) {
return this.serializeHTML({ env:
this.env, onSOL: false }, tplAttrs[i][1].html);
}
}
@@ -3005,7 +3005,10 @@
if (tplV) {
v = tplV;
} else {
- v = this.getAttributeValue(node, k, v);
+ // Pass in kv.k, not k since k can
potentially
+ // be original wikitext source for 'k'
rather than
+ // the string value of the key.
+ v = this.getAttributeValue(node, kv.k,
v);
}
// Remove encapsulation from protected
attributes
diff --git a/js/tests/parserTests-blacklist.js
b/js/tests/parserTests-blacklist.js
index 85016ca..a342949 100644
--- a/js/tests/parserTests-blacklist.js
+++ b/js/tests/parserTests-blacklist.js
@@ -585,10 +585,8 @@
add("wt2wt", "Case-sensitive magic words, when cased differently, should just
be template transclusions");
add("wt2wt", "Nonexistent template");
add("wt2wt", "Template with argument in separate line");
-add("wt2wt", "Template-generated attribute string (k='v')");
add("wt2wt", "Template with targets containing wikilinks");
add("wt2wt", "msgnw keyword");
-add("wt2wt", "0. includeonly around the entire attribute");
add("wt2wt", "2. includeonly in html attr value");
add("wt2wt", "Templates: HTML Tag: 2. Generation of HTML attr. value");
add("wt2wt", "Templates: HTML Tag: 3. Generation of HTML attr key and value");
@@ -3072,12 +3070,6 @@
add("selser", "Nonexistent template [[4]]", "{{thistemplatedoesnotexist}}");
add("selser", "Nonexistent template [[2]]", "{{thistemplatedoesnotexist}}");
add("selser", "Nonexistent template [[3]]", "{{thistemplatedoesnotexist}}");
-add("selser", "Template-generated attribute string (k='v') [2]",
"p6mic904q6wrvn29\n\n<span {{attr_str|id|v1}}>bar</span>");
-add("selser", "Template-generated attribute string (k='v') [1]", "<span
{{attr_str|id|v1}}>bar</span>");
-add("selser", "Template-generated attribute string (k='v') [[2]]",
"2r17p7ijxvjqncdi<span {{attr_str|id|v1}}>bar</span>");
-add("selser", "Template-generated attribute string (k='v') [[[3]]]", "<span
{{attr_str|id|v1}}>bar</span>");
-add("selser", "Template-generated attribute string (k='v') [[[2]]]", "<span
{{attr_str|id|v1}}>bar</span>");
-add("selser", "Template-generated attribute string (k='v') [[[4]]]", "<span
{{attr_str|id|v1}}>bar</span>");
add("selser", "Template with targets containing wikilinks [0,2,1,0,0]",
"{{[[foo]]}}\n\n{{[[{{echo|foo}}]]}}\n\n{{{{echo|[[foo}}]]}}");
add("selser", "Template with targets containing wikilinks [0,0,0,0,[3]]",
"{{[[foo]]}}\n\n{{[[{{echo|foo}}]]}}\n\n{{{{echo|[[foo}}]]}}");
add("selser", "Template with targets containing wikilinks [0,0,3,0,2]",
"{{[[foo]]}}\n\ncyacg230i1ss8aor\n\n{{{{echo|[[foo}}]]}}");
@@ -3092,12 +3084,6 @@
add("selser", "msgnw keyword [[4]]", "{{msgnw:MSGNW test}}");
add("selser", "msgnw keyword [[2]]", "{{msgnw:MSGNW test}}");
add("selser", "msgnw keyword [[3]]", "{{msgnw:MSGNW test}}");
-add("selser", "0. includeonly around the entire attribute [1]", "<span
<includeonly>id=\"v1\"</includeonly><noinclude>id=\"v2\"</noinclude>>bar</span>");
-add("selser", "0. includeonly around the entire attribute [[2]]",
"8gtj3g224yrpb9<span
<includeonly>id=\"v1\"</includeonly><noinclude>id=\"v2\"</noinclude>>bar</span>");
-add("selser", "0. includeonly around the entire attribute [2]",
"iq0f3f4t35t2csor\n\n<span
<includeonly>id=\"v1\"</includeonly><noinclude>id=\"v2\"</noinclude>>bar</span>");
-add("selser", "0. includeonly around the entire attribute [[[2]]]", "<span
<includeonly>id=\"v1\"</includeonly><noinclude>id=\"v2\"</noinclude>>bar</span>");
-add("selser", "0. includeonly around the entire attribute [[[4]]]", "<span
<includeonly>id=\"v1\"</includeonly><noinclude>id=\"v2\"</noinclude>>bar</span>");
-add("selser", "0. includeonly around the entire attribute [[[3]]]", "<span
<includeonly>id=\"v1\"</includeonly><noinclude>id=\"v2\"</noinclude>>bar</span>");
add("selser", "2. includeonly in html attr value [[0,3,0]]", "<span
id=\"<noinclude>v1</noinclude><includeonly>v2</includeonly>\">bar</span>\n<span
id=<noinclude>\"v1\"</noinclude><includeonly>\"v2\"</includeonly>>bar</span>");
add("selser", "2. includeonly in html attr value [[0,4,0]]", "<span
id=\"<noinclude>v1</noinclude><includeonly>v2</includeonly>\">bar</span>\n<span
id=<noinclude>\"v1\"</noinclude><includeonly>\"v2\"</includeonly>>bar</span>");
add("selser", "2. includeonly in html attr value [2]",
"u352zdrjeccsdcxr\n\n<span
id=\"<noinclude>v1</noinclude><includeonly>v2</includeonly>\">bar</span>\n<span
id=<noinclude>\"v1\"</noinclude><includeonly>\"v2\"</includeonly>>bar</span>");
--
To view, visit https://gerrit.wikimedia.org/r/90082
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8119d753a02d10c8db48db8dfaac8c46dba981df
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