Project: rehypejs/rehype-minify

Package: hast-util-from-string@2.0.0

  1. Dependents: 9
  2. hast utility to set the plain-text value of a node
  1. util 143
  2. utility 139
  3. unist 127
  4. html 122
  5. hast 72
  6. hast-util 46
  7. content 20
  8. text 19
  9. string 7


Build Coverage Downloads Size Sponsors Backers Chat

Set the plain-text value of a hast node. This is like the DOMs Node#textContent setter. The given node is returned.


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


npm install hast-util-from-string

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


import {h} from 'hastscript'
import {fromString} from 'hast-util-from-string'

fromString(h('p'), 'Alpha')
// { type: 'element',
//   tagName: 'p',
//   properties: {},
//   children: [ { type: 'text', value: 'Alpha' } ] }
fromString(h('div', [h('b', 'Bold'), ' and ', h('i', 'italic'), '.']), 'Charlie')
// { type: 'element',
//   tagName: 'div',
//   properties: {},
//   children: [ { type: 'text', value: 'Charlie' } ] }


fromString(node[, value])

If node is a text node (has a value property), set that to the given value or an empty string. If node is a parent node (has children), replace them with a text node whose data is set to the given value, or if value is not given, remove all its children.


See contributing.md in rehypejs/.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