pub struct MD001HeadingIncrement {
pub front_matter_title: bool,
pub front_matter_title_pattern: Option<Regex>,
}Expand description
Rule MD001: Heading levels should only increment by one level at a time
See docs/md001.md for full documentation, configuration, and examples.
This rule enforces a fundamental principle of document structure: heading levels should increase by exactly one level at a time to maintain a proper document hierarchy.
§Purpose
Proper heading structure creates a logical document outline and improves:
- Readability for humans
- Accessibility for screen readers
- Navigation in rendered documents
- Automatic generation of tables of contents
§Examples
§Correct Heading Structure
# Heading 1
## Heading 2
### Heading 3
## Another Heading 2§Incorrect Heading Structure
# Heading 1
### Heading 3 (skips level 2)
#### Heading 4§Behavior
This rule:
- Tracks the heading level throughout the document
- Validates that each new heading is at most one level deeper than the previous heading
- Allows heading levels to decrease by any amount (e.g., going from ### to #)
- Works with both ATX (
#) and Setext (underlined) heading styles
§Fix Behavior
When applying automatic fixes, this rule:
- Changes the level of non-compliant headings to be one level deeper than the previous heading
- Preserves the original heading style (ATX or Setext)
- Maintains indentation and other formatting
§Rationale
Skipping heading levels (e.g., from h1 to h3) can confuse readers and screen readers
by creating gaps in the document structure. Consistent heading increments create a proper
hierarchical outline essential for well-structured documents.
§Front Matter Title Support
When front_matter_title is enabled (default: true), this rule recognizes a title: field
in YAML/TOML frontmatter as an implicit level-1 heading. This allows documents like:
---
title: My Document
---
## First SectionWithout triggering a warning about skipping from H1 to H2, since the frontmatter title counts as the H1.
Fields§
§front_matter_title: boolWhether to treat frontmatter title field as an implicit H1
front_matter_title_pattern: Option<Regex>Optional regex pattern to match custom title fields in frontmatter
Implementations§
Trait Implementations§
Source§impl Clone for MD001HeadingIncrement
impl Clone for MD001HeadingIncrement
Source§fn clone(&self) -> MD001HeadingIncrement
fn clone(&self) -> MD001HeadingIncrement
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MD001HeadingIncrement
impl Debug for MD001HeadingIncrement
Source§impl Default for MD001HeadingIncrement
impl Default for MD001HeadingIncrement
Source§impl Rule for MD001HeadingIncrement
impl Rule for MD001HeadingIncrement
fn name(&self) -> &'static str
fn description(&self) -> &'static str
fn check(&self, ctx: &LintContext<'_>) -> LintResult
fn fix(&self, ctx: &LintContext<'_>) -> Result<String, LintError>
Source§fn category(&self) -> RuleCategory
fn category(&self) -> RuleCategory
Source§fn should_skip(&self, ctx: &LintContext<'_>) -> bool
fn should_skip(&self, ctx: &LintContext<'_>) -> bool
fn as_any(&self) -> &dyn Any
Source§fn from_config(config: &Config) -> Box<dyn Rule>where
Self: Sized,
fn from_config(config: &Config) -> Box<dyn Rule>where
Self: Sized,
Source§fn default_config_section(&self) -> Option<(String, Value)>
fn default_config_section(&self) -> Option<(String, Value)>
impl Rule for ... block,
not just the inherent impl. Read moreSource§fn config_schema(&self) -> Option<(String, Value)>
fn config_schema(&self) -> Option<(String, Value)>
Source§fn skippable_by_category(&self) -> bool
fn skippable_by_category(&self) -> bool
Source§fn config_aliases(&self) -> Option<HashMap<String, String>>
fn config_aliases(&self) -> Option<HashMap<String, String>>
Source§fn polymorphic_config_keys(&self) -> &'static [&'static str]
fn polymorphic_config_keys(&self) -> &'static [&'static str]
Rule::config_schema, so
default_config_section() keeps returning the clean user-facing default.