Socket
Socket
Sign inDemoInstall

mdast-util-heading-style

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdast-util-heading-style

mdast utility to get the style of a heading


Version published
Weekly downloads
114K
decreased by-14.51%
Maintainers
2
Weekly downloads
 
Created
Source

mdast-util-heading-style

Build Coverage Downloads Size Sponsors Backers Chat

mdast utility to get the style of a heading.

Contents

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.

Install

This package is ESM only. In Node.js (version 14.14+ and 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'
</script>

Use

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'

API

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

headingStyle(node[, relative])

Get the heading style of a heading, optionally relative to a preferred style.

This is because ATX headings with a depth of three or more could be considered setext.

Parameters
  • node (Heading) — heading node to check
  • style (Style, optional) — relative style
Returns

Style (Style) if it can be inferred, null otherwise.

Style

Style of heading (TypeScript type).

Type
type Style = 'atx' | 'atx-closed' | 'setext'

Types

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

Compatibility

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

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

Keywords

FAQs

Package last updated on 25 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc