mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +01:00
Update markdown-it dependency to 4.0.1, fix breaking changes.
This commit is contained in:
parent
e305d22cce
commit
c764d2798f
4 changed files with 25 additions and 24 deletions
|
|
@ -64,12 +64,12 @@ function lintFile(file, config, callback) {
|
|||
var lines = contents.split(shared.newLineRe);
|
||||
// Annotate tokens with line/lineNumber
|
||||
tokens.forEach(function forToken(token) {
|
||||
if (token.lines) {
|
||||
token.line = lines[token.lines[0]];
|
||||
token.lineNumber = token.lines[0] + 1;
|
||||
if (token.map) {
|
||||
token.line = lines[token.map[0]];
|
||||
token.lineNumber = token.map[0] + 1;
|
||||
// Trim bottom of token to exclude whitespace lines
|
||||
while (!(lines[token.lines[1] - 1].trim())) {
|
||||
token.lines[1]--;
|
||||
while (!(lines[token.map[1] - 1].trim())) {
|
||||
token.map[1]--;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
35
lib/rules.js
35
lib/rules.js
|
|
@ -9,7 +9,7 @@ function indentFor(token) {
|
|||
|
||||
// Returns the heading style for a heading token
|
||||
function headingStyleFor(token) {
|
||||
if ((token.lines[1] - token.lines[0]) === 1) {
|
||||
if ((token.map[1] - token.map[0]) === 1) {
|
||||
if (/#\s*$/.test(token.line)) {
|
||||
return "atx_closed";
|
||||
}
|
||||
|
|
@ -44,7 +44,7 @@ function forEachLine(params, callback) {
|
|||
var codeLines = [];
|
||||
filterTokens(params.tokens, "code_block")
|
||||
.forEach(function forToken(token) {
|
||||
for (var i = token.lines[0]; i < token.lines[1]; i++) {
|
||||
for (var i = token.map[0]; i < token.map[1]; i++) {
|
||||
codeLines.push(i);
|
||||
}
|
||||
});
|
||||
|
|
@ -79,7 +79,7 @@ function flattenLists(tokens, filterBy) {
|
|||
var lists = [];
|
||||
var stack = [];
|
||||
var current = null;
|
||||
var lastWithLines = null;
|
||||
var lastWithMap = null;
|
||||
tokens.forEach(function forToken(token) {
|
||||
if ((token.type === "bullet_list_open") ||
|
||||
(token.type === "ordered_list_open")) {
|
||||
|
|
@ -96,7 +96,7 @@ function flattenLists(tokens, filterBy) {
|
|||
} else if ((token.type === "bullet_list_close") ||
|
||||
(token.type === "ordered_list_close")) {
|
||||
// Finalize current context and restore previous
|
||||
current.lastLineIndex = lastWithLines.lines[1];
|
||||
current.lastLineIndex = lastWithMap.map[1];
|
||||
if ((filterBy === undefined) || (filterBy === current.ordered)) {
|
||||
lists.splice(current.insert, 0, current);
|
||||
delete current.insert;
|
||||
|
|
@ -105,9 +105,9 @@ function flattenLists(tokens, filterBy) {
|
|||
} else if (token.type === "list_item_open") {
|
||||
// Add list item
|
||||
current.items.push(token);
|
||||
} else if (token.lines) {
|
||||
// Track last token with lines
|
||||
lastWithLines = token;
|
||||
} else if (token.map) {
|
||||
// Track last token with map
|
||||
lastWithMap = token;
|
||||
}
|
||||
});
|
||||
return lists;
|
||||
|
|
@ -122,10 +122,11 @@ module.exports = [
|
|||
var prevLevel = 0;
|
||||
filterTokens(params.tokens, "heading_open")
|
||||
.forEach(function forToken(token) {
|
||||
if (prevLevel && (token.hLevel > prevLevel + 1)) {
|
||||
var level = parseInt(token.tag.slice(1), 10);
|
||||
if (prevLevel && (level > prevLevel + 1)) {
|
||||
errors.push(token.lineNumber);
|
||||
}
|
||||
prevLevel = token.hLevel;
|
||||
prevLevel = level;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
|
@ -137,7 +138,7 @@ module.exports = [
|
|||
"func": function MD002(params, errors) {
|
||||
params.tokens.every(function forToken(token) {
|
||||
if (token.type === "heading_open") {
|
||||
if (token.hLevel !== 1) {
|
||||
if (token.tag !== "h1") {
|
||||
errors.push(token.lineNumber);
|
||||
}
|
||||
return false;
|
||||
|
|
@ -391,7 +392,7 @@ module.exports = [
|
|||
var needBlankLine = false;
|
||||
params.tokens.forEach(function forToken(token) {
|
||||
if (token.type === "heading_open") {
|
||||
if ((token.lines[0] - prevMaxLineIndex) === 0) {
|
||||
if ((token.map[0] - prevMaxLineIndex) === 0) {
|
||||
errors.push(token.lineNumber);
|
||||
}
|
||||
prevHeadingLineNumber = token.lineNumber;
|
||||
|
|
@ -401,18 +402,18 @@ module.exports = [
|
|||
token.content.split(shared.newLineRe)
|
||||
.forEach(function forLine(line, offset) {
|
||||
if (/^(-+|=+)\s*$/.test(line)) {
|
||||
errors.push(token.lines[0] + offset);
|
||||
errors.push(token.map[0] + offset);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (token.lines) {
|
||||
if (token.map) {
|
||||
if (needBlankLine) {
|
||||
if ((token.lines[0] - prevMaxLineIndex) === 0) {
|
||||
if ((token.map[0] - prevMaxLineIndex) === 0) {
|
||||
errors.push(prevHeadingLineNumber);
|
||||
}
|
||||
needBlankLine = false;
|
||||
}
|
||||
prevMaxLineIndex = Math.max(prevMaxLineIndex, token.lines[1]);
|
||||
prevMaxLineIndex = Math.max(prevMaxLineIndex, token.map[1]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -456,7 +457,7 @@ module.exports = [
|
|||
var hasTopLevelHeading = false;
|
||||
filterTokens(params.tokens, "heading_open")
|
||||
.forEach(function forToken(token) {
|
||||
if (token.hLevel === 1) {
|
||||
if (token.tag === "h1") {
|
||||
if (hasTopLevelHeading) {
|
||||
errors.push(token.lineNumber);
|
||||
} else if (token.lineNumber === 1) {
|
||||
|
|
@ -553,7 +554,7 @@ module.exports = [
|
|||
var ulMulti = params.options.ul_multi || 1;
|
||||
var olMulti = params.options.ol_multi || 1;
|
||||
flattenLists(params.tokens).forEach(function forList(list) {
|
||||
var lineCount = list.lastLineIndex - list.open.lines[0];
|
||||
var lineCount = list.lastLineIndex - list.open.map[0];
|
||||
var allSingle = lineCount === list.items.length;
|
||||
var expectedSpaces = list.ordered ?
|
||||
(allSingle ? olSingle : olMulti) :
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
"example": "cd example & node standalone.js & grunt markdownlint & gulp markdownlint"
|
||||
},
|
||||
"dependencies": {
|
||||
"markdown-it": "^3.0.7"
|
||||
"markdown-it": "^4.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^0.15.0",
|
||||
|
|
|
|||
|
|
@ -514,7 +514,7 @@ module.exports.doc = function doc(test) {
|
|||
var inHeading = false;
|
||||
var rule = null;
|
||||
md.parse(contents, {}).forEach(function forToken(token) {
|
||||
if ((token.type === "heading_open") && (token.hLevel === 2)) {
|
||||
if ((token.type === "heading_open") && (token.tag === "h2")) {
|
||||
inHeading = true;
|
||||
} else if (token.type === "heading_close") {
|
||||
inHeading = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue