Skip to content

Commit

Permalink
Add improved docs
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jan 9, 2023
1 parent 23da80e commit 46a4e51
Showing 1 changed file with 46 additions and 10 deletions.
56 changes: 46 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`fromDom(node, options?)`](#fromdomnode-options)
* [`fromDom(tree, options?)`](#fromdomtree-options)
* [`AfterTransform`](#aftertransform)
* [`Options`](#options)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
Expand Down Expand Up @@ -50,7 +52,7 @@ parse HTML with DOM APIs.
## Install

This package is [ESM only][esm].
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:
In Node.js (version 14.14+ and 16.0+), install with [npm][]:

```sh
npm install hast-util-from-dom
Expand Down Expand Up @@ -99,21 +101,47 @@ Now running `open example.html` prints the following to the console:

## API

This package exports the identifier `fromDom`.
This package exports the identifier [`fromDom`][fromdom].
There is no default export.

### `fromDom(node, options?)`
### `fromDom(tree, options?)`

Turn a DOM tree into a hast tree.
Transform a DOM tree to a hast tree.

##### options
###### Parameters

Configuration (optional).
* `tree` ([`DomNode`][dom-node])
— DOM tree to transform
* `options` ([`Options`][options], optional)
— configuration

###### `options.afterTransform`
###### Returns

Called when a DOM node was transformed into a hast node
(`(Node, HastNode) => void?`).
Equivalent hast node ([`HastNode`][hast-node]).

### `AfterTransform`

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

###### Parameters

* `domNode` ([`DomNode`][dom-node])
— DOM node that was handled
* `hastNode` ([`HastNode`][hast-node])
— corresponding hast node

###### Returns

Nothing.

### `Options`

Configuration (TypeScript type).

##### Fields

* `afterTransform` ([`AfterTransform`][aftertransform], optional)
— callback called when each node is transformed

##### Returns

Expand Down Expand Up @@ -215,10 +243,18 @@ abide by its terms.

[dom]: https://developer.mozilla.org/docs/Web/API/Document_Object_Model

[dom-node]: https://developer.mozilla.org/docs/Web/API/Node

[hast-util-from-html]: https://github.com/syntax-tree/hast-util-from-html

[hast-util-to-dom]: https://github.com/syntax-tree/hast-util-to-dom

[rehype-dom-parse]: https://github.com/rehypejs/rehype-dom/tree/main/packages/rehype-dom-parse

[jsdom]: https://github.com/jsdom/jsdom

[fromdom]: #fromdomtree-options

[options]: #options

[aftertransform]: #aftertransform

0 comments on commit 46a4e51

Please sign in to comment.