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 · 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.Source§fn config_aliases(&self) -> Option<HashMap<String, String>>
fn config_aliases(&self) -> Option<HashMap<String, String>>
Source§fn fix_capability(&self) -> FixCapability
fn fix_capability(&self) -> FixCapability
Source§fn cross_file_scope(&self) -> CrossFileScope
fn cross_file_scope(&self) -> CrossFileScope
Source§fn contribute_to_index(
&self,
_ctx: &LintContext<'_>,
_file_index: &mut FileIndex,
)
fn contribute_to_index( &self, _ctx: &LintContext<'_>, _file_index: &mut FileIndex, )
Source§fn cross_file_check(
&self,
_file_path: &Path,
_file_index: &FileIndex,
_workspace_index: &WorkspaceIndex,
) -> LintResult
fn cross_file_check( &self, _file_path: &Path, _file_index: &FileIndex, _workspace_index: &WorkspaceIndex, ) -> LintResult
Auto Trait Implementations§
impl Freeze for MD001HeadingIncrement
impl RefUnwindSafe for MD001HeadingIncrement
impl Send for MD001HeadingIncrement
impl Sync for MD001HeadingIncrement
impl Unpin for MD001HeadingIncrement
impl UnwindSafe for MD001HeadingIncrement
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more