Subramanya Sastry has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/335187 )
Change subject: Code refactoring: Handle special case for {{!}} early ...................................................................... Code refactoring: Handle special case for {{!}} early This could let us use existing information from resolveTemplateTarget and eliminate some duplicate code. To be explored in future patches. Change-Id: I2eeb27967f2e43ba8d6808292058ac48ee32a27e --- M lib/wt2html/tt/TemplateHandler.js 1 file changed, 29 insertions(+), 28 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid refs/changes/87/335187/1 diff --git a/lib/wt2html/tt/TemplateHandler.js b/lib/wt2html/tt/TemplateHandler.js index 84e5bbb..89967ae 100644 --- a/lib/wt2html/tt/TemplateHandler.js +++ b/lib/wt2html/tt/TemplateHandler.js @@ -236,19 +236,42 @@ * - currently only DEFAULTSORT and DISPLAYTITLE are considered */ TemplateHandler.prototype.checkForMagicWordVariable = function(tplToken) { + var env = this.manager.env; + var magicWord = tplToken.attribs[0].k; + + // special case for {{!}} magic word + if (magicWord === "!") { + // If we're not at the top level, return a table cell. This will always + // be the case. Either {{!}} was tokenized as a td, or it is tokenized + // as template but the recursive call to fetch its content returns a + // single | in an ambiguous context which will again be tokenized as td. + 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; + } + // Deal with the following scenarios: // - // 0. Simple: {{!}} // 1. Normal string: {{DEFAULTSORT:foo}} // 2. String with entities: {{DEFAULTSORT:"foo"bar}} // 3. Templated key: {{DEFAULTSORT:{{foo}}bar}} - var env = this.manager.env; var property, key, propAndKey, keyToks; - var magicWord = tplToken.attribs[0].k; - if (magicWord.constructor === String) { - // Scenario 0. or 1. above -- common case + // Scenario 1. above -- common case propAndKey = magicWord.match(/^([^:]+:?)(.*)$/); if (propAndKey) { property = propAndKey[1]; @@ -290,29 +313,7 @@ name = env.conf.wiki.magicWords[property.slice(0, -1)]; } - // special case for {{!}} magic word - if (name === "!") { - // If we're not at the top level, return a table cell. This will always - // be the case. Either {{!}} was tokenized as a td, or it is tokenized - // as template but the recursive call to fetch its content returns a - // single | in an ambiguous context which will again be tokenized as td. - 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; - } else if (Util.magicMasqs.has(name)) { + if (Util.magicMasqs.has(name)) { var templatedKey = false; if (keyToks) { // Check if any part of the key is templated -- To view, visit https://gerrit.wikimedia.org/r/335187 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2eeb27967f2e43ba8d6808292058ac48ee32a27e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: Subramanya Sastry <ssas...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits