List Formatting Guide¶
Purpose: This guide provides examples of common list formatting issues and their fixes in Markdown documentation.
Rule: Blank Line Required After Headers¶
CRITICAL: In Markdown, headers (both markdown headers # and bold headers **Header**:) must be followed by a
blank line before any list starts. Without this blank line, Markdown parsers may not render lists correctly.
Common Formatting Issues¶
Issue 1: Markdown Header Followed by Bullet List (No Blank Line)¶
Incorrect:
Correct:
Issue 2: Markdown Header Followed by Numbered List (No Blank Line)¶
Incorrect:
Correct:
Issue 3: Bold Header Followed by Bullet List (No Blank Line)¶
Incorrect:
Correct:
Issue 4: Bold Header Followed by Numbered List (No Blank Line)¶
Incorrect:
Correct:
Issue 5: Multiple Levels of Headers¶
Incorrect:
Correct:
Issue 6: Header with Bold List Items¶
Incorrect:
Correct:
Issue 7: Header Followed by Nested Lists¶
Incorrect:
Correct:
Issue 8: Header Followed by Mixed Content (Text + List)¶
Incorrect:
Correct:
Issue 9: Bold Header with Colon Followed by List¶
Incorrect:
Correct:
Issue 10: Header Followed by Code Block Then List¶
Incorrect:
- Note 1
- Note 2
- Note 1
- Note 2
## Detection Patterns
### Pattern 1: Markdown Header Pattern
**Regex**: `^#{1,6}\s+.*`
**Check**: Next line should be blank before list starts.
**Example**:
```markdown
## Header
- List item # WRONG - missing blank line
Fixed:
Pattern 2: Bold Header Pattern¶
Regex: ^\*\*.*:\*\*$
Check: Next line should be blank before list starts.
Example:
Fixed:
Pattern 3: List Item Pattern¶
Regex: ^[-*+]\s+ or ^\d+\.\s+
Check: Previous line should be blank if it's a header.
Example:
Fixed:
Automated Fix Script¶
Python Script for Detection and Fix¶
import re
def fix_list_formatting(file_path):
"""
Fixes list formatting issues by adding blank lines after headers
that are immediately followed by lists.
"""
with open(file_path, 'r') as f:
lines = f.readlines()
fixed_count = 0
i = 0
while i < len(lines) - 1:
line = lines[i].rstrip()
next_line = lines[i + 1].rstrip() if i + 1 < len(lines) else ""
# Check if it's a markdown header
is_markdown_header = re.match(r'^#{1,6}\s+', line)
# Check if it's a bold header
is_bold_header = re.match(r'^\*\*.*:\*\*$', line)
if is_markdown_header or is_bold_header:
# Check if next line is a list item
is_list = (
re.match(r'^[-*+]\s+', next_line) or
re.match(r'^\d+\.\s+', next_line)
)
if is_list:
# Check if there's already a blank line
if next_line != '':
# Insert blank line after header
lines.insert(i + 1, '\n')
fixed_count += 1
i += 2 # Skip the inserted line
continue
i += 1
if fixed_count > 0:
with open(file_path, 'w') as f:
f.writelines(lines)
print(f"Fixed {fixed_count} formatting issues in {file_path}")
else:
print(f"No formatting fixes needed in {file_path}")
return fixed_count
# Usage
if __name__ == '__main__':
fix_list_formatting('your-file.md')
Bash/AWK Script for Detection¶
#!/bin/bash
# Detect list formatting issues
file="$1"
# Find headers followed by lists without blank lines
awk '
/^#{1,6}\s+|^\*\*.*:\*\*$/ {
header=$0
line_num=NR
getline
if (/^[-*+]|[0-9]+\./) {
print FILENAME ": " line_num ": " header " -> " $0
}
}
' "$file"
Common Scenarios in Documentation¶
Scenario 1: Use Case Documentation¶
Incorrect:
Correct:
Scenario 2: API Documentation¶
Incorrect:
## Endpoints
### GET /api/v1/doctors
**Parameters**:
- `id`: Doctor ID
- `specialty`: Medical specialty
Correct:
## Endpoints
### GET /api/v1/doctors
**Parameters**:
- `id`: Doctor ID
- `specialty`: Medical specialty
Scenario 3: Implementation Plan¶
Incorrect:
Correct:
Scenario 4: Architecture Documentation¶
Incorrect:
## Architecture Layers
1. **API Layer**: REST API
2. **Service Layer**: Business logic
3. **Repository Layer**: Data access
Correct:
## Architecture Layers
1. **API Layer**: REST API
2. **Service Layer**: Business logic
3. **Repository Layer**: Data access
Scenario 5: Requirements Documentation¶
Incorrect:
## Functional Requirements
**FR-1**: Requirement 1
- Sub-requirement 1.1
- Sub-requirement 1.2
**FR-2**: Requirement 2
Correct:
## Functional Requirements
**FR-1**: Requirement 1
- Sub-requirement 1.1
- Sub-requirement 1.2
**FR-2**: Requirement 2
Scenario 6: Implementation Tasks with Numbered Steps¶
Incorrect:
**Tasks**:
1. Create docker/ directory
2. Create Dockerfile.dev and Dockerfile.test
3. Create docker-compose.dev.yml with dev and demo database services
4. Create scripts/build-test-container.sh
5. Make script executable: chmod +x scripts/build-test-container.sh
6. Build test container: ./scripts/build-test-container.sh
7. Start development database: docker-compose -f docker-compose.dev.yml up -d postgres-dev
8. Start demo database: docker-compose -f docker-compose.dev.yml up -d postgres-demo
Correct:
**Tasks**:
1. Create docker/ directory
2. Create Dockerfile.dev and Dockerfile.test
3. Create docker-compose.dev.yml with dev and demo database services
4. Create scripts/build-test-container.sh
5. Make script executable: chmod +x scripts/build-test-container.sh
6. Build test container: ./scripts/build-test-container.sh
7. Start development database: docker-compose -f docker-compose.dev.yml up -d postgres-dev
8. Start demo database: docker-compose -f docker-compose.dev.yml up -d postgres-demo
Edge Cases¶
Edge Case 1: Header with Only Whitespace¶
Incorrect:
Correct:
Edge Case 2: Multiple Headers in Sequence¶
Incorrect:
Correct:
Edge Case 3: Header Followed by Code Block¶
Incorrect:
- Note
- Note
### Edge Case 4: Header Followed by Blockquote
**Incorrect**:
```markdown
## Quote
> This is a quote
- Item
Correct:
Edge Case 5: Header Followed by Table¶
Incorrect:
Correct:
Verification Checklist¶
When fixing list formatting, verify:
- All markdown headers (
#,##,###, etc.) have blank lines before lists - All bold headers (
**Header**:) have blank lines before lists - Nested lists have proper blank lines
- Lists after code blocks have blank lines
- Lists after tables have blank lines
- Lists after blockquotes have blank lines
- Documentation builds successfully (MkDocs, GitHub, etc.)
Testing¶
Test Case 1: Simple Header + List¶
Input:
Expected Output:
Test Case 2: Bold Header + Numbered List¶
Input:
Expected Output:
Test Case 3: Multiple Headers¶
Input:
Expected Output:
Test Case 4: Header + Text + List¶
Input:
Expected Output:
Tools and Commands¶
MkDocs Build Check¶
Manual Verification¶
# Check for headers followed by lists without blank lines
grep -n "^##\|^\*\*" your-file.md | while read line; do
line_num=$(echo $line | cut -d: -f1)
next_line=$(sed -n "${line_num}p" your-file.md)
if [[ $next_line =~ ^[-*+]|[0-9]+\. ]]; then
echo "Potential issue at line $line_num"
fi
done
Summary¶
Key Rule: Always add a blank line after headers (both markdown headers and bold headers) before starting any list.
Common Patterns:
## Header→ blank line →- List item**Header**:→ blank line →1. List item### Subheader→ blank line →- List item
Automation: Use the provided Python or AWK scripts to automatically detect and fix formatting issues.
Verification: Always verify documentation builds successfully after making formatting changes.
Last updated: 2026-01-27