unified

Project: syntax-tree/mdast-util-definitions

Package: mdast-util-definitions@5.1.1

  1. Dependents: 0
  2. mdast utility to find definition nodes in a tree
  1. markdown 153
  2. util 145
  3. utility 141
  4. unist 131
  5. mdast 86
  6. tree 44
  7. mdast-util 30
  8. node 25
  9. definition 16
  10. find 11

mdast-util-definitions

Build Coverage Downloads Size Sponsors Backers Chat

mdast utility to find definitions by identifier.

Contents

What is this?

This package is a tiny utility that lets you find definitions.

When should I use this?

This utility can be useful because definitions can occur after the things that reference them. It’s small and protects against prototype pollution.

Install

This package is ESM only. In Node.js (version 16+), install with npm:

npm install mdast-util-definitions

In Deno with esm.sh:

import {definitions} from 'https://esm.sh/mdast-util-definitions@6'

In browsers with esm.sh:

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

Use

import {definitions} from 'mdast-util-definitions'
import {fromMarkdown} from 'mdast-util-from-markdown'

const tree = fromMarkdown('[example]: https://example.com "Example"')

const definition = definitions(tree)

definition('example')
// => {type: 'definition', 'title': 'Example', …}

definition('foo')
// => undefined

API

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

definitions(tree)

Find definitions in tree.

Uses CommonMark precedence, which means that earlier definitions are preferred over duplicate later definitions.

Parameters
Returns

Getter (GetDefinition).

GetDefinition

Get a definition by identifier (TypeScript type).

Parameters
Returns

Definition corresponding to identifier (Definition) or undefined.

Types

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

Compatibility

Projects maintained by the unified collective are compatible with maintained versions of Node.js.

When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line, mdast-util-definitions@^6, compatible with Node.js 16.

Security

Use of mdast-util-definitions does not involve hast or user content so there are no openings for cross-site scripting (XSS) attacks. Additionally, safe guards are in place to protect against prototype poisoning.

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