mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Fix MD007/ul-indent to use parent indent instead of previous indent (fixes #106).
This commit is contained in:
parent
748c8cac17
commit
40ace5bb5e
6 changed files with 58 additions and 15 deletions
|
|
@ -10,9 +10,8 @@ module.exports = {
|
||||||
"tags": [ "bullet", "ul", "indentation" ],
|
"tags": [ "bullet", "ul", "indentation" ],
|
||||||
"function": function MD005(params, onError) {
|
"function": function MD005(params, onError) {
|
||||||
shared.flattenLists().forEach(function forList(list) {
|
shared.flattenLists().forEach(function forList(list) {
|
||||||
var indent = shared.indentFor(list.items[0]);
|
|
||||||
list.items.forEach(function forItem(item) {
|
list.items.forEach(function forItem(item) {
|
||||||
shared.addErrorDetailIf(onError, item.lineNumber, indent,
|
shared.addErrorDetailIf(onError, item.lineNumber, list.indent,
|
||||||
shared.indentFor(item), null,
|
shared.indentFor(item), null,
|
||||||
shared.rangeFromRegExp(item.line, shared.listItemMarkerRe));
|
shared.rangeFromRegExp(item.line, shared.listItemMarkerRe));
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ module.exports = {
|
||||||
shared.flattenLists().forEach(function forList(list) {
|
shared.flattenLists().forEach(function forList(list) {
|
||||||
if (list.unordered && !list.nesting) {
|
if (list.unordered && !list.nesting) {
|
||||||
shared.addErrorDetailIf(onError, list.open.lineNumber,
|
shared.addErrorDetailIf(onError, list.open.lineNumber,
|
||||||
0, shared.indentFor(list.open), null,
|
0, list.indent, null,
|
||||||
shared.rangeFromRegExp(list.open.line, shared.listItemMarkerRe));
|
shared.rangeFromRegExp(list.open.line, shared.listItemMarkerRe));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
13
lib/md007.js
13
lib/md007.js
|
|
@ -10,16 +10,11 @@ module.exports = {
|
||||||
"tags": [ "bullet", "ul", "indentation" ],
|
"tags": [ "bullet", "ul", "indentation" ],
|
||||||
"function": function MD007(params, onError) {
|
"function": function MD007(params, onError) {
|
||||||
var optionsIndent = params.config.indent || 2;
|
var optionsIndent = params.config.indent || 2;
|
||||||
var prevIndent = 0;
|
|
||||||
shared.flattenLists().forEach(function forList(list) {
|
shared.flattenLists().forEach(function forList(list) {
|
||||||
if (list.unordered && list.parentsUnordered) {
|
if (list.unordered && list.parentsUnordered && list.indent) {
|
||||||
var indent = shared.indentFor(list.open);
|
shared.addErrorDetailIf(onError, list.open.lineNumber,
|
||||||
if (indent > prevIndent) {
|
list.parentIndent + optionsIndent, list.indent, null,
|
||||||
shared.addErrorDetailIf(onError, list.open.lineNumber,
|
shared.rangeFromRegExp(list.open.line, shared.listItemMarkerRe));
|
||||||
prevIndent + optionsIndent, indent, null,
|
|
||||||
shared.rangeFromRegExp(list.open.line, shared.listItemMarkerRe));
|
|
||||||
}
|
|
||||||
prevIndent = indent;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,10 +99,11 @@ module.exports.escapeForRegExp = function escapeForRegExp(str) {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Returns the indent for a token
|
// Returns the indent for a token
|
||||||
module.exports.indentFor = function indentFor(token) {
|
function indentFor(token) {
|
||||||
var line = token.line.replace(/^[\s>]*(> |>)/, "");
|
var line = token.line.replace(/^[\s>]*(> |>)/, "");
|
||||||
return line.length - trimLeft(line).length;
|
return line.length - trimLeft(line).length;
|
||||||
};
|
}
|
||||||
|
module.exports.indentFor = indentFor;
|
||||||
|
|
||||||
// Returns the heading style for a heading token
|
// Returns the heading style for a heading token
|
||||||
module.exports.headingStyleFor = function headingStyleFor(token) {
|
module.exports.headingStyleFor = function headingStyleFor(token) {
|
||||||
|
|
@ -180,6 +181,8 @@ function makeTokenCache(params) {
|
||||||
"parentsUnordered": !current ||
|
"parentsUnordered": !current ||
|
||||||
(current.unordered && current.parentsUnordered),
|
(current.unordered && current.parentsUnordered),
|
||||||
"open": token,
|
"open": token,
|
||||||
|
"indent": indentFor(token),
|
||||||
|
"parentIndent": (current && current.indent) || 0,
|
||||||
"items": [],
|
"items": [],
|
||||||
"nesting": stack.length - 1,
|
"nesting": stack.length - 1,
|
||||||
"lastLineIndex": -1,
|
"lastLineIndex": -1,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
* Item
|
* Item
|
||||||
* Item {MD007}
|
* Item {MD007}
|
||||||
* Item {MD005}
|
* Item {MD005}
|
||||||
* Item
|
* Item {MD007}
|
||||||
46
test/list-indentation.md
Normal file
46
test/list-indentation.md
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
# list-indentation
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
- Item
|
||||||
|
- Item {MD007}
|
||||||
|
- Item
|
||||||
|
- Item {MD007}
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
- Item
|
||||||
|
- Item
|
||||||
|
- Item
|
||||||
|
- Item {MD007}
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
- Item
|
||||||
|
- Item {MD007}
|
||||||
|
- Item
|
||||||
|
- Item
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
- Item
|
||||||
|
- Item
|
||||||
|
- Item {MD005}
|
||||||
|
- Item
|
||||||
|
- Item {MD005}
|
||||||
|
- Item {MD005}
|
||||||
|
- Item
|
||||||
|
- Item
|
||||||
|
- Item
|
||||||
|
- Item {MD005}
|
||||||
|
- Item
|
||||||
|
- Item
|
||||||
|
- Item {MD007}
|
||||||
|
- Item
|
||||||
|
- Item
|
||||||
|
- Item
|
||||||
|
- Item {MD007}
|
||||||
|
- Item
|
||||||
|
- Item {MD005}
|
||||||
|
|
||||||
|
Text
|
||||||
Loading…
Add table
Add a link
Reference in a new issue