mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-04-25 09:16:02 +03:00
[GH-ISSUE #43] Add rule for checking proper formating of fenced code block inside lists #35
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#35
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 @pascalberger on GitHub (Jan 18, 2017).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/43
Writing fenced code blocks inside of ordered and unordered lists might not be the most obvious thing. A rule indicating mistakes might be really helpful in this case.
Stuff to check:
@twocs commented on GitHub (May 30, 2025):
I would say that the original problem is difficult to solve. However, there are currently two conflicting rules regarding fenced code blocks inside (numbered) lists. The new line before and following a fenced code block rule, but if a numbered list has a blank line before the subsequent number, then there's a warning that the number kept incrementing.
I can avoid the MD031 by adding the blank lines (but they must not be indented). However, I'm unable to avoid MD029 except by annotations. This is the way I currently embed code into my numbered lists.
Note that the first comment simply guides markdownlint to consider the code block as being surrounded by blank lines, it doesn't actually require explicit mention of MD031. On the other hand, the second markdownlint-disable-next-line must specifically disable MD029.
@DavidAnson commented on GitHub (May 30, 2025):
Properly indenting your original example produces no warnings:
https://dlaa.me/markdownlint/#%25m%23%20Example%0A%0A1.%20My%20bulleted%20list%20includes%20some%20important%20code%0A2.%20This%20is%20my%20second%20point%0A%20%20%201.%20Code%20must%20be%20indented%20to%20be%20kept%20with%20this%20list%20item.%20It%20must%20be%20surrounded%20by%20blank%20lines%20to%20avoid%202.1.%20But%20a%20blank%20line%20is%20also%20a%20signal%20that%20the%20numbering%20does%20not%20continue.%0A%0A%20%20%20%20%20%20%60%60%60json%0A%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22ID%22%3A%2012345%2C%0A%20%20%20%20%20%20%20%20%22Price%22%3A%20100000%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%60%60%60%0A%0A%20%20%202.%20If%20I%20want%20the%20number%202%20here%2C%20this%20line%20sees%20a%20warning%20for%20MD029.%0A
@twocs commented on GitHub (May 30, 2025):
Yes, looks like we simply need an extra indent for the code block as well as surrounding it with blank lines. Additionally I missed that the example for MD029 does explain how to add the extra indent for code blocks.
In regards to the original issue report, I'm unclear how you could make the rules any clearer than they already are. However, I do agree with the statement: "Writing fenced code blocks inside of ordered and unordered lists might not be the most obvious thing". On the other hand, now that I know how it works I don't have any issue.
@DavidAnson commented on GitHub (May 30, 2025):
Yeah, that's the challenge: it's easy when you know and hard when you don't. :) I don't have a great idea for how to make a rule like this reliable, but it would be nice to have and so I've kept the issue open for tracking. Glad you got your issue sorted out!