pub struct MD002FirstHeadingH1 { /* private fields */ }Expand description
Rule MD002: First heading should be a top-level heading
See docs/md002.md for full documentation, configuration, and examples.
This rule enforces that the first heading in a document is a top-level heading (typically h1), which establishes the main topic or title of the document.
§Purpose
- Document Structure: Ensures proper document hierarchy with a single top-level heading
- Accessibility: Improves screen reader navigation by providing a clear document title
- SEO: Helps search engines identify the primary topic of the document
- Readability: Provides users with a clear understanding of the document’s main subject
§Configuration Options
The rule supports customizing the required level for the first heading:
MD002:
level: 1 # The heading level required for the first heading (default: 1)Setting level: 2 would require the first heading to be an h2 instead of h1.
§Examples
§Correct (with default configuration)
# Document Title
## Section 1
Content here...
## Section 2
More content...§Incorrect (with default configuration)
## Introduction
Content here...
# Main Title
More content...§Behavior
This rule:
- Ignores front matter (YAML metadata at the beginning of the document)
- Works with both ATX (
#) and Setext (underlined) heading styles - Only examines the first heading it encounters
- Does not apply to documents with no headings
§Fix Behavior
When applying automatic fixes, this rule:
- Changes the level of the first heading to match the configured level
- Preserves the original heading style (ATX, closed ATX, or Setext)
- Maintains indentation and other formatting
§Rationale
Having a single top-level heading establishes the document’s primary topic and creates
a logical structure. This follows semantic HTML principles where each page should have
a single <h1> element that defines its main subject.
Implementations§
Source§impl MD002FirstHeadingH1
impl MD002FirstHeadingH1
pub fn new(level: u32) -> Self
pub fn from_config_struct(config: MD002Config) -> Self
Trait Implementations§
Source§impl Clone for MD002FirstHeadingH1
impl Clone for MD002FirstHeadingH1
Source§fn clone(&self) -> MD002FirstHeadingH1
fn clone(&self) -> MD002FirstHeadingH1
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MD002FirstHeadingH1
impl Debug for MD002FirstHeadingH1
Source§impl Default for MD002FirstHeadingH1
impl Default for MD002FirstHeadingH1
Source§fn default() -> MD002FirstHeadingH1
fn default() -> MD002FirstHeadingH1
Source§impl Rule for MD002FirstHeadingH1
impl Rule for MD002FirstHeadingH1
Source§fn category(&self) -> RuleCategory
fn category(&self) -> RuleCategory
Get the category of this rule for selective processing
Source§fn should_skip(&self, ctx: &LintContext<'_>) -> bool
fn should_skip(&self, ctx: &LintContext<'_>) -> bool
Check if this rule should be skipped
fn name(&self) -> &'static str
fn description(&self) -> &'static str
fn check(&self, ctx: &LintContext<'_>) -> LintResult
fn fix(&self, ctx: &LintContext<'_>) -> Result<String, LintError>
fn as_any(&self) -> &dyn Any
fn as_maybe_document_structure(&self) -> Option<&dyn MaybeDocumentStructure>
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 from_config(config: &Config) -> Box<dyn Rule>where
Self: Sized,
fn from_config(config: &Config) -> Box<dyn Rule>where
Self: Sized,
Source§fn check_with_structure(
&self,
ctx: &LintContext<'_>,
_structure: &DocumentStructure,
) -> LintResult
fn check_with_structure( &self, ctx: &LintContext<'_>, _structure: &DocumentStructure, ) -> LintResult
Source§fn check_with_ast(
&self,
ctx: &LintContext<'_>,
_ast: &MarkdownAst,
) -> LintResult
fn check_with_ast( &self, ctx: &LintContext<'_>, _ast: &MarkdownAst, ) -> LintResult
Source§fn check_with_structure_and_ast(
&self,
ctx: &LintContext<'_>,
_structure: &DocumentStructure,
_ast: &MarkdownAst,
) -> LintResult
fn check_with_structure_and_ast( &self, ctx: &LintContext<'_>, _structure: &DocumentStructure, _ast: &MarkdownAst, ) -> LintResult
Source§fn uses_document_structure(&self) -> bool
fn uses_document_structure(&self) -> bool
fn as_maybe_ast(&self) -> Option<&dyn MaybeAst>
Auto Trait Implementations§
impl Freeze for MD002FirstHeadingH1
impl RefUnwindSafe for MD002FirstHeadingH1
impl Send for MD002FirstHeadingH1
impl Sync for MD002FirstHeadingH1
impl Unpin for MD002FirstHeadingH1
impl UnwindSafe for MD002FirstHeadingH1
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