A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/syntax-tree/hast-util-from-dom below:

syntax-tree/hast-util-from-dom: utility to transform a DOM tree to hast

hast utility to transform from a DOM tree.

This package is a utility that takes a DOM tree (from the actual DOM or from things like jsdom) as input and turns it into a hast (HTML) syntax tree.

You can use this project when you want to use hast in browsers. This package is very small, but it does so by:

The hast utility hast-util-to-dom does the inverse of this utility. It turns hast into a DOM tree.

The rehype plugin rehype-dom-parse wraps this utility to parse HTML with DOM APIs.

This package is ESM only. In Node.js (version 16+), install with npm:

npm install hast-util-from-dom

In Deno with esm.sh:

import {fromDom} from 'https://esm.sh/hast-util-from-dom@5'

In browsers with esm.sh:

<script type="module">
  import {fromDom} from 'https://esm.sh/hast-util-from-dom@5?bundle'
</script>

Say our page example.html looks as follows:

<!doctype html>
<title>Example</title>
<body>
  <main>
    <h1>Hi</h1>
    <p><em>Hello</em>, world!</p>
  </main>
  <script type="module">
    import {fromDom} from 'https://esm.sh/hast-util-from-dom@4?bundle'

    const hast = fromDom(document.querySelector('main'))

    console.log(hast)
  </script>

Now running open example.html prints the following to the console:

{type: "element", tagName: "main", properties: {}, children: Array}

This package exports the identifier fromDom. There is no default export.

Transform a DOM tree to a hast tree.

Equivalent hast node (HastNode).

Callback called when each node is transformed (TypeScript type).

Nothing.

Configuration (TypeScript type).

HastNode.

This package is fully typed with TypeScript. It exports the additional types AfterTransform and Options.

Projects maintained by the unified collective are compatible with maintained versions of Node.js.

When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line, hast-util-from-dom@^5, compatible with Node.js 16.

Use of hast-util-from-dom itself is safe but see other utilities for more information on potential security problems.

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, organisation, or community you agree to abide by its terms.

ISC © Keith McKnight


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4