Project: syntax-tree/mdast-util-heading-style

Package: mdast-util-heading-style@2.0.0

  1. Dependents: 0
  2. mdast utility to get the style of a heading
  1. util 147
  2. markdown 145
  3. utility 143
  4. unist 133
  5. mdast 90
  6. mdast-util 31
  7. node 25
  8. heading 25
  9. style 10


Build Coverage Downloads Size Sponsors Backers Chat

mdast utility to get the style of a heading.


What is this?

This package is a tiny utility to figure out if a heading was written as ATX or as setext.

## ATX uses hashes

Setext uses an underline

When should I use this?

Probably not a lot! It’s used in remark-lint.


This package is ESM only. In Node.js (version 12.20+, 14.14+, or 16.0+), install with npm:

npm install mdast-util-heading-style

In Deno with esm.sh:

import {headingStyle} from 'https://esm.sh/mdast-util-heading-style@2'

In browsers with esm.sh:

<script type="module">
  import {headingStyle} from 'https://esm.sh/mdast-util-heading-style@2?bundle'


import {unified} from 'unified'
import {fromMarkdown} from 'mdast-util-from-markdown'
import {headingStyle} from 'mdast-util-heading-style'

headingStyle(fromMarkdown('# ATX').children[0]) // => 'atx'
headingStyle(fromMarkdown('# ATX #\n').children[0]) // => 'atx-closed'
headingStyle(fromMarkdown('ATX\n===').children[0]) // => 'setext'

headingStyle(fromMarkdown('### ATX').children[0]) // => null
headingStyle(fromMarkdown('### ATX').children[0], 'setext') // => 'setext'


This package exports the identifier headingStyle. There is no default export.

headingStyle(node[, relative])

Get the heading style of a node (Node), optionally relative to a preferred style ('atx', 'atx-closed', 'setext', optional). This is because ATX headings with a depth of three or more could be considered setext.


Style ('atx', 'atx-closed', or 'setext'). When an ambiguous heading is found, either relative or null is returned.


This package is fully typed with TypeScript. It exports the type Style.


Projects maintained by the unified collective are compatible with all maintained versions of Node.js. As of now, that is Node.js 12.20+, 14.14+, and 16.0+. Our projects sometimes work with older versions, but this is not guaranteed.


Use of mdast-util-heading-style does not involve hast so there are no openings for cross-site scripting (XSS) attacks.


See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.


MIT © Titus Wormer