Project: syntax-tree/mdast-util-to-string

Package: mdast-util-to-string@3.1.0

  1. Dependencies: 0·Dependents: 180
  2. mdast utility to get the plain text content of a node
  1. util 129
  2. markdown 127
  3. utility 125
  4. unist 119
  5. mdast 89
  6. mdast-util 29
  7. node 23
  8. serialize 9
  9. string 5


Build Coverage Downloads Size Sponsors Backers Chat

mdast utility to get the plain text content of a node.


This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.


npm install mdast-util-to-string


import unified from 'unified'
import remarkParse from 'remark-parse'
import {toString} from 'mdast-util-to-string'

var tree = unified()
  .parse('Some _emphasis_, **importance**, and `code`.')

console.log(toString(tree)) // => 'Some emphasis, importance, and code.'


This package exports the following identifiers: toString. There is no default export.

toString(node[, options])

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

The algorithm checks value of node and then alt. If no value is found, the algorithm checks the children of node and joins them (without spaces or newlines).

This is not a markdown to plain-text library. Use strip-markdown for that.


Whether to use alt (boolean, default: true)


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.


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.


MIT © Titus Wormer