
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
mdast-util-to-string
Advanced tools
The mdast-util-to-string package is a utility to extract plain text strings from an MDAST (Markdown Abstract Syntax Tree) node. It is commonly used when working with markdown processing or AST manipulation to get the string representation of a node without any markdown syntax.
Extracting string from MDAST node
This feature allows you to pass an MDAST node to the `toString` function and receive a plain text string in return. It's useful for extracting readable text from markdown content.
const toString = require('mdast-util-to-string');
const mdast = {
type: 'paragraph',
children: [{type: 'text', value: 'Hello, world!'}]
};
const text = toString(mdast);
console.log(text); // 'Hello, world!'
Similar to mdast-util-to-string, hast-util-to-text is a utility for converting HAST (Hypertext Abstract Syntax Tree) nodes to plain text strings. While mdast-util-to-string works with markdown, hast-util-to-text is used for HTML content.
This package is similar in that it also operates on AST nodes, specifically UNIST nodes, to stringify the position of a node. It's different from mdast-util-to-string as it focuses on the position rather than extracting the text content.
Remark-stringify is part of the remark ecosystem and is used to serialize markdown. It is similar to mdast-util-to-string in that it deals with markdown content, but it focuses on converting the entire MDAST back to a markdown string, rather than extracting plain text.
remark utility to get the plain text content of an mdast node.
npm:
npm install mdast-util-to-string
mdast-util-to-string is also available for duo, and as an AMD, CommonJS, and globals module, uncompressed and compressed.
/*
* Dependencies.
*/
var remark = require('remark');
var toString = require('mdast-util-to-string');
/*
* AST.
*/
var ast = remark.parse('Some *emphasis*, **strongness**, and `code`.');
toString(ast);
// 'Some emphasis, strongness, and code.'
toString(node)
Get the text content of a node.
The algorithm checks value
of node
, then alt
, and finally title
.
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.
Parameters:
node
(Node
).Returns: string
— text representation of node
.
FAQs
mdast utility to get the plain text content of a node
The npm package mdast-util-to-string receives a total of 14,696,301 weekly downloads. As such, mdast-util-to-string popularity was classified as popular.
We found that mdast-util-to-string demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.