mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-04-25 01:05:55 +03:00
[GH-ISSUE #977] New rule: Prevent lazy continuation lines #2425
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#2425
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 @skwde on GitHub (Sep 15, 2023).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/977
This is somewhat related to
MD032and emerged from https://github.com/DavidAnson/markdownlint/issues/972Lazy line conditions make the markdown file less readable. That is because
behave the same like standard lists
Even more confusing/weird is the behavior when using multiple levels like
where
ghigoes to the 2nd indent level.In addition, as mentioned in https://github.com/DavidAnson/markdownlint/blob/main/doc/md032.md some parsers do not parse lists if they are not surrounded by blank lines.
MD032is however only concerned with the starting line because it cannot know when it should be a lazy line continuation or when the list is done.@BlaineEXE commented on GitHub (Apr 29, 2024):
Ditto. This would be a great add :)
@amyq commented on GitHub (Jun 3, 2024):
Chiming in here. My coworker Marcel (@ravlen) and I have been talking about this problem over in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/155088 for the GitLab docs. He's trying to construct a rule in Vale to error out on (what I now know are) lazy continuation lines.
While lazy continuation lines are valid CommonMark, I agree with Marcel - when managing Markdown-formatted docs at scale, our technical writing team would find it helpful to prevent them from creeping into our docs. It feels like a good rule to leave off by default, but make available to users who need every scrap of scannability improvements they can get.
@Ravlen commented on GitHub (Jun 4, 2024):
Yeah, 👍 from me, though I think this is a repeat of the request in https://github.com/DavidAnson/markdownlint/issues/344, where I've got a non-breaking change suggestion that could work in https://github.com/DavidAnson/markdownlint/issues/344#issuecomment-1891542874
@wwarriner commented on GitHub (Jun 6, 2025):
In preparation for a fix, we'd need to formalize what it means to be a lazy continuation line to constrain the problem space. Here is my first attempt at a formalization.
Presumably the parser already knows what content is part of list item and that information is available for rules to examine in markdownlint. This would enable checking items (1)-(4). Item (5) is not yet accounted for, and what we need to consider.
I wrote the last item like I did because it allows us to account for block quotes implicitly. Nothing in the spec appears to allow other contexts starting on the same line as a list item, so we need only consider block quotes. If another context starts on the next line, then other parts of the spec apply, that line isn't part of the list item (unless indented appropriately), and this rule doesn't apply. If another context starts after one or more blank lines, then this rule doesn't apply by item (3).
As for fixes, consider (5). If we know the starting column of the parent list item, and the starting column of the lazy continuation line, we can increase the indent of the lazy continuation line by the difference, to match the parent list item. Repeat this for all lazy continuation lines of the current list item.
Have I missed anything?
Edit: Some parsers may treat any amount of indentation on subsequent lines to be part of the list item. So we may also need to consider any case where indentation doesn't match parent list item content.
@wwarriner commented on GitHub (Jun 26, 2025):
Here is a first attempt at a custom rule. I've got working tests and everything, but I haven't tried it on a documentation repository I manage yet.
https://github.com/wwarriner/markdownlint-rule-lazy-continuation-lines
I welcome feedback on the code, I'm a complete novice at JS.
@DavidAnson commented on GitHub (Jun 27, 2025):
@wwarriner, what I saw briefly looked was pretty much as I'd expect. You may want to consider importing
helpers/micromarkfor some token utility functions that could possibly replace some of what you have. Thanks for sharing!@wwarriner commented on GitHub (Jun 27, 2025):
@DavidAnson Thank you, good to know. I'll look into the helpers, that's great!
JS (especially module management) is all very new to me, so I'd like to pick your brain about some things to facilitate development of future rules.
vscode-markdownlint, as I'm seeing an error. https://github.com/DavidAnson/vscode-markdownlint/issues/386npmas a package? What sort of maintenance cost (time and effort) should I expect?markdownlintrules, and what would I need to do to make that happen?@DavidAnson commented on GitHub (Jun 27, 2025):
The Node and npm documentation sites are both good resources to get answers to your questions. There are probably some blogs that take a friendlier approach to this, but I don't know of any to recommend offhand. Other than syntax, I don't think the philosophy of exports in Node is much different than other environments.
Regarding the specific question about publishing your custom rule, I would recommend having a look at this custom rule I previously wrote and published because it's about as simple as possible: https://github.com/DavidAnson/markdownlint-rule-extended-ascii
Before adding this rule to the core library, I would want to see it used in the real world for a while to work out any kinks. That's also an opportunity to convert to the helper functions I reference above because I wouldn't want duplication in the core library. Finally, I'd want to review the code for style and behavior. But the first step is definitely to demonstrate utility and versatility in the real world. :)
@Ravlen commented on GitHub (Nov 26, 2025):
@DavidAnson Coming back to this after some more cleanup work in our docs and I wonder if there would be interest in a more targeted rule for one case of lazy continuation lines in lists. I'm realizing that lazy continuation for the last list item is more problematic than the other list items. There is more ambiguity here, which I think is a good reason to add it to the main markdownlint rules.
If the last line is a lazy continuation, it could be that the author is trying to do one of two things, and parsers can't determine which one the author is intending:
For example:
It's ambiguous what the author is intending. In all cases, lazy continuation should be avoided at the end of the list, in preference of either:
Then the accepted options would be either:
@DavidAnson commented on GitHub (Nov 26, 2025):
@Ravlen, have you tried the implementation above?
@Ravlen commented on GitHub (Nov 28, 2025):
@DavidAnson Unfortunately, I couldn't get it to work, there were dependency issues for me (could very possibly on my end).
For a POC, I used AI to generate something workable (I'm not an engineer and can't write code). I'm not sure I would submit the AI-generated code for review at GitLab, because I can't guarantee the quality of it, but it at least demonstrated the value it would have for me: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/214400
@DavidAnson commented on GitHub (Nov 28, 2025):
@Ravlen, AI submissions are against the policies of this project.
@Ravlen commented on GitHub (Nov 28, 2025):
@DavidAnson Yup! Which is why it's just a POC (to see how much of an impact it would have on our large docs project) and not submitted for review here (or anywhere) 🙇