jenkins-bot has submitted this change and it was merged.
Change subject: (Bug 61928) Fix WTS to recognize templated attrs in inline
images.
......................................................................
(Bug 61928) Fix WTS to recognize templated attrs in inline images.
* Added new parser test to catch future regressions.
Change-Id: I23636d770705a76cb75ada99966337fa2f996176
---
M lib/mediawiki.WikitextSerializer.js
M tests/parserTests.txt
2 files changed, 18 insertions(+), 3 deletions(-)
Approvals:
GWicke: Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/mediawiki.WikitextSerializer.js
b/lib/mediawiki.WikitextSerializer.js
index 87c9ef6..db5950b 100644
--- a/lib/mediawiki.WikitextSerializer.js
+++ b/lib/mediawiki.WikitextSerializer.js
@@ -2242,6 +2242,12 @@
'mw:DiffMarker': 1
};
+WSP.isRecognizedSpanWrapper = function(type) {
+ var contentTypes = this.genContentSpanTypes;
+ return type &&
+ type.split(/\s/).find(function(t) { return contentTypes[t] ===
1; }) !== undefined;
+};
+
function id(v) {
return function() {
return v;
@@ -2950,7 +2956,7 @@
span: {
handle: function(node, state, cb) {
var type = node.getAttribute('typeof');
- if (type && state.serializer.genContentSpanTypes[type])
{
+ if (state.serializer.isRecognizedSpanWrapper(type)) {
if (type === 'mw:Nowiki') {
cb('<nowiki>', node);
if (node.childNodes.length === 1 &&
node.firstChild.nodeName === 'PRE') {
diff --git a/tests/parserTests.txt b/tests/parserTests.txt
index ffd170c..556f24a 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -10003,7 +10003,7 @@
!! end
!! test
-1. Image with individual attributes from templates
+1. Block image with individual attributes from templates
!! options
parsoid
!! input
@@ -10013,7 +10013,7 @@
!! end
!! test
-2. Image with individual attributes from templates
+2. Block Image with individual attributes from templates
!! options
parsoid
!! input
@@ -10022,6 +10022,15 @@
<figure typeof="mw:Image/Thumb mw:ExpandedAttrs"
data-mw='{"attribs":[["thumbnail",{"html":"<span about=\"#mwt1\"
typeof=\"mw:Transclusion\"
data-mw=\"{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;thumb&quot;}},&quot;i&quot;:0}}]}\"
data-parsoid=\"{&quot;dsr&quot;:[18,32,null,null],&quot;pi&quot;:[[{&quot;k&quot;:&quot;1&quot;,&quot;spc&quot;:[&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;]}]]}\">thumb</span>"}],["width",{"html":"<span
about=\"#mwt2\" typeof=\"mw:Transclusion\"
data-mw=\"{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;137px&quot;}},&quot;i&quot;:0}}]}\"
data-parsoid=\"{&quot;dsr&quot;:[33,47,null,null],&quot;pi&quot;:[[{&quot;k&quot;:&quot;1&quot;,&quot;spc&quot;:[&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;]}]]}\">137px</span>"}]]}'><a
href="File:Foobar.jpg"><img resource="./File:Foobar.jpg"
src="//example.com/images/3/3a/Foobar.jpg" height="16"
width="137"/></a><figcaption>This is a caption</figcaption></figure>
!! end
+!! test
+3. Inline image with individual attributes from templates
+!! options
+parsoid
+!! input
+[[File:Foobar.jpg|{{echo|50px}}]]
+!! result
+<p><span typeof="mw:Image mw:ExpandedAttrs" about="#mwt2"
data-mw='{"attribs":[["width",{"html":"<span about=\"#mwt1\"
typeof=\"mw:Transclusion\"
data-mw=\"{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;50px&quot;}},&quot;i&quot;:0}}]}\"
data-parsoid=\"{&quot;dsr&quot;:[18,31,null,null],&quot;pi&quot;:[[{&quot;k&quot;:&quot;1&quot;,&quot;spc&quot;:[&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;]}]]}\">50px</span>"}]]}'
data-parsoid='{"optList":[{"ck":"width","ak":"{{echo|50px}}"}]}'><a
href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"}}'><img
resource="./File:Foobar.jpg"
src="//example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg" height="6"
width="50"
data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"6","width":"50"},"sa":{"resource":"File:Foobar.jpg"}}'/></a></span></p>
+!! end
!! test
Image with multiple attributes from the same template (php)
--
To view, visit https://gerrit.wikimedia.org/r/115551
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I23636d770705a76cb75ada99966337fa2f996176
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits