mdast-util-to-string
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
@types/mdast | 4.0.4 | 28.74 kB | MIT | prod |
mdast-util-to-string is a fantastic tool that fetches the text content of a specific node. With assistance from this JavaScript utility, users can easily extract the plain text inside a node without having to go through the markdown serialization process.
The usage of mdast-util-to-string is straightforward. This package does not come with a default export; it exports the identifier toString
. Below is an example on how to use this utility:
import {fromMarkdown} from 'mdast-util-from-markdown'
import {toString} from 'mdast-util-to-string'
const tree = fromMarkdown('Some _emphasis_, **importance**, and `code`.')
console.log(toString(tree)) // => 'Some emphasis, importance, and code.'
From this code snippet, we can see it's a two-step process:
First, we import the utility functions fromMarkdown
and toString
. Then, the fromMarkdown
function is used to parse a markdown string into a tree, and finally, the toString
function outputs the text content of that markdown content, stripping all the markdown syntax.
The full documentation for mdast-util-to-string is available directly at its GitHub page, https://github.com/syntax-tree/mdast-util-to-string. This package is part of the unified collective and majorly supports Node.js versions. The documentation provides ample insights about installation, usage, options available, compatibility, security, related packages, contribution, and license involved in the use of this package.