diff --git a/demo/markdownlint-browser.js b/demo/markdownlint-browser.js index aade2f47..e1f9a55d 100644 --- a/demo/markdownlint-browser.js +++ b/demo/markdownlint-browser.js @@ -2212,12 +2212,13 @@ module.exports = { "function": function MD007(params, onError) { var indent = Number(params.config.indent || 2); var startIndented = !!params.config.start_indented; + var startIndent = Number(params.config.start_indent || indent); flattenedLists().forEach(function (list) { if (list.unordered && list.parentsUnordered) { list.items.forEach(function (item) { var lineNumber = item.lineNumber, line = item.line; - var expectedNesting = list.nesting + (startIndented ? 1 : 0); - var expectedIndent = expectedNesting * indent; + var expectedIndent = (startIndented ? startIndent : 0) + + (list.nesting * indent); var actualIndent = indentFor(item); var range = null; var editColumn = 1; diff --git a/doc/Rules.md b/doc/Rules.md index bb3d6844..9b968c7c 100644 --- a/doc/Rules.md +++ b/doc/Rules.md @@ -292,7 +292,11 @@ Tags: bullet, ul, indentation Aliases: ul-indent -Parameters: indent, start_indented (number; default 2, boolean; default false) + + +Parameters: indent, start_indented, start_indent (number; default 2, boolean; default false, number; defaults to indent) + + Fixable: Most violations can be fixed by tooling @@ -319,7 +323,9 @@ rule). The `start_indented` parameter allows the first level of lists to be indented by the configured number of spaces rather than starting at zero (the inverse of -MD006). +MD006). The `start_indent` parameter allows the first level of lists to be indented +by a different number of spaces than the rest (ignored when `start_indented` is not +set). Rationale: Indenting by 2 spaces allows the content of a nested list to be in line with the start of the content of the parent list when a single space is diff --git a/lib/md007.js b/lib/md007.js index 0a02b618..1bb6f342 100644 --- a/lib/md007.js +++ b/lib/md007.js @@ -13,12 +13,14 @@ module.exports = { "function": function MD007(params, onError) { const indent = Number(params.config.indent || 2); const startIndented = !!params.config.start_indented; + const startIndent = Number(params.config.start_indent || indent); flattenedLists().forEach((list) => { if (list.unordered && list.parentsUnordered) { list.items.forEach((item) => { const { lineNumber, line } = item; - const expectedNesting = list.nesting + (startIndented ? 1 : 0); - const expectedIndent = expectedNesting * indent; + const expectedIndent = + (startIndented ? startIndent : 0) + + (list.nesting * indent); const actualIndent = indentFor(item); let range = null; let editColumn = 1; diff --git a/schema/.markdownlint.jsonc b/schema/.markdownlint.jsonc index 3cea1729..a7bfa5b2 100644 --- a/schema/.markdownlint.jsonc +++ b/schema/.markdownlint.jsonc @@ -39,7 +39,9 @@ // Spaces for indent "indent": 2, // Whether to indent the first level of the list - "start_indented": false + "start_indented": false, + // Spaces for first level indent (when start_indented is set) + "start_indent": 2 }, // MD009/no-trailing-spaces - Trailing spaces diff --git a/schema/.markdownlint.yaml b/schema/.markdownlint.yaml index b8960a4a..ce92ec5c 100644 --- a/schema/.markdownlint.yaml +++ b/schema/.markdownlint.yaml @@ -36,6 +36,8 @@ MD007: indent: 2 # Whether to indent the first level of the list start_indented: false + # Spaces for first level indent (when start_indented is set) + start_indent: 2 # MD009/no-trailing-spaces - Trailing spaces MD009: diff --git a/schema/build-config-schema.js b/schema/build-config-schema.js index 76cfd539..f0585e19 100644 --- a/schema/build-config-schema.js +++ b/schema/build-config-schema.js @@ -107,6 +107,12 @@ rules.forEach(function forRule(rule) { "description": "Whether to indent the first level of the list", "type": "boolean", "default": false + }, + "start_indent": { + "description": + "Spaces for first level indent (when start_indented is set)", + "type": "integer", + "default": 2 } }; break; diff --git a/schema/markdownlint-config-schema.json b/schema/markdownlint-config-schema.json index e3f36409..5c974fd7 100644 --- a/schema/markdownlint-config-schema.json +++ b/schema/markdownlint-config-schema.json @@ -238,6 +238,11 @@ "description": "Whether to indent the first level of the list", "type": "boolean", "default": false + }, + "start_indent": { + "description": "Spaces for first level indent (when start_indented is set)", + "type": "integer", + "default": 2 } }, "additionalProperties": false @@ -259,6 +264,11 @@ "description": "Whether to indent the first level of the list", "type": "boolean", "default": false + }, + "start_indent": { + "description": "Spaces for first level indent (when start_indented is set)", + "type": "integer", + "default": 2 } }, "additionalProperties": false diff --git a/test/list-indentation-start-indent-indent.md b/test/list-indentation-start-indent-indent.md new file mode 100644 index 00000000..727cc951 --- /dev/null +++ b/test/list-indentation-start-indent-indent.md @@ -0,0 +1,35 @@ +# List Indentation start_indent/indent + + * item 1 + * item 2 + * item 2.1 + * item 2.2 + * item 2.2.1 + * item 2.3 + * item 2.3.1 {MD007} + * item 3 + * item 4 {MD005} {MD007} + +Text + + * item 1 {MD007} + * item 2 {MD007} + * item 2.1 + * item 2.2 + * item 2.2.1 + +Text + + * item 1 + * item 2 + * item 2.1 {MD007} + * item 2.2 {MD007} + * item 2.2.1 {MD007} + + diff --git a/test/list-indentation-start-indent-no-indent.md b/test/list-indentation-start-indent-no-indent.md new file mode 100644 index 00000000..27ec4acd --- /dev/null +++ b/test/list-indentation-start-indent-no-indent.md @@ -0,0 +1,34 @@ +# List Indentation start_indent/no indent + + * item 1 + * item 2 + * item 2.1 + * item 2.2 + * item 2.2.1 + * item 2.3 + * item 2.3.1 {MD007} + * item 3 + * item 4 {MD005} {MD007} + +Text + + * item 1 {MD007} + * item 2 {MD007} + * item 2.1 {MD007} + * item 2.2 {MD007} + * item 2.2.1 {MD007} + +Text + + * item 1 + * item 2 + * item 2.1 {MD007} + * item 2.2 {MD007} + * item 2.2.1 {MD007} + + diff --git a/test/list-indentation-start-indented.json b/test/list-indentation-start-indented-indent.json similarity index 100% rename from test/list-indentation-start-indented.json rename to test/list-indentation-start-indented-indent.json diff --git a/test/list-indentation-start-indented.md b/test/list-indentation-start-indented-indent.md similarity index 100% rename from test/list-indentation-start-indented.md rename to test/list-indentation-start-indented-indent.md diff --git a/test/list-indentation-start-indented-no-indent.md b/test/list-indentation-start-indented-no-indent.md new file mode 100644 index 00000000..b30e1b6a --- /dev/null +++ b/test/list-indentation-start-indented-no-indent.md @@ -0,0 +1,46 @@ +# List Indentation - Start Indented/No Indent + + * item 1 + * item 2 + * item 2.1 + * item 2.2 + * item 2.2.1 + * item 2.3 + * item 3 + +## Disallowed List Indentation - Starts at Zero + +* item 1 {MD007} +* item 2 {MD007} + * item 2.1 {MD007} + * item 2.2 {MD007} + * item 2.2.1 {MD007} + * item 2.3 {MD007} +* item 3 {MD007} + +## Disallowed List Indentation - Starts at One + + * item 1 {MD007} + * item 2 {MD007} + * item 2.1 {MD007} + * item 2.2 {MD007} + * item 2.2.1 {MD007} + * item 2.3 {MD007} + * item 2.3.1 + * item 3 {MD007} + +## Disallowed List Indentation - Starts at Three + + * item 1 {MD007} + * item 2 {MD007} + * item 2.1 {MD007} + * item 2.2 {MD007} + * item 2.2.1 {MD007} + * item 2.3 {MD007} + * item 3 {MD007} + +