mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02: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" ],
|
||||
"function": function MD005(params, onError) {
|
||||
shared.flattenLists().forEach(function forList(list) {
|
||||
var indent = shared.indentFor(list.items[0]);
|
||||
list.items.forEach(function forItem(item) {
|
||||
shared.addErrorDetailIf(onError, item.lineNumber, indent,
|
||||
shared.addErrorDetailIf(onError, item.lineNumber, list.indent,
|
||||
shared.indentFor(item), null,
|
||||
shared.rangeFromRegExp(item.line, shared.listItemMarkerRe));
|
||||
});
|
||||
|
|
|
@ -13,7 +13,7 @@ module.exports = {
|
|||
shared.flattenLists().forEach(function forList(list) {
|
||||
if (list.unordered && !list.nesting) {
|
||||
shared.addErrorDetailIf(onError, list.open.lineNumber,
|
||||
0, shared.indentFor(list.open), null,
|
||||
0, list.indent, null,
|
||||
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" ],
|
||||
"function": function MD007(params, onError) {
|
||||
var optionsIndent = params.config.indent || 2;
|
||||
var prevIndent = 0;
|
||||
shared.flattenLists().forEach(function forList(list) {
|
||||
if (list.unordered && list.parentsUnordered) {
|
||||
var indent = shared.indentFor(list.open);
|
||||
if (indent > prevIndent) {
|
||||
shared.addErrorDetailIf(onError, list.open.lineNumber,
|
||||
prevIndent + optionsIndent, indent, null,
|
||||
shared.rangeFromRegExp(list.open.line, shared.listItemMarkerRe));
|
||||
}
|
||||
prevIndent = indent;
|
||||
if (list.unordered && list.parentsUnordered && list.indent) {
|
||||
shared.addErrorDetailIf(onError, list.open.lineNumber,
|
||||
list.parentIndent + optionsIndent, list.indent, null,
|
||||
shared.rangeFromRegExp(list.open.line, shared.listItemMarkerRe));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -99,10 +99,11 @@ module.exports.escapeForRegExp = function escapeForRegExp(str) {
|
|||
};
|
||||
|
||||
// Returns the indent for a token
|
||||
module.exports.indentFor = function indentFor(token) {
|
||||
function indentFor(token) {
|
||||
var line = token.line.replace(/^[\s>]*(> |>)/, "");
|
||||
return line.length - trimLeft(line).length;
|
||||
};
|
||||
}
|
||||
module.exports.indentFor = indentFor;
|
||||
|
||||
// Returns the heading style for a heading token
|
||||
module.exports.headingStyleFor = function headingStyleFor(token) {
|
||||
|
@ -180,6 +181,8 @@ function makeTokenCache(params) {
|
|||
"parentsUnordered": !current ||
|
||||
(current.unordered && current.parentsUnordered),
|
||||
"open": token,
|
||||
"indent": indentFor(token),
|
||||
"parentIndent": (current && current.indent) || 0,
|
||||
"items": [],
|
||||
"nesting": stack.length - 1,
|
||||
"lastLineIndex": -1,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
* Item
|
||||
* Item {MD007}
|
||||
* 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