Arlolra has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/398909 )
Change subject: [WIP] Emit lint markers in the token stream
......................................................................
[WIP] Emit lint markers in the token stream
Unfortunately, this complicates template wrapping.
Change-Id: I61dbbf422ecc0e3d0ab1103ccf2b308cbd2aad44
---
M lib/wt2html/pp/handlers/linter.js
M lib/wt2html/tt/LinkHandler.js
M tests/mocha/linter.js
3 files changed, 38 insertions(+), 21 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/09/398909/1
diff --git a/lib/wt2html/pp/handlers/linter.js
b/lib/wt2html/pp/handlers/linter.js
index ffa1079..58d6a44 100644
--- a/lib/wt2html/pp/handlers/linter.js
+++ b/lib/wt2html/pp/handlers/linter.js
@@ -813,6 +813,23 @@
env.log('lint/multiline-html-table-in-list', lintObj);
}
+/**
+ * Log lints for linting meta markers that were inserted in the token stream
+ */
+var logLintMetas = function(env, node, dp, tplInfo) {
+ console.log('here', node.nodeName, node.getAttribute('typeof'))
+ if (!DU.isMarkerMeta(node, 'mw:Lint/lint/Marker')) {
+ return false;
+ }
+ var lintObj = dp.lintObj;
+ var templateInfo = findEnclosingTemplateName(env, tplInfo);
+ lintObj.templateInfo = templateInfo;
+ lintObj.dsr = findLintDSR(templateInfo, tplInfo, lintObj.dsr);
+ env.log('lint/' + dp.type, lintObj);
+ DU.deleteNode(node);
+ return true;
+};
+
function logWikitextFixups(node, env, atTopLevel, tplInfo) {
// For now, don't run linter in subpipelines.
// Only on the final DOM for the top-level page.
@@ -827,6 +844,11 @@
var dp = DU.getDataParsoid(node);
+ var next = node.nextSibling;
+ if (logLintMetas(env, node, dp, tplInfo)) {
+ return next;
+ }
+
/*
* Turn this off since this is wasted processing
* that is not really actionable at this time.
diff --git a/lib/wt2html/tt/LinkHandler.js b/lib/wt2html/tt/LinkHandler.js
index 5aea514..5c4dc0b 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(token, hrefKV) {
+WikiLinkHandler.prototype.getWikiLinkTargetInfo = function(token, hrefKV, cb) {
var env = this.manager.env;
var info = {
@@ -87,23 +87,19 @@
}
if (/^:/.test(info.href)) {
if (env.conf.parsoid.linting) {
- var lint = {
- dsr: token.dataAttribs.tsr,
- params: { href: ':' + info.href },
- templateInfo: undefined,
- };
- if (this.options.inTemplate) {
- // `frame.title` is already the result of
calling
- // `getPrefixedDBKey`, but for the sake of
consistency with
- // `findEnclosingTemplateName`, we do a little
more work to
- // match `env.makeLink`.
- var name =
Util.sanitizeTitleURI(env.page.relativeLinkPrefix +
-
this.manager.frame.title).replace(/^\.\//, '');
- lint.templateInfo = { name: name };
- // TODO(arlolra): Pass tsr info to the frame
- lint.dsr = [0, 0];
- }
- env.log('lint/multi-colon-escape', lint);
+ var tsr = token.dataAttribs.tsr;
+ var meta = new SelfclosingTagTk('meta', [
+ new KV('typeof', 'mw:Lint/lint/Marker'),
+ ], {
+ tsr: [tsr[0], tsr[0]],
+ type: 'multi-colon-escape',
+ lintObj: {
+ dsr: tsr,
+ params: { href: ':' + info.href },
+ templateInfo: undefined,
+ }
+ });
+ cb({ tokens: [meta] });
}
// This will get caught by the caller, and mark the target as
invalid
throw new Error('Multiple colons prefixing href.');
@@ -130,7 +126,7 @@
// Recurse!
hrefKV = new KV('href', (/:/.test(info.href) ?
':' : '') + info.href);
hrefKV.vsrc = info.hrefSrc;
- info = this.getWikiLinkTargetInfo(token,
hrefKV);
+ info = this.getWikiLinkTargetInfo(token,
hrefKV, cb);
info.localprefix = nsPrefix +
(info.localprefix ? (':' +
info.localprefix) : '');
}
@@ -219,7 +215,7 @@
var target, tokens, tsr;
try {
- target = this.getWikiLinkTargetInfo(token, hrefKV);
+ target = this.getWikiLinkTargetInfo(token, hrefKV, cb);
} catch (e) {
// Invalid title
target = null;
diff --git a/tests/mocha/linter.js b/tests/mocha/linter.js
index 69f02ad..0dec620 100644
--- a/tests/mocha/linter.js
+++ b/tests/mocha/linter.js
@@ -587,7 +587,6 @@
result.should.have.length(1);
result[0].should.have.a.property('templateInfo');
result[0].templateInfo.should.have.a.property('name', 'Template:1x');
- // TODO(arlolra): Frame doesn't have tsr info
yet
result[0].dsr.should.deep.equal([ 0, 0 ]);
result[0].should.have.a.property('params');
result[0].params.should.have.a.property('href',
'::Two');
--
To view, visit https://gerrit.wikimedia.org/r/398909
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I61dbbf422ecc0e3d0ab1103ccf2b308cbd2aad44
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