Arlolra has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/378250 )
Change subject: [WIP] Lint multiple colon escaped links ...................................................................... [WIP] Lint multiple colon escaped links * From the wikitech-ambassador's thread, https://lists.wikimedia.org/pipermail/wikitech-ambassadors/2017-September/001675.html Change-Id: Ibee7875bb93b11d80099b3f690b0a61824e36c24 --- M lib/wt2html/tt/LinkHandler.js M tests/mocha/linter.js 2 files changed, 37 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid refs/changes/50/378250/1 diff --git a/lib/wt2html/tt/LinkHandler.js b/lib/wt2html/tt/LinkHandler.js index 554f5f4..2787851 100644 --- a/lib/wt2html/tt/LinkHandler.js +++ b/lib/wt2html/tt/LinkHandler.js @@ -72,7 +72,7 @@ * * @return {Object} The target info */ -WikiLinkHandler.prototype.getWikiLinkTargetInfo = function(hrefKV) { +WikiLinkHandler.prototype.getWikiLinkTargetInfo = function(token, hrefKV) { var env = this.manager.env; var info = { @@ -86,6 +86,21 @@ info.href = info.href.substr(1); } if (/^:/.test(info.href)) { + if (env.conf.parsoid.linting) { + var lint; + if (this.options.inTemplate) { + lint = { + // FIXME: Pass tsr info to the frame, but note that + // the transclusion cache will prevent us from being + // able to lint multiple occurrances. + dsr: [null, null], + templateInfo: { name: this.manager.frame.title }, + }; + } else { + lint = { dsr: token.dataAttribs.tsr }; + } + env.log('lint/multi-colon-escape', lint); + } // This will get caught by the caller, and mark the target as invalid throw new Error('Multiple colons prefixing href.'); } @@ -112,7 +127,7 @@ // Recurse! hrefKV = new KV('href', (/:/.test(info.href) ? ':' : '') + info.href); hrefKV.vsrc = info.hrefSrc; - info = this.getWikiLinkTargetInfo(hrefKV); + info = this.getWikiLinkTargetInfo(token, hrefKV); info.localprefix = nsPrefix + (info.localprefix ? (':' + info.localprefix) : ''); } @@ -199,7 +214,7 @@ var target, tokens, tsr; try { - target = this.getWikiLinkTargetInfo(hrefKV); + target = this.getWikiLinkTargetInfo(token, hrefKV); } catch (e) { // Invalid title target = null; diff --git a/tests/mocha/linter.js b/tests/mocha/linter.js index f1ad362..9edc798 100644 --- a/tests/mocha/linter.js +++ b/tests/mocha/linter.js @@ -600,4 +600,23 @@ return expectEmptyResults(wt, { tweakEnv: tweakEnv }); }); }); + + describe.only('MULTIPLE COLON ESCAPE', function() { + it('should lint links prefixed with multiple colons', function() { + return parseWT('[[None]]\n[[:One]]\n[[::Two]]\n[[:::Three]]') + .then(function(result) { + result.should.have.length(2); + result[0].dsr.should.deep.equal([ 18, 27 ]); + result[1].dsr.should.deep.equal([ 28, 40 ]); + }); + }); + it('should lint links prefixed with multiple colons from templates', function() { + return parseWT('{{1x|[[:One]]}}\n{{1x|[[::Two]]}}') + .then(function(result) { + result.should.have.length(1); + console.log(result) + }); + }); + }); + }); -- To view, visit https://gerrit.wikimedia.org/r/378250 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ibee7875bb93b11d80099b3f690b0a61824e36c24 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: Arlolra <abrea...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits