List Rules
List rules ensure consistent formatting, indentation, and structure for both ordered and unordered lists.
Rules in This Category
Rule | Description | Fix |
---|---|---|
MD004 | Unordered list style (consistent markers) | ❌ |
MD005 | Inconsistent indentation for list items at the same level | ❌ |
MD006 | Consider starting lists at the beginning of the line | ❌ |
MD007 | Unordered list indentation | ❌ |
MD029 | Ordered list item prefix | ❌ |
MD030 | Spaces after list markers | ✅ |
MD031 | Fenced code blocks should be surrounded by blank lines | ❌ |
MD032 | Lists should be surrounded by blank lines | ❌ |
List Basics
Unordered Lists
Markdown supports three markers for unordered lists:
* Item with asterisk
- Item with dash
+ Item with plus
All render the same, but consistency is important.
Ordered Lists
1. First item
2. Second item
3. Third item
Or with lazy numbering:
1. First item
1. Second item
1. Third item
Best Practices
Consistent Markers
Pick one unordered list marker and stick with it:
Good:
* First item
* Second item
* Nested item
* Another nested
* Third item
Bad:
* First item
- Second item
+ Nested item
* Another nested
+ Third item
Proper Indentation
Use consistent indentation for nested lists:
2-space indentation:
* Parent item
* Child item
* Grandchild item
* Another child
* Another parent
4-space indentation:
* Parent item
* Child item
* Grandchild item
* Another child
* Another parent
Spacing After Markers
Maintain consistent spacing after list markers:
Good (single space):
* Item one
* Item two
1. First item
2. Second item
Bad (inconsistent):
*Item one
* Item two
1.First item
2. Second item
Complex List Structures
Multi-line List Items
For list items with multiple paragraphs:
1. First item with multiple paragraphs.
This is still part of the first item. Note the blank line above
and the indentation.
2. Second item.
* Nested list in second item
* Another nested item
3. Third item.
Lists with Code Blocks
Proper indentation for code blocks in lists:
1. Install the package:
```bash
npm install mdbook-lint
-
Configure the linter:
{ "rules": { "MD009": true } }
-
Run the linter.
### Task Lists
GitHub Flavored Markdown task lists:
```markdown
- [x] Completed task
- [ ] Incomplete task
- [ ] Another todo
- [x] Completed subtask
- [ ] Incomplete subtask
Common Issues and Solutions
Issue: Inconsistent List Indentation
Problem:
* Item 1
* Nested with 2 spaces
* Deep nested with 4 spaces
* Wrong indentation
* More inconsistency
Solution:
* Item 1
* Nested with 2 spaces
* Consistent 2-space indent
* All items aligned
* Deeper nesting maintains pattern
Issue: Missing Blank Lines Around Lists
Problem:
Some paragraph text
* List starts immediately
* No separation
Paragraph continues here
Solution:
Some paragraph text
* List has blank line before
* Proper separation
Paragraph has blank line after list
Issue: Lazy Numbering Problems
Problem with lazy numbering:
1. First item
1. Second item
5. Oops, wrong number
1. Fourth item
Solution 1 (sequential):
1. First item
2. Second item
3. Third item
4. Fourth item
Solution 2 (all ones):
1. First item
1. Second item
1. Third item
1. Fourth item
Accessibility Considerations
Proper list formatting improves accessibility:
- Screen Readers: Announce list structure and item count
- Navigation: Users can skip between lists
- Context: Proper nesting conveys relationships
- Semantics: Lists convey meaning beyond visual formatting
mdBook-Specific Considerations
In mdBook projects:
- Table of Contents: Lists in SUMMARY.md define book structure
- Navigation: Nested lists create hierarchical navigation
- Rendering: List formatting affects HTML output
- Search: List items are indexed for search
Configuration Examples
Enforce Consistent Unordered List Style
[MD004]
style = "asterisk" # or "dash" or "plus"
Set List Indentation
[MD007]
indent = 2 # or 4, or any consistent value
Configure Ordered List Style
[MD029]
style = "ordered" # or "one" for all 1s
Spaces After List Markers
[MD030]
ul_single = 1 # Spaces after unordered list marker
ol_single = 1 # Spaces after ordered list marker
ul_multi = 1 # Spaces after marker for multi-line items
ol_multi = 1 # Spaces after marker for multi-line items
Related Rules
- MD013 - Line length (affects long list items)
- MD022 - Blank lines (around list blocks)
- MD031 - Code blocks in lists
- MD032 - Blank lines around lists