Arlolra has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/349521 )
Change subject: Factor out common encapsulation pattern
......................................................................
Factor out common encapsulation pattern
Change-Id: I564e3a9d40b0ead088d37c87a47015069cb4a938
---
M lib/wt2html/tt/TemplateHandler.js
1 file changed, 22 insertions(+), 27 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/21/349521/1
diff --git a/lib/wt2html/tt/TemplateHandler.js
b/lib/wt2html/tt/TemplateHandler.js
index eaf5080..436ca09 100644
--- a/lib/wt2html/tt/TemplateHandler.js
+++ b/lib/wt2html/tt/TemplateHandler.js
@@ -249,6 +249,15 @@
}
};
+TemplateHandler.prototype.encapTokens = function(state, tokens, extraDict) {
+ var toks = this.getEncapsulationInfo(state, tokens);
+ toks.push(this.getEncapsulationInfoEndTag(state));
+ var argInfo = this.getArgInfo(state);
+ if (extraDict) { Object.assign(argInfo.dict, extraDict); }
+ toks[0].dataAttribs.tmp.tplarginfo = JSON.stringify(argInfo);
+ return toks;
+};
+
/**
* Process the special magic word as specified by resolvedTgt.magicWordType
* magicWordType === '!' => {{!}} is the magic word
@@ -267,19 +276,13 @@
if (!this.atTopLevel) {
return [new TagTk("td")];
}
-
var state = {
token: tplToken,
wrapperType: "mw:Transclusion",
wrappedObjectId: env.newObjectId(),
};
-
this.resolveTemplateTarget(state, "!");
- var toks = this.getEncapsulationInfo(state, ["|"]);
- toks.push(this.getEncapsulationInfoEndTag(state));
- var argInfo = this.getArgInfo(state);
- toks[0].dataAttribs.tmp.tplarginfo = JSON.stringify(argInfo);
- return toks;
+ return this.encapTokens(state, ["|"]);
}
if (!resolvedTgt || resolvedTgt.magicWordType !== 'MASQ') {
@@ -581,9 +584,7 @@
// more readily fixed by fixing the markup. The goal
here is
// to ensure that the output renders properly and it
roundtrips
// without dirty diffs rather then faithful DOMspec
representation.
- newTokens = tplHandler.getEncapsulationInfo(state,
newTokens);
-
newTokens.push(tplHandler.getEncapsulationInfoEndTag(state));
- newTokens[0].dataAttribs.tmp.tplarginfo =
JSON.stringify(tplHandler.getArgInfo(state));
+ newTokens = tplHandler.encapTokens(state, newTokens);
}
newTokens.rank = tplHandler.rank; // Assign the correct rank to
the tokens
@@ -1194,19 +1195,16 @@
// or refactor to emit it later for all paths, but the
pragmatic
// thing to do is just ignore it and wrap this anew.
state.wrappedObjectId = env.newObjectId();
- tokens = this.getEncapsulationInfo(state, tokens);
- var argInfo = this.getArgInfo(state);
- argInfo.dict.errors = [
- {
- key: 'mw-api-tplfetch-error',
- message: 'Page / template fetching
disabled, and no cache for ' + title,
- },
- ];
- var start = tokens[0];
- start.dataAttribs.tmp.tplarginfo =
JSON.stringify(argInfo);
- var typeOf = start.getAttribute('typeof');
- start.setAttribute('typeof', 'mw:Error ' + typeOf);
- tokens.push(this.getEncapsulationInfoEndTag(state));
+ tokens = this.encapTokens(state, tokens, {
+ errors: [
+ {
+ key: 'mw-api-tplfetch-error',
+ message: 'Page / template
fetching disabled, and no cache for ' + title,
+ },
+ ],
+ });
+ var typeOf = tokens[0].getAttribute('typeof');
+ tokens[0].setAttribute('typeof', 'mw:Error ' + typeOf);
}
parentCB({ tokens: tokens });
} else {
@@ -1262,10 +1260,7 @@
wrapperType: "mw:Param",
wrappedObjectId:
tplHandler.manager.env.newObjectId(),
};
- toks = tplHandler.getEncapsulationInfo(state, toks);
- toks.push(tplHandler.getEncapsulationInfoEndTag(state));
- var argInfo = tplHandler.getArgInfo(state);
- toks[0].dataAttribs.tmp.tplarginfo =
JSON.stringify(argInfo);
+ toks = tplHandler.encapTokens(state, toks);
cb({ tokens: toks });
};
} else {
--
To view, visit https://gerrit.wikimedia.org/r/349521
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I564e3a9d40b0ead088d37c87a47015069cb4a938
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits