markdown-preferences/level2-heading-style
enforce consistent style for level 2 headings
- ⚙️ This rule is included in
plugin.configs.standard. - 🔧 The
--fixoption on the command line can automatically fix some of the problems reported by this rule.
📖 Rule Details
This rule enforces consistent style for level 2 headings in Markdown files. Level 2 headings can be written in two formats:
- ATX style: Lines that start with two
##characters, followed by a space and the heading text - Setext style: Text followed by a line of
-characters (underline)
Both formats are valid according to the CommonMark specification, but mixing styles within a document or project can reduce readability and consistency.
<!-- ATX style -->
## This is a level 2 heading
<!-- Setext style -->
This is a level 2 heading
-------------------------This rule allows you to enforce either ATX style ("atx") or Setext style ("setext") for all level 2 headings in your Markdown files.
Why enforce this?
- Consistency: Ensures all level 2 headings follow the same style throughout your documentation
- Readability: Makes it easier to scan and understand document structure
- Tooling: Simplifies automated processing and formatting of Markdown files
- Maintainability: Reduces cognitive load when editing and reviewing documentation
Examples
ATX Style
<!-- eslint markdown-preferences/level2-heading-style: ['error', { style: 'atx' }] -->
<!-- ✓ GOOD -->
## Installation
## Configuration
## Usage
<!-- ✗ BAD -->
Installation
------------
Configuration
-------------
Usage
-----Setext Style
<!-- eslint markdown-preferences/level2-heading-style: ['error', { style: 'setext' }] -->
<!-- ✓ GOOD -->
Installation
------------
Configuration
-------------
Usage
-----
<!-- ✗ BAD -->
## Installation
## Configuration
## Usage🔧 Options
{
"markdown-preferences/level2-heading-style": [
"error",
{
"style": "atx", // or "setext"
"allowMultilineSetext": false
}
]
}style
- Type:
"atx" | "setext" - Default:
"atx"
Specifies which heading style to enforce for level 2 headings:
"atx": Enforce ATX style (## Heading)"setext": Enforce Setext style (Heading\n------)
allowMultilineSetext
- Type:
boolean - Default:
false
This option only takes effect when style is set to "atx".
When true, allows Setext headings that span multiple lines. When false, multiline Setext headings are reported as errors.
Note: Multiline Setext headings cannot be automatically fixed to ATX style due to the complexity of handling line breaks in heading text.
📚 Further Reading
👫 Related Rules
🚀 Version
This rule was introduced in eslint-plugin-markdown-preferences v0.18.0