unified

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

Package: mdast-util-heading-style@2.0.0

  1. Dependents: 2
  2. mdast utility to get the style of a heading
  1. util 143
  2. utility 139
  3. markdown 139
  4. unist 127
  5. mdast 83
  6. mdast-util 30
  7. heading 26
  8. node 25
  9. style 10

mdast-util-heading-style

Build Coverage Downloads Size Sponsors Backers Chat

mdast utility to get the style of a heading.

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.

npm:

npm install mdast-util-heading-style

Use

import {unified} from 'unified'
import {headingStyle} from 'mdast-util-heading-style'
import remarkParse from 'remark-parse'

const processor = unified().use(remarkParse)

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

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

API

This package exports the following identifiers: headingStyle. There is no default export.

headingStyle(node[, relative])

Get the heading style of a node.

Parameters
Returns

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

Security

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

Contribute

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.

License

MIT © Titus Wormer