{"library":"mdast-util-to-string","title":"mdast utility to extract plain text content","description":"mdast-util-to-string is a focused utility within the unified ecosystem designed to extract the plain text content from an mdast (Markdown Abstract Syntax Tree) node or a list of nodes. It is currently stable at version 4.0.0. The project maintains compatibility with maintained versions of Node.js, typically releasing new major versions when older Node.js versions become unmaintained, which often includes breaking changes like switching to ESM or dropping specific API support. This package prioritizes text extraction over full markdown serialization, differentiating itself from `mdast-util-to-markdown`. It's particularly useful for scenarios like generating excerpts, search indexing, or displaying a node's textual content without its formatting, similar to `hast-util-to-string` for hast trees. It ships with full TypeScript support.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install mdast-util-to-string"],"cli":null},"imports":["import { toString } from 'mdast-util-to-string'","import type { Options } from 'mdast-util-to-string'","import {toString} from 'https://esm.sh/mdast-util-to-string@4'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import {fromMarkdown} from 'mdast-util-from-markdown'\nimport {toString} from 'mdast-util-to-string'\n\n// A sample markdown string with various inline elements\nconst markdown = '# Hello World\\n\\nThis is a paragraph with _emphasis_, **importance**, and `code`.\\n\\nIt also has an [image](https://example.com/image.png \"Image Title\") and an <a>link</a>.'\n\n// Parse the markdown string into an mdast syntax tree\nconst tree = fromMarkdown(markdown)\n\n// Get the plain text content of the entire tree\nconsole.log('Plain text content:', toString(tree))\n\n// Get the plain text content of a specific node, e.g., the heading\nconst headingNode = tree.children[0];\nconsole.log('Heading text:', toString(headingNode))\n\n// Get the plain text content of the paragraph with `includeHtml` option\nconst paragraphNode = tree.children[1];\nconsole.log('Paragraph text (with HTML):', toString(paragraphNode, {includeHtml: true}))\nconsole.log('Paragraph text (without HTML):', toString(paragraphNode, {includeHtml: false}))","lang":"typescript","description":"This example demonstrates how to parse a markdown string into an mdast tree and then use `toString` to extract the plain text content from the entire tree or specific nodes, including options for handling HTML.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}