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