Skip to main content
Version: 3.x.x 🚧


Npm VersionNpm DownloadNpm LicenseModule formats: cjs, esmNode.js VersionTested with JestCode Style: prettier

github flavor markdown spec

An ATX heading consists of a string of characters, parsed as inline content, between an opening sequence of 1–6 unescaped # characters and an optional closing sequence of any number of unescaped # characters. The opening sequence of # characters must be followed by a space or by the end of line. The optional closing sequence of #s must be preceded by a space and may be followed by spaces only. The opening # character may be indented 0-3 spaces. The raw contents of the heading are stripped of leading and trailing spaces before being parsed as inline content. The heading level is equal to the number of # characters in the opening sequence.


npm install --save @yozora/tokenizer-heading



@yozora/tokenizer-heading has been integrated into @yozora/parser / @yozora/parser-gfm-ex / @yozora/parser-gfm, so you can use YozoraParser / GfmExParser / GfmParser directly.

import YozoraParser from '@yozora/parser'

const parser = new YozoraParser()

// parse source markdown content
# h1
## h2
### h3
#### h4
##### h5
###### h6


  • name: The unique name of the tokenizer, used to bind the token it generates, to determine the tokenizer that should be called in each life cycle of the token in the entire matching / parsing phase.

  • priority: Priority of the tokenizer, determine the order of processing, high priority priority execution. interruptable. In addition, in the match-block stage, a high-priority tokenizer can interrupt the matching process of a low-priority tokenizer.


@yozora/tokenizer-heading produce Heading type nodes. See @yozora/ast for full base types.

import type { Parent } from '@yozora/ast'

export const HeadingType = 'heading'
export type HeadingType = typeof HeadingType

* Heading represents a heading of a section.
* @see
* @see
export interface Heading extends Parent<HeadingType> {
* HTML anchor identifier.
identifier?: string
* level of heading
depth: 1 | 2 | 3 | 4 | 5 | 6

Live Examples

  • Basic

  • More than six # characters is not a heading.

  • At least one space is required between the # characters and the heading’s contents, unless the heading is empty.

  • This is not a heading, because the first # is escaped.

  • Contents are parsed as inlines.

  • Leading and trailing whitespace is ignored in parsing inline content.

  • One to three spaces indentation are allowed.

  • Four spaces are too much.

  • A closing sequence of # characters is optional.

  • It need not be the same length as the opening sequence.

  • Spaces are allowed after the closing sequence.

  • A sequence of # characters with anything but spaces following it is not a closing sequence, but counts as part of the contents of the heading.

  • The closing sequence must be preceded by a space.

  • Backslash-escaped # characters do not count as part of the closing sequence.

  • ATX headings need not be separated from surrounding content by blank lines, and they can interrupt paragraphs.

  • ATX headings can be empty.