
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
hast-util-to-dom
Advanced tools
hast utility to transform to a DOM tree.
yarn:
yarn add hast-util-to-dom
npm:
npm install hast-util-to-dom
This utility is intended for browser use!
import toDOM from 'hast-util-to-dom';
const el = toDOM({
type: 'element',
tagName: 'h1',
properties: {},
children: [{type: 'text', value: 'World!'}]
});
console.log(el);
This will create a DOM node like this:
<h1>World!</h1>
If you want a string of HTML, you have a few options:
// Outer HTML, eg. if you want an entire fragment
console.log(el.outerHTML);
// "<h1>World</h1>"
// Inner HTML, eg. if you have a wrapping element you don't need
console.log(el.innerHTML);
// "World"
// Full serialization, eg. when you want the whole document
console.log(new XMLSerializer().serializeToString(el));
// "<div xmlns="http://www.w3.org/1999/xhtml">World</div>"
Due to the nature of various browser implementations, you may notice cross-browser differences in the serialized output, especially with respect to whitespace or self-closing tags. Buddy, that’s the web!
toDOM(node[, options])
Transform a hast tree to a DOM tree.
options
options.fragment
Whether a DOM fragment should be returned (default: false
).
options.document
Document interface to use (default: global.document
).
options.namespace
namespace
to use to create elements.
hast-util-sanitize
— Sanitize hast nodeshast-util-to-html
— Create an HTML stringhast-util-from-dom
— Create a hast tree from a DOM treeSee 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, organisation, or community you agree to abide by its terms.
FAQs
hast utility to transform to the DOM
The npm package hast-util-to-dom receives a total of 1,770 weekly downloads. As such, hast-util-to-dom popularity was classified as popular.
We found that hast-util-to-dom demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.