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 spaces or tabs, or
by the end of line. The optional closing sequence of #s must be preceded by
spaces or tabs and may be followed by spaces or tabs only. The opening
# character may be preceded by up to three spaces of indentation. The raw
contents of the heading are stripped of leading and trailing space or tabs
before being parsed as inline content. The heading level is equal to the number
of # characters in the opening sequence.
Simple headings:
# foo
## foo
### foo
#### foo
##### foo
###### foo
<h1>foo</h1>
<h2>foo</h2>
<h3>foo</h3>
<h4>foo</h4>
<h5>foo</h5>
<h6>foo</h6>
More than six # characters is not a heading:
At least one space or tab is required between the # characters and the
heading’s contents, unless the heading is empty. Note that many
implementations currently do not require the space. However, the
space was required by the
original ATX implementation,
and it helps prevent things like the following from being parsed as
headings:
This is not a heading, because the first # is escaped:
Contents are parsed as inlines:
Leading and trailing spaces or tabs are ignored in parsing inline content:
Up to three spaces of indentation are allowed:
Four spaces of indentation is too many:
A closing sequence of # characters is optional:
It need not be the same length as the opening sequence:
Spaces or tabs are allowed after the closing sequence:
A sequence of # characters with anything but spaces or tabs 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 or tab:
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: