{"id":13716793,"url":"https://github.com/syntax-tree/hast-util-to-dom","last_synced_at":"2025-06-29T22:03:38.348Z","repository":{"id":33224437,"uuid":"136044109","full_name":"syntax-tree/hast-util-to-dom","owner":"syntax-tree","description":"utility to transform hast to a DOM tree","archived":false,"fork":false,"pushed_at":"2025-02-19T15:16:40.000Z","size":962,"stargazers_count":20,"open_issues_count":0,"forks_count":8,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-05-25T18:48:52.533Z","etag":null,"topics":["dom","hast","hast-util","html","syntax-tree","unist","util"],"latest_commit_sha":null,"homepage":"https://unifiedjs.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/syntax-tree.png","metadata":{"funding":{"github":"unifiedjs","open_collective":"unified","thanks_dev":"u/gh/syntax-tree"},"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-06-04T15:16:58.000Z","updated_at":"2025-02-19T15:16:58.000Z","dependencies_parsed_at":"2024-01-14T22:03:39.887Z","dependency_job_id":"974612c9-41d3-476c-aa1a-16a6124a9376","html_url":"https://github.com/syntax-tree/hast-util-to-dom","commit_stats":{"total_commits":83,"total_committers":5,"mean_commits":16.6,"dds":"0.12048192771084343","last_synced_commit":"8ded2e44dc4b7b753de4e755bebd359e11a542e9"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/syntax-tree/hast-util-to-dom","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-to-dom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-to-dom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-to-dom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-to-dom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syntax-tree","download_url":"https://codeload.github.com/syntax-tree/hast-util-to-dom/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-to-dom/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262270689,"owners_count":23285172,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dom","hast","hast-util","html","syntax-tree","unist","util"],"created_at":"2024-08-03T00:01:14.449Z","updated_at":"2025-06-29T22:03:38.325Z","avatar_url":"https://github.com/syntax-tree.png","language":"JavaScript","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified","https://thanks.dev/u/gh/syntax-tree"],"categories":["hast utilities"],"sub_categories":[],"readme":"# hast-util-to-dom\n\n[![Build][badge-build-image]][badge-build-url]\n[![Coverage][badge-coverage-image]][badge-coverage-url]\n[![Downloads][badge-downloads-image]][badge-downloads-url]\n[![Size][badge-size-image]][badge-size-url]\n\n[hast][github-hast] utility to transform to a [DOM][mozilla-dom] tree.\n\n## Contents\n\n* [What is this?](#what-is-this)\n* [When should I use this?](#when-should-i-use-this)\n* [Install](#install)\n* [Use](#use)\n* [API](#api)\n  * [`toDom(tree[, options])`](#todomtree-options)\n  * [`AfterTransform`](#aftertransform)\n  * [`Options`](#options)\n* [Syntax tree](#syntax-tree)\n* [Types](#types)\n* [Compatibility](#compatibility)\n* [Security](#security)\n* [Related](#related)\n* [Contribute](#contribute)\n* [License](#license)\n\n## What is this?\n\nThis package is a utility that creates a DOM tree\n(defaulting to the actual DOM but also supporting things like\n[`jsdom`][github-jsdom])\nfrom a [hast][github-hast] (HTML) syntax tree.\n\n## When should I use this?\n\nYou can use this project when you want to turn hast into a DOM in browsers,\neither to use it directly on a page,\nor to enable the use of DOM APIs\n(such as `querySelector` to find things or `innerHTML` to serialize stuff).\n\nThe hast utility [`hast-util-from-dom`][github-hast-util-from-dom] does the\ninverse of this utility.\nIt turns DOM trees into hast.\n\nThe rehype plugin [`rehype-dom-stringify`][github-rehype-dom-stringify] wraps\nthis utility to serialize as HTML with DOM APIs.\n\n## Install\n\nThis package is [ESM only][github-gist-esm].\nIn Node.js (version 16+),\ninstall with [npm][npmjs-install]:\n\n```sh\nnpm install hast-util-to-dom\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {toDom} from 'https://esm.sh/hast-util-to-dom@4'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {toDom} from 'https://esm.sh/hast-util-to-dom@4?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\nSay our page `example.html` looks as follows:\n\n```html\n\u003c!doctype html\u003e\n\u003ctitle\u003eExample\u003c/title\u003e\n\u003cbody\u003e\n  \u003cscript type=\"module\"\u003e\n    import {h} from 'https://esm.sh/hastscript?bundle'\n    import {toDom} from 'https://esm.sh/hast-util-to-dom?bundle'\n\n    const tree = h('main', [\n      h('h1', 'Hi'),\n      h('p', [h('em', 'Hello'), ', world!'])\n    ])\n\n    document.body.append(toDom(tree))\n  \u003c/script\u003e\n```\n\nNow running `open example.html` shows the\n`main`,\n`h1`,\nand `p` elements on the page.\n\n## API\n\nThis package exports the identifier [`toDom`][api-to-dom].\nThere is no default export.\n\n### `toDom(tree[, options])`\n\nTurn a hast tree into a DOM tree.\n\n###### Parameters\n\n* `tree`\n  ([`HastNode`][github-hast-nodes])\n  — tree to transform\n* `options`\n  ([`Options`][api-options], optional)\n  — configuration\n\n###### Returns\n\nDOM node ([`DomNode`][mozilla-dom-node]).\n\n### `AfterTransform`\n\nCallback called when each node is transformed (TypeScript type).\n\n###### Parameters\n\n* `hastNode` ([`HastNode`][github-hast-nodes])\n  — hast node that was handled\n* `domNode` ([`DomNode`][mozilla-dom-node])\n  — corresponding DOM node\n\n###### Returns\n\nNothing.\n\n### `Options`\n\nConfiguration (TypeScript type).\n\n###### Fields\n\n* `afterTransform`\n  ([`AfterTransform`][api-after-transform], optional)\n  — callback called when each node is transformed\n* `document`\n  (`Document`, default: `globalThis.document`)\n  — document interface to use.\n* `fragment`\n  (`boolean`, default: `false`)\n  — whether to return a DOM fragment (`true`) or a whole document (`false`)\n* `namespace`\n  (`string`, default: depends)\n  — namespace to use to create elements\n\n## Syntax tree\n\nThe syntax tree is [hast][github-hast].\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types [`AfterTransform`][api-after-transform] and\n[`Options`][api-options].\n\n## Compatibility\n\nProjects maintained by the unified collective are compatible with maintained\nversions of Node.js.\n\nWhen we cut a new major release,\nwe drop support for unmaintained versions of Node.\nThis means we try to keep the current release line,\n`hast-util-to-dom@4`,\ncompatible with Node.js 16.\n\n## Security\n\nUse of `hast-util-to-dom` can open you up to a\n[cross-site scripting (XSS)][wikipedia-xss] attack if the hast tree is unsafe.\nUse [`hast-util-santize`][github-hast-util-sanitize] to make the hast tree\nsafe.\n\n## Related\n\n* [`hast-util-sanitize`][github-hast-util-sanitize]\n  — sanitize hast nodes\n* [`hast-util-to-html`](https://github.com/syntax-tree/hast-util-to-html)\n  — serialize as HTML\n* [`hast-util-from-dom`][github-hast-util-from-dom]\n  — create a hast tree from a DOM tree\n\n## Contribute\n\nSee [`contributing.md`][health-contributing]\nin\n[`syntax-tree/.github`][health]\nfor ways to get started.\nSee [`support.md`][health-support] for ways to get help.\n\nThis project has a [code of conduct][health-coc].\nBy interacting with this repository,\norganization,\nor community you agree to abide by its terms.\n\n## License\n\n[ISC][file-license] © [Keith McKnight][mcknight]\n\n\u003c!-- Definitions --\u003e\n\n[api-after-transform]: #aftertransform\n\n[api-options]: #options\n\n[api-to-dom]: #todomtree-options\n\n[badge-build-image]: https://github.com/syntax-tree/hast-util-to-dom/workflows/main/badge.svg\n\n[badge-build-url]: https://github.com/syntax-tree/hast-util-to-dom/actions\n\n[badge-coverage-image]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-to-dom.svg\n\n[badge-coverage-url]: https://codecov.io/github/syntax-tree/hast-util-to-dom\n\n[badge-downloads-image]: https://img.shields.io/npm/dm/hast-util-to-dom.svg\n\n[badge-downloads-url]: https://www.npmjs.com/package/hast-util-to-dom\n\n[badge-size-image]: https://img.shields.io/bundlejs/size/hast-util-to-dom\n\n[badge-size-url]: https://bundlejs.com/?q=hast-util-to-dom\n\n[esmsh]: https://esm.sh\n\n[file-license]: license\n\n[github-gist-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[github-hast]: https://github.com/syntax-tree/hast\n\n[github-hast-nodes]: https://github.com/syntax-tree/hast#nodes\n\n[github-hast-util-from-dom]: https://github.com/syntax-tree/hast-util-from-dom\n\n[github-hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize\n\n[github-jsdom]: https://github.com/jsdom/jsdom\n\n[github-rehype-dom-stringify]: https://github.com/rehypejs/rehype-dom/tree/main/packages/rehype-dom-stringify\n\n[health]: https://github.com/syntax-tree/.github\n\n[health-coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[health-contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[health-support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[mcknight]: https://keith.mcknig.ht\n\n[mozilla-dom]: https://developer.mozilla.org/docs/Web/API/Document_Object_Model\n\n[mozilla-dom-node]: https://developer.mozilla.org/docs/Web/API/Node\n\n[npmjs-install]: https://docs.npmjs.com/cli/install\n\n[typescript]: https://www.typescriptlang.org\n\n[wikipedia-xss]: https://en.wikipedia.org/wiki/Cross-site_scripting\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fhast-util-to-dom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyntax-tree%2Fhast-util-to-dom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fhast-util-to-dom/lists"}