What is mdast-util-definitions?
The mdast-util-definitions npm package is a utility for working with Markdown Abstract Syntax Tree (MDAST) data structures. It provides a way to look up and manage definitions in a MDAST, which is useful when working with markdown documents in a programmatic way. This can include tasks like parsing, manipulating, or inspecting markdown content.
What are mdast-util-definitions's main functionalities?
Definition lookup
This feature allows you to look up definitions in a MDAST by their identifier. It's useful for resolving references in markdown documents, such as links or images, to their corresponding definitions.
const definitions = require('mdast-util-definitions');
const ast = { /* some MDAST */ };
const definition = definitions(ast);
console.log(definition('referenceId'));
Other packages similar to mdast-util-definitions
unist-util-visit
While unist-util-visit is not specifically designed for handling definitions within markdown documents, it is a utility for traversing Unist syntax trees, which includes MDASTs. It can be used in conjunction with mdast-util-definitions for more complex operations involving visiting nodes and acting upon them, offering a broader scope of manipulation than mdast-util-definitions.
remark-parse
remark-parse is a part of the remark ecosystem, which is built on top of MDAST. It is used for parsing markdown into MDASTs. While it doesn't provide definition lookup functionality directly, it is a foundational tool for creating MDASTs from markdown content, which can then be used with mdast-util-definitions for definition management.
mdast-util-definitions
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 12.20+, 14.14+, or 16.0+), install with npm:
npm install mdast-util-definitions
In Deno with esm.sh
:
import {definitions} from 'https://esm.sh/mdast-util-definitions@5'
In browsers with esm.sh
:
<script type="module">
import {definitions} from 'https://esm.sh/mdast-util-definitions@5?bundle'
</script>
Use
import {fromMarkdown} from 'mdast-util-from-markdown'
import {definitions} from 'mdast-util-definitions'
const tree = fromMarkdown('[example]: https://example.com "Example"')
const definition = definitions(tree)
definition('example')
definition('foo')
API
This package exports the identifier definitions
.
There is no default export.
definitions(node)
Find definitions in node
(Node
).
Uses CommonMark precedence, which means that earlier definitions are preferred
over duplicate later definitions.
Returns
definition
(Function
).
definition(identifier)
Get a node from the bound definition cache by its identifier
(string
).
Returns
Definition, if found (Node?
)
Types
This package is fully typed with TypeScript.
There are no additional exported types.
Compatibility
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.
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.
Related
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