CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
1# mdast-util-to-string2 3[![Build][build-badge]][build]4[![Coverage][coverage-badge]][coverage]5[![Downloads][downloads-badge]][downloads]6[![Size][size-badge]][size]7[![Sponsors][sponsors-badge]][collective]8[![Backers][backers-badge]][collective]9[![Chat][chat-badge]][chat]10 11[mdast][] utility to get the text content of a node.12 13## Contents14 15*   [What is this?](#what-is-this)16*   [When should I use this?](#when-should-i-use-this)17*   [Install](#install)18*   [Use](#use)19*   [API](#api)20    *   [`toString(value[, options])`](#tostringvalue-options)21    *   [`Options`](#options)22*   [Types](#types)23*   [Compatibility](#compatibility)24*   [Security](#security)25*   [Related](#related)26*   [Contribute](#contribute)27*   [License](#license)28 29## What is this?30 31This package is a tiny utility that gets the textual content of a node.32 33## When should I use this?34 35This utility is useful when you have a node, say a heading, and want to get the36text inside it.37 38This package does not serialize markdown, that’s what39[`mdast-util-to-markdown`][mdast-util-to-markdown] does.40 41Similar packages, [`hast-util-to-string`][hast-util-to-string] and42[`hast-util-to-text`][hast-util-to-text], do the same but on [hast][].43 44## Install45 46This package is [ESM only][esm].47In Node.js (version 16+), install with [npm][]:48 49```sh50npm install mdast-util-to-string51```52 53In Deno with [`esm.sh`][esmsh]:54 55```js56import {toString} from 'https://esm.sh/mdast-util-to-string@4'57```58 59In browsers with [`esm.sh`][esmsh]:60 61```html62<script type="module">63  import {toString} from 'https://esm.sh/mdast-util-to-string@4?bundle'64</script>65```66 67## Use68 69```js70import {fromMarkdown} from 'mdast-util-from-markdown'71import {toString} from 'mdast-util-to-string'72 73const tree = fromMarkdown('Some _emphasis_, **importance**, and `code`.')74 75console.log(toString(tree)) // => 'Some emphasis, importance, and code.'76```77 78## API79 80This package exports the identifier [`toString`][api-to-string].81There is no default export.82 83### `toString(value[, options])`84 85Get the text content of a node or list of nodes.86 87Prefers the node’s plain-text fields, otherwise serializes its children,88and if the given value is an array, serialize the nodes in it.89 90###### Parameters91 92*   `value` (`unknown`)93    — thing to serialize, typically [`Node`][node]94*   `options` ([`Options`][api-options], optional)95    — configuration96 97###### Returns98 99Serialized `value` (`string`).100 101### `Options`102 103Configuration (TypeScript type).104 105###### Fields106 107*   `includeImageAlt` (`boolean`, default: `true`)108    — whether to use `alt` for `image`s109*   `includeHtml` (`boolean`, default: `true`)110    — whether to use `value` of HTML111 112## Types113 114This package is fully typed with [TypeScript][].115It exports the additional type [`Options`][api-options].116 117## Compatibility118 119Projects maintained by the unified collective are compatible with maintained120versions of Node.js.121 122When we cut a new major release, we drop support for unmaintained versions of123Node.124This means we try to keep the current release line, `mdast-util-to-string@^4`,125compatible with Node.js 16.126 127## Security128 129Use of `mdast-util-to-string` does not involve **[hast][]**, user content, or130change the tree, so there are no openings for [cross-site scripting (XSS)][xss]131attacks.132 133## Related134 135*   [`hast-util-to-string`](https://github.com/wooorm/rehype-minify/tree/main/packages/hast-util-to-string)136    — get text content in hast137*   [`hast-util-to-text`](https://github.com/syntax-tree/hast-util-to-text)138    — get text content in hast according to the `innerText` algorithm139 140## Contribute141 142See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for143ways to get started.144See [`support.md`][support] for ways to get help.145 146This project has a [code of conduct][coc].147By interacting with this repository, organization, or community you agree to148abide by its terms.149 150## License151 152[MIT][license] © [Titus Wormer][author]153 154<!-- Definitions -->155 156[build-badge]: https://github.com/syntax-tree/mdast-util-to-string/workflows/main/badge.svg157 158[build]: https://github.com/syntax-tree/mdast-util-to-string/actions159 160[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-to-string.svg161 162[coverage]: https://codecov.io/github/syntax-tree/mdast-util-to-string163 164[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-to-string.svg165 166[downloads]: https://www.npmjs.com/package/mdast-util-to-string167 168[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-to-string169 170[size]: https://bundlejs.com/?q=mdast-util-to-string171 172[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg173 174[backers-badge]: https://opencollective.com/unified/backers/badge.svg175 176[collective]: https://opencollective.com/unified177 178[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg179 180[chat]: https://github.com/syntax-tree/unist/discussions181 182[npm]: https://docs.npmjs.com/cli/install183 184[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c185 186[esmsh]: https://esm.sh187 188[typescript]: https://www.typescriptlang.org189 190[license]: license191 192[author]: https://wooorm.com193 194[health]: https://github.com/syntax-tree/.github195 196[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md197 198[support]: https://github.com/syntax-tree/.github/blob/main/support.md199 200[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md201 202[mdast]: https://github.com/syntax-tree/mdast203 204[mdast-util-to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown205 206[hast]: https://github.com/syntax-tree/hast207 208[hast-util-to-string]: https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-to-string209 210[hast-util-to-text]: https://github.com/syntax-tree/hast-util-to-text211 212[node]: https://github.com/syntax-tree/mdast#nodes213 214[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting215 216[api-to-string]: #tostringvalue-options217 218[api-options]: #options219