All Projects → syntax-tree → mdast-util-to-string

syntax-tree / mdast-util-to-string

Licence: MIT license
utility to get the plain text content of an mdast node

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to mdast-util-to-string

mdast-util-to-hast
utility to transform mdast to hast
Stars: ✭ 53 (+96.3%)
Mutual labels:  syntax-tree, unist, mdast, mdast-util
unist-util-map
utility to create a new tree by mapping all nodes
Stars: ✭ 30 (+11.11%)
Mutual labels:  syntax-tree, util, unist
MarkdownSyntax
☄️ A Type-safe Markdown parser in Swift.
Stars: ✭ 65 (+140.74%)
Mutual labels:  syntax-tree, unist, mdast
unist-builder
utility to create a new trees with a nice syntax
Stars: ✭ 52 (+92.59%)
Mutual labels:  syntax-tree, util, unist
hast-util-from-dom
utility to transform a DOM tree to hast
Stars: ✭ 20 (-25.93%)
Mutual labels:  syntax-tree, util, unist
unist-util-visit-parents
utility to recursively walk over unist nodes, with ancestral information
Stars: ✭ 25 (-7.41%)
Mutual labels:  syntax-tree, util, unist
nlcst-to-string
utility to transform an nlcst tree to a string
Stars: ✭ 16 (-40.74%)
Mutual labels:  syntax-tree, util, unist
unist-util-inspect
utility to inspect nodes
Stars: ✭ 16 (-40.74%)
Mutual labels:  syntax-tree, util, unist
hast-util-sanitize
utility to sanitize hast nodes
Stars: ✭ 34 (+25.93%)
Mutual labels:  syntax-tree, util, unist
hast-util-to-html
utility to serialize hast to HTML
Stars: ✭ 47 (+74.07%)
Mutual labels:  syntax-tree, util, unist
hast-util-to-mdast
utility to transform hast (HTML) to mdast (markdown)
Stars: ✭ 26 (-3.7%)
Mutual labels:  unist, mdast, mdast-util
sast
Parse CSS, Sass, SCSS, and Less into a unist syntax tree
Stars: ✭ 51 (+88.89%)
Mutual labels:  syntax-tree, unist
Unist Util Visit
utility to visit nodes
Stars: ✭ 101 (+274.07%)
Mutual labels:  syntax-tree, util
unist-util-select
utility to select unist nodes with CSS-like selectors
Stars: ✭ 41 (+51.85%)
Mutual labels:  util, unist
xast
Extensible Abstract Syntax Tree
Stars: ✭ 32 (+18.52%)
Mutual labels:  syntax-tree, unist
ntast
Notion Abstract Syntax Tree specification.
Stars: ✭ 101 (+274.07%)
Mutual labels:  syntax-tree, unist
Unified
☔️ interface for parsing, inspecting, transforming, and serializing content through syntax trees
Stars: ✭ 3,036 (+11144.44%)
Mutual labels:  syntax-tree, unist
Calcit Editor
Intuitive S-expressions editing for Clojure(Script).
Stars: ✭ 158 (+485.19%)
Mutual labels:  syntax-tree
Nlcst
Natural Language Concrete Syntax Tree format
Stars: ✭ 116 (+329.63%)
Mutual labels:  syntax-tree
UnityCLI
Unity TCP CLI communication for debugging
Stars: ✭ 22 (-18.52%)
Mutual labels:  util

mdast-util-to-string

Build Coverage Downloads Size Sponsors Backers Chat

mdast utility to get the text content of a node.

Contents

What is this?

This package is a tiny utility that gets the textual content of a node.

When should I use this?

This utility is useful when you have a node, say a heading, and want to get the text inside it.

This package does not serialize markdown, that’s what mdast-util-to-markdown does.

Similar packages, hast-util-to-string and hast-util-to-text, do the same but on hast.

Install

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

npm install mdast-util-to-string

In Deno with esm.sh:

import {toString} from 'https://esm.sh/mdast-util-to-string@3'

In browsers with esm.sh:

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

Use

import {unified} from 'unified'
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.'

API

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

toString(value[, options])

Get the text content of a node or list of nodes.

Prefers the node’s plain-text fields, otherwise serializes its children, and if the given value is an array, serialize the nodes in it.

Parameters
  • value (unknown) — thing to serialize, typically Node
  • options (Options, optional) — configuration
Returns

Serialized value (string).

Options

Configuration (TypeScript type).

Fields
  • includeImageAlt (boolean, default: true) — whether to use alt for images

Types

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

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-to-string does not involve hast, user content, or change the tree, so there are no openings for cross-site scripting (XSS) attacks.

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].