mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-04-25 09:16:02 +03:00
[GH-ISSUE #138] Add rule for ordered list indentation (ol-indent) #1964
Labels
No labels
bug
enhancement
enhancement
enhancement
fixed in next
fixed in next
fixed in next
new rule
new rule
new rule
pull-request
question
refactoring
refactoring
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/markdownlint#1964
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @gandalfsaxe on GitHub (Jul 22, 2018).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/138
From the discussion in #137 we seemed to agree that a rule for ordered list indentation (alias:
ol-indent) is oddly missing. Rule MD007 sets a default spaces to 2 for ordered sublists, however there is no such constraint on unordered sublists.So while current we would only get a warning to the first (unordered) list:
this issue suggests that
ol-indentwould also gives warning for the second (ordered) list for using 4 spaces, whereas the correct would be 3.@TheJaredWilcurt commented on GitHub (Aug 25, 2019):
Would this also handle this case?
@jthomerson commented on GitHub (Dec 29, 2019):
Any update on this rule? If a PR were created that mimicked the behavior of ul-indent, but worked with ol's, would that be reviewed and accepted?
@DavidAnson commented on GitHub (Dec 29, 2019):
I have no objections to this proposed rule, but have not gotten around to adding it myself. An implementation that is structured like MD007 but applies to ordered lists seems like it would be suitable here. I’d be happy to review such a PR according to the contribution guidelines.
@mschoettle commented on GitHub (Mar 16, 2025):
Would it make sense to have a generic indentation rule?
For example:
Does not render the code block indented with the ul item. Maybe it depends on the renderer though.
In any case, it could be helpful to enforce general consistent indentation.
@DavidAnson commented on GitHub (Mar 16, 2025):
FYI, the example immediately above should/does render the code fence as part of the list item (per CommonMark spec): https://dlaa.me/markdownlint/#%25m%23%20Example%0A%0A*%20A%20ul%20item%0A%0A%20%20%60%60%60python%0A%20%20print('Hello%20World')%0A%20%20%60%60%60%0A%0A%20%20Still%20item%0A%0ANew%20paragraph%0A%0A%60%60%60python%0Aprint('Hello%20World')%0A%60%60%60%0A
@mschoettle commented on GitHub (Mar 17, 2025):
Indeed. I use
mkdocswhich usespython-markdown. Based on the documentation one difference is that it enforces the indentation to 4: https://python-markdown.github.io/#differences:Are you open to adding a general indentation rule instead of adding
ol-indent(or both)?@DavidAnson commented on GitHub (Mar 17, 2025):
If one wants to start list item content at column 5, that is valid and supported by CommonMark: https://dlaa.me/markdownlint/#%25m%23%20Example%0A%0A*%20%20%20List%20item%20starting%20at%20column%205%0A%0A%20%20%20%20%60%60%60python%0A%20%20%20%20print('Hello%20World')%0A%20%20%20%20%60%60%60%0A
Your configuration is starting to sound like Prettier's 4-space tab width which is discussed more here: https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/Prettier.md#list-item-indentation
I'm not sure what a "general indentation" rule would be as the choice is not always flexible (ex: code fences at 4).
@mschoettle commented on GitHub (Mar 19, 2025):
Indeed. Setting
ul-indentto 4 works for the list item, however, the "content" of the list item itself is not ensured to be at 4 as well. Similarly, for ul-indent: 2, if additional content is (incorrectly) indented at 1 space instead there is no violation (forul-indent: 41-3 spaces cause that same behaviour).https://dlaa.me/markdownlint/#%25m%23%20Example%0A%0A*%20list%20item%0A%20%20spanning%20text%0A%20%20over%20multiple%20lines%0A%0A%20%60%60%60python%0A%20print('Hello%20World')%0A%20%60%60%60%0A%0A%20another%20sentence%20part%20of%20the%20first%20list%20item%0A%0A*%20list%20item%202%0A%0A%20%20sentence%0A%0ANew%20paragraph.%0A
I realize now that that has nothing to do with "general indentation" :)
Since it is not relevant to this issue I can open a new one to discuss it there.
@DavidAnson commented on GitHub (Mar 19, 2025):
Okay. FYI that I recently had a somewhat related discussion and the second half of the messages in this issue is relevant: https://github.com/DavidAnson/markdownlint/issues/1473
Specifically, I didn't see an easy way to get list item indent from the parser. However in your case, I wouldn't even be able to trust the parser because you want to pick up on cases where TOO FEW spaces are used and the list ends early. That would push the implementation over toward regular expressions which is both a blessing and a curse. :)