Marcoil has uploaded a new change for review. https://gerrit.wikimedia.org/r/131733
Change subject: Minor cleanup: move helpers out of _onChunk ...................................................................... Minor cleanup: move helpers out of _onChunk Change-Id: Id7cf151912bc9d60f0931b7c7a3d2a742130a0d7 --- M lib/ext.core.TemplateHandler.js 1 file changed, 70 insertions(+), 66 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid refs/changes/33/131733/1 diff --git a/lib/ext.core.TemplateHandler.js b/lib/ext.core.TemplateHandler.js index 74df5c3..a27c8b4 100644 --- a/lib/ext.core.TemplateHandler.js +++ b/lib/ext.core.TemplateHandler.js @@ -667,6 +667,76 @@ }; /** + * Parameter processing helpers + */ +var isSimpleParam = function (tokens) { + var isSimpleToken = function (token) { + return (token.constructor === String || + token.constructor === CommentTk || + token.constructor === NlTk); + }; + if (!Array.isArray(tokens)) { + return isSimpleToken(tokens); + } + return tokens.every(isSimpleToken); +}; + +// Add its HTML conversion to a parameter. The eachCb is only +// used to signal an error to async.each +var getParamHTML = function (paramData, eachCb) { + var param = paramData.param, + paramTokens = paramData.tokens, + srcStart = paramData.info.srcOffsets[2], + srcEnd = paramData.info.srcOffsets[3]; + if (paramData.info.spc) { + srcStart += paramData.info.spc[2].length; + srcEnd -= paramData.info.spc[3].length; + } else if (paramData.info.named) { + // The default spacing for named arguments is one + // space after the '=' + srcStart++; + } + + Util.processContentInPipeline( + this.manager.env, this.manager.frame, + param.wt, + { + pipelineType: "text/x-mediawiki/full", + pipelineOpts: { + isInclude: true, + wrapTemplates: true, + inBlockToken: true, + // TODO: This helps in the case of unnamed + // parameters which start with whitespace, + // but it's not be the correct solution + // for cases with significant start-of-line + // chars inserted after "\n". + noPre: true + }, + srcOffsets: [ srcStart, srcEnd ], + documentCB: function (html) { + // Remove DSR from children + for (var c = 0; c < html.body.children.length; c++) { + var node = html.body.children[c], + dp = DU.getDataParsoid(node); + if (dp.dsr) { + delete (dp.dsr); + // If data-parsoid only had dsr, remove it completely + if (Object.keys(dp).length === 0) { + node.removeAttribute('data-parsoid'); + } else { + DU.setDataParsoid(node, dp); + } + } + } + + param.html = html.body.innerHTML; + eachCb(null); + } + }); +}; + +/** * Handle chunk emitted from the input pipeline after feeding it a template */ TemplateHandler.prototype._onChunk = function( state, cb, chunk ) { @@ -702,61 +772,6 @@ var argInfo = this.getArgInfo(state), argDict = argInfo.dict; - // Add its HTML conversion to a parameter. The eachCb is only - // used to signal an error to async.each - var getParamHTML = function (paramData, eachCb) { - var param = paramData.param, - paramTokens = paramData.tokens, - srcStart = paramData.info.srcOffsets[2], - srcEnd = paramData.info.srcOffsets[3]; - if (paramData.info.spc) { - srcStart += paramData.info.spc[2].length; - srcEnd -= paramData.info.spc[3].length; - } else if (paramData.info.named) { - // The default spacing for named arguments is one - // space after the '=' - srcStart++; - } - - Util.processContentInPipeline( - this.manager.env, this.manager.frame, - param.wt, - { - pipelineType: "text/x-mediawiki/full", - pipelineOpts: { - isInclude: true, - wrapTemplates: true, - inBlockToken: true, - // TODO: This helps in the case of unnamed - // parameters which start with whitespace, - // but it's not be the correct solution - // for cases with significant start-of-line - // chars inserted after "\n". - noPre: true - }, - srcOffsets: [ srcStart, srcEnd ], - documentCB: function (html) { - // Remove DSR from children - for (var c = 0; c < html.body.children.length; c++) { - var node = html.body.children[c], - dp = DU.getDataParsoid(node); - if (dp.dsr) { - delete (dp.dsr); - // If data-parsoid only had dsr, remove it completely - if (Object.keys(dp).length === 0) { - node.removeAttribute('data-parsoid'); - } else { - DU.setDataParsoid(node, dp); - } - } - } - - param.html = html.body.innerHTML; - eachCb(null); - } - }); - }; - // Collect the parameters that need parsing into HTML, that is, // those that are not simple strings. // This optimizes for the common case where all are simple strings, @@ -772,17 +787,6 @@ paramTokens = state.token.attribs[paramInfo.k].v; } - var isSimpleParam = function (tokens) { - var isSimpleToken = function (token) { - return (token.constructor === String || - token.constructor === CommentTk || - token.constructor === NlTk); - }; - if (!Array.isArray(tokens)) { - return isSimpleToken(tokens); - } - return tokens.every(isSimpleToken); - }; // No need to pass through a whole sub-pipeline to get the // html if the param is either a single string, or if it's // just text, comments or newlines. -- To view, visit https://gerrit.wikimedia.org/r/131733 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id7cf151912bc9d60f0931b7c7a3d2a742130a0d7 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: dom_tpl_params_4 Gerrit-Owner: Marcoil <marc...@wikimedia.org> Gerrit-Reviewer: GWicke <gwi...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits