Skip to content

markdown-heading

Handles ATX-style headings from h1 through h6.

Details

PropertyValue
Namemarkdown-heading
Priority100
TypeBlock
FactorymarkdownHeading()

What It Handles

ATX Headings

Lines starting with one to six # characters followed by a space:

markdown
# Heading 1
## Heading 2
### Heading 3
#### Heading 4
##### Heading 5
###### Heading 6

Renders as <h1> through <h6>.

Closing Hashes

Optional trailing # characters are stripped:

markdown
# Heading 1 #
## Heading 2 ##
### Heading 3 ###########

All render identically to their non-closing-hash versions.

Inline Formatting in Headings

Heading content supports inline formatting:

markdown
# This is **bold** heading
## Heading with `code` and *italic*

The heading plugin produces a block token with the heading text as content. The core's inline parser then processes the content using the markdown-inline plugin.

API

ts
import { markdownHeading } from '@generative-dom/plugins';

const plugin = markdownHeading();

No configuration options.

Edge Cases

  • # without a space after it is not a heading -- it is treated as a paragraph by markdown-base
  • ####### (seven or more hashes) is not a heading
  • A heading line can be preceded by up to three spaces of indentation
  • Empty headings (# ) are valid and render as an empty heading element
  • Headings do not support setext style (underline with === or ---) -- Generative DOM only supports ATX style

Rendering

InputOutput Element
# text<h1>
## text<h2>
### text<h3>
#### text<h4>
##### text<h5>
###### text<h6>

Heading content is rendered as child text/inline nodes within the heading element.