MD020 - No Space Inside Hashes on Closed ATX Style Heading
Severity: Warning
Category: Headings
Auto-fix: ✓ Available
Rule Description
This rule ensures closed ATX-style headings have no spaces inside the closing hashes. Closed ATX headings use trailing hash characters for symmetry, and spaces inside these markers are incorrect.
Why This Rule Exists
Proper closed heading format is important because:
- Follows the ATX heading specification
- Maintains consistent heading style
- Prevents parsing issues with some markdown processors
- Ensures visual symmetry in closed headings
Examples
❌ Incorrect (violates rule)
# Heading with space before closing #
## Another heading ##
### Heading with spaces ###
✅ Correct
# Heading with proper closing #
## Another heading ##
### Correctly closed heading ###
# Open heading is also fine
Configuration
This rule has no configuration options.
Automatic Fix
This rule supports automatic fixing with --fix
. The fix will:
- Remove spaces between heading content and closing hashes
- Preserve the heading level and content
- Maintain the closed heading style
Apply Fix
# Fix closed heading spacing
mdbook-lint lint --fix docs/
# Preview what would be fixed
mdbook-lint lint --fix --dry-run docs/
When to Disable
Consider disabling this rule if:
- You prefer open ATX headings (without closing hashes)
- Your markdown processor has different requirements for closed headings
Disable in Config
# .mdbook-lint.toml
disabled_rules = ["MD020"]
Disable Inline
<!-- mdbook-lint-disable MD020 -->
# Heading with space #
<!-- mdbook-lint-enable MD020 -->
Related Rules
- MD018 - No space after hash on ATX heading
- MD019 - Multiple spaces after hash on ATX heading
- MD021 - Multiple spaces inside hashes on closed ATX heading
- MD022 - Headings should be surrounded by blank lines
- MD003 - Heading style