{"id":13837617,"url":"https://github.com/syntax-tree/hast-util-from-html-isomorphic","last_synced_at":"2025-06-29T22:03:39.777Z","repository":{"id":143172457,"uuid":"614785351","full_name":"syntax-tree/hast-util-from-html-isomorphic","owner":"syntax-tree","description":"hast utility that turns HTML into a syntax tree (while being small in browsers)","archived":false,"fork":false,"pushed_at":"2023-08-08T13:08:54.000Z","size":27,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-05-27T04:41:44.120Z","etag":null,"topics":["dom","hast","hast-util","html","parse","unist"],"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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/syntax-tree.png","metadata":{"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},"funding":{"github":"unifiedjs","open_collective":"unified"}},"created_at":"2023-03-16T10:12:14.000Z","updated_at":"2023-12-27T04:20:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"406f6781-556e-4a43-b438-dc45c242f06f","html_url":"https://github.com/syntax-tree/hast-util-from-html-isomorphic","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/syntax-tree/hast-util-from-html-isomorphic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-from-html-isomorphic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-from-html-isomorphic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-from-html-isomorphic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-from-html-isomorphic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syntax-tree","download_url":"https://codeload.github.com/syntax-tree/hast-util-from-html-isomorphic/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-from-html-isomorphic/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262465750,"owners_count":23315638,"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","parse","unist"],"created_at":"2024-08-04T15:01:17.146Z","updated_at":"2025-06-29T22:03:39.754Z","avatar_url":"https://github.com/syntax-tree.png","language":"JavaScript","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified"],"categories":["JavaScript"],"sub_categories":[],"readme":"# hast-util-from-html-isomorphic\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n[![Sponsors][sponsors-badge]][collective]\n[![Backers][backers-badge]][collective]\n[![Chat][chat-badge]][chat]\n\n[hast][] utility that turns HTML into a syntax tree, using browser APIs\nwhen available, so it has a smaller bundle size there.\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    *   [`fromHtmlIsomorphic(value[, options])`](#fromhtmlisomorphicvalue-options)\n    *   [`Options`](#options)\n*   [Examples](#examples)\n    *   [Example: fragment versus document](#example-fragment-versus-document)\n*   [Syntax](#syntax)\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 takes HTML input and turns it into a hast syntax\ntree.\n\nIn a browser, this uses [`hast-util-from-dom`][hast-util-from-dom],\notherwise it uses [`hast-util-from-html`][hast-util-from-html].\n\n## When should I use this?\n\nIf you want to get a syntax tree without positional info, and your code should\nbe isomorphic (it could run anywhere), as it results in a smaller bundle size.\n\nIf you need positional information, use\n[`hast-util-from-html`][hast-util-from-html].\n\nIf you don’t care about positional info and your code only runs in browsers,\nuse [`hast-util-from-dom`][hast-util-from-dom].\n\nFinally you can use the utility [`hast-util-to-html`][hast-util-to-html],\nor [`hast-util-to-dom`][hast-util-to-dom] with `.outerHTML`, to do the inverse\nof this utility.\nThat turns hast into HTML.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install hast-util-from-html-isomorphic\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {fromHtmlIsomorphic} from 'https://esm.sh/hast-util-from-html-isomorphic@2'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {fromHtmlIsomorphic} from 'https://esm.sh/hast-util-from-html-isomorphic@2?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\n```js\nimport {fromHtmlIsomorphic} from 'hast-util-from-html-isomorphic'\n\nconst tree = fromHtmlIsomorphic('\u003ch1\u003eHello, world!\u003c/h1\u003e', {fragment: true})\n\nconsole.log(tree)\n```\n\nYields (positional info and data omitted for brevity):\n\n```js\n{\n  type: 'root',\n  children: [\n    {\n      type: 'element',\n      tagName: 'h1',\n      properties: {},\n      children: [Array],\n    }\n  ]\n}\n```\n\n## API\n\nThis package exports the identifier\n[`fromHtmlIsomorphic`][api-from-html-isomorphic].\nThere is no default export.\n\n### `fromHtmlIsomorphic(value[, options])`\n\nTurn serialized HTML into a hast tree.\n\n###### Parameters\n\n*   `value` (`string`)\n    — serialized HTML to parse\n*   `options` ([`Options`][api-options], optional)\n    — configuration\n\n###### Returns\n\nTree ([`Root`][root]).\n\n### `Options`\n\nConfiguration (TypeScript type).\n\n##### Fields\n\n###### `fragment`\n\nWhether to parse as a fragment (`boolean`, default: `false`).\nThe default is to expect a whole document.\nIn document mode, unopened `html`, `head`, and `body` elements are opened.\n\n## Examples\n\n### Example: fragment versus document\n\nThe following example shows the difference between parsing as a document and\nparsing as a fragment:\n\n```js\nimport {fromHtml} from 'hast-util-from-html-isomorphic'\n\nconst doc = '\u003ctitle\u003eHi!\u003c/title\u003e\u003ch1\u003eHello!\u003c/h1\u003e'\n\nconsole.log(fromHtml(doc))\n\nconsole.log(fromHtml(doc, {fragment: true}))\n```\n\n…yields (positional info and data omitted for brevity):\n\n```js\n{\n  type: 'root',\n  children: [\n    {type: 'element', tagName: 'html', properties: {}, children: [Array]}\n  ]\n}\n```\n\n```js\n{\n  type: 'root',\n  children: [\n    {type: 'element', tagName: 'title', properties: {}, children: [Array]},\n    {type: 'element', tagName: 'h1', properties: {}, children: [Array]}\n  ]\n}\n```\n\n\u003e 👉 **Note**: observe that when a whole document is expected (first example),\n\u003e missing elements are opened and closed.\n\n## Syntax\n\nHTML is parsed according to WHATWG HTML (the living standard), which is also\nfollowed by browsers such as Chrome and Firefox.\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional type [`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, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line,\n`hast-util-from-html-isomorphic@^1`, compatible with Node.js 16.\n\n## Security\n\nParsing HTML is safe but using user-provided content can open you up to a\n[cross-site scripting (XSS)][xss] attack.\nUse [`hast-util-santize`][hast-util-sanitize] to make the hast tree safe.\n\n## Related\n\n*   [`hast-util-from-html`](https://github.com/syntax-tree/hast-util-from-html)\n    — parse html into hast\n*   [`hast-util-from-dom`](https://github.com/syntax-tree/hast-util-from-dom)\n    — parse a DOM tree into hast\n*   [`hast-util-to-html`](https://github.com/syntax-tree/hast-util-to-html)\n    — serialize hast\n*   [`hast-util-sanitize`](https://github.com/syntax-tree/hast-util-sanitize)\n    — sanitize hast\n*   [`xast-util-from-xml`][xast-util-from-xml]\n    — parse XML\n\n## Contribute\n\nSee [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for\nways to get started.\nSee [`support.md`][support] for ways to get help.\n\nThis project has a [code of conduct][coc].\nBy interacting with this repository, organization, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][license] © [Remco Haszing][author]\n\n\u003c!-- Definitions --\u003e\n\n[build-badge]: https://github.com/syntax-tree/hast-util-from-html-isomorphic/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/hast-util-from-html-isomorphic/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-from-html-isomorphic.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/hast-util-from-html-isomorphic\n\n[downloads-badge]: https://img.shields.io/npm/dm/hast-util-from-html-isomorphic.svg\n\n[downloads]: https://www.npmjs.com/package/hast-util-from-html-isomorphic\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size\u0026query=$.size.compressedSize\u0026url=https://deno.bundlejs.com/?q=hast-util-from-html-isomorphic\n\n[size]: https://bundlejs.com/?q=hast-util-from-html-isomorphic\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[collective]: https://opencollective.com/unified\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[chat]: https://github.com/syntax-tree/unist/discussions\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[typescript]: https://www.typescriptlang.org\n\n[license]: license\n\n[author]: https://github.com/remcohaszing\n\n[health]: https://github.com/syntax-tree/.github\n\n[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting\n\n[hast]: https://github.com/syntax-tree/hast\n\n[root]: https://github.com/syntax-tree/hast#root\n\n[hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize\n\n[hast-util-from-dom]: https://github.com/syntax-tree/hast-util-from-dom\n\n[hast-util-from-html]: https://github.com/syntax-tree/hast-util-from-html\n\n[hast-util-to-dom]: https://github.com/syntax-tree/hast-util-to-dom\n\n[hast-util-to-html]: https://github.com/syntax-tree/hast-util-to-html\n\n[xast-util-from-xml]: https://github.com/syntax-tree/xast-util-from-xml\n\n[api-from-html-isomorphic]: #fromhtmlisomorphicvalue-options\n\n[api-options]: #options\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fhast-util-from-html-isomorphic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyntax-tree%2Fhast-util-from-html-isomorphic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fhast-util-from-html-isomorphic/lists"}