-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add start and end properties to WikiText AST nodes for all elements. #7866
Changes from 5 commits
4200495
d3e62ec
e2b9a4e
ac8dda0
df0a1b1
5687d9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,16 @@ exports.init = function(parser) { | |
|
||
exports.parse = function() { | ||
// Move past the match | ||
var filterStart = this.parser.pos + 3; | ||
var filterEnd = filterStart + this.match[1].length; | ||
var toolTipStart = filterEnd + 1; | ||
var toolTipEnd = toolTipStart + (this.match[2] ? this.match[2].length : 0); | ||
var templateStart = toolTipEnd + 2; | ||
var templateEnd = templateStart + (this.match[3] ? this.match[3].length : 0); | ||
var styleStart = templateEnd + 2; | ||
var styleEnd = styleStart + (this.match[4] ? this.match[4].length : 0); | ||
var classesStart = styleEnd + 1; | ||
var classesEnd = classesStart + (this.match[5] ? this.match[5].length : 0); | ||
this.parser.pos = this.matchRegExp.lastIndex; | ||
// Get the match details | ||
var filter = this.match[1], | ||
|
@@ -42,21 +52,21 @@ exports.parse = function() { | |
var node = { | ||
type: "list", | ||
attributes: { | ||
filter: {type: "string", value: filter} | ||
filter: {type: "string", value: filter, start: filterStart, end: filterEnd}, | ||
This comment was marked as resolved.
Sorry, something went wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @linonetwo I must have misread the code this morning, this code is fine and needs no further changes, and this comment can be ignored. |
||
}, | ||
isBlock: true | ||
}; | ||
if(tooltip) { | ||
node.attributes.tooltip = {type: "string", value: tooltip}; | ||
node.attributes.tooltip = {type: "string", value: tooltip, start: toolTipStart, end: toolTipEnd}; | ||
} | ||
if(template) { | ||
node.attributes.template = {type: "string", value: template}; | ||
node.attributes.template = {type: "string", value: template, start: templateStart, end: templateEnd}; | ||
} | ||
if(style) { | ||
node.attributes.style = {type: "string", value: style}; | ||
node.attributes.style = {type: "string", value: style, start: styleStart, end: styleEnd}; | ||
} | ||
if(classes) { | ||
node.attributes.itemClass = {type: "string", value: classes.split(".").join(" ")}; | ||
node.attributes.itemClass = {type: "string", value: classes.split(".").join(" "), start: classesStart, end: classesEnd}; | ||
} | ||
return [node]; | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,10 @@ Parse the most recent match | |
exports.parse = function() { | ||
// Retrieve the most recent match so that recursive calls don't overwrite it | ||
var tag = this.nextTag; | ||
if (!tag.isSelfClosing) { | ||
tag.openTagStart = tag.start; | ||
tag.openTagEnd = tag.end; | ||
} | ||
this.nextTag = null; | ||
// Advance the parser position to past the tag | ||
this.parser.pos = tag.end; | ||
|
@@ -60,6 +64,27 @@ exports.parse = function() { | |
var reEnd = new RegExp("(" + reEndString + ")","mg"); | ||
tag.children = this.parser.parseInlineRun(reEnd,{eatTerminator: true}); | ||
} | ||
tag.end = this.parser.pos; | ||
tag.closeTagEnd = tag.end; | ||
if (tag.closeTagEnd === tag.openTagEnd) { | ||
tag.closeTagStart = tag.end; | ||
} else { | ||
tag.closeTagStart = tag.end - 1; | ||
while (tag.closeTagStart >= tag.start) { | ||
var char = this.parser.source[tag.closeTagStart - 1]; | ||
if (char === '>') { | ||
tag.closeTagStart = -1; | ||
break; | ||
} | ||
if (char === '<') { | ||
break; | ||
} | ||
tag.closeTagStart--; | ||
Gk0Wk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
if (tag.closeTagStart < tag.start) { | ||
tag.closeTagStart = tag.end; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Gk0Wk @Jermolene we should make sure that this PR does not introduce any significant performance regression. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this won't cost much, because it just But why would we need open/closeTagStart/End ? Can this feature be turn on when needed? |
||
} | ||
// Return the tag | ||
return [tag]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We always collapse multiple var statements into one:
This applies to all changes throughout this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this apply while there is assignment?
Hope this can be done by eslint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would need to be resolved manually.