{"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},"bugs":{"url":"https://github.com/syntax-tree/hast-util-from-parse5/issues"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"}],"dependencies":{"@types/hast":"^3.0.0","@types/unist":"^3.0.0","devlop":"^1.0.0","hastscript":"^9.0.0","property-information":"^6.0.0","vfile":"^6.0.0","vfile-location":"^5.0.0","web-namespaces":"^2.0.0"},"description":"hast utility to transform from a `parse5` AST","devDependencies":{"@types/node":"^22.0.0","c8":"^10.0.0","is-hidden":"^2.0.0","parse5":"^7.0.0","prettier":"^3.0.0","remark-cli":"^12.0.0","remark-preset-wooorm":"^10.0.0","to-vfile":"^8.0.0","type-coverage":"^2.0.0","typescript":"^5.0.0","unist-util-visit":"^5.0.0","xo":"^0.59.0"},"exports":"./index.js","funding":{"type":"opencollective","url":"https://opencollective.com/unified"},"keywords":["ast","change","hast-util","hast","transform","unist","utility","util"],"license":"MIT","name":"hast-util-from-parse5","prettier":{"bracketSpacing":false,"semi":false,"singleQuote":true,"tabWidth":2,"trailingComma":"none","useTabs":false},"remarkConfig":{"plugins":["remark-preset-wooorm"]},"repository":{"type":"git","url":"git+https://github.com/syntax-tree/hast-util-from-parse5.git"},"scripts":{"build":"tsc --build --clean && tsc --build && type-coverage","format":"remark --frail --quiet --output -- . && prettier --log-level warn --write -- . && xo --fix","test-api":"node --conditions development test/index.js","test-coverage":"c8 --100 --reporter lcov -- npm run test-api","test":"npm run build && npm run format && npm run test-coverage"},"sideEffects":false,"typeCoverage":{"atLeast":100,"strict":true},"type":"module","version":"8.0.2","xo":{"overrides":[{"files":["**/*.d.ts"],"rules":{"@typescript-eslint/array-type":["error",{"default":"generic"}],"@typescript-eslint/ban-types":["error",{"extendDefaults":true}],"@typescript-eslint/consistent-type-definitions":["error","interface"]}},{"files":"test/**/*.js","rules":{"no-await-in-loop":"off"}}],"prettier":true,"rules":{"max-depth":"off","unicorn/prefer-at":"off"}},"_id":"hast-util-from-parse5@8.0.2","gitHead":"3cff4a63fe824109bdee6b09a097d3d770e05a16","types":"./index.d.ts","homepage":"https://github.com/syntax-tree/hast-util-from-parse5#readme","_nodeVersion":"23.1.0","_npmVersion":"10.9.0","dist":{"integrity":"sha512-SfMzfdAi/zAoZ1KkFEyyeXBn7u/ShQrfd675ZEE9M3qj+PMFX05xubzRyF76CCSJu8au9jgVxDV1+okFvgZU4A==","shasum":"29b42758ba96535fd6021f0f533c000886c0f00f","tarball":"http://registry-npm.ywwl.com/hast-util-from-parse5/download/hast-util-from-parse5-8.0.2.tgz","fileCount":8,"unpackedSize":24777,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICoyeYPvBmeGvff9N4wJl5ndn7UOy8y3X+MCSU4kWTkZAiEA4grVL+KF4VB9+jpqUK+oqLEW5NePjXgSxe85BBKIJBI="}],"size":8103,"noattachment":false,"key":"/hast-util-from-parse5/-/hast-util-from-parse5-8.0.2.tgz"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hast-util-from-parse5_8.0.2_1732005888131_0.9415634299628173"},"_hasShrinkwrap":false,"readme":"# hast-util-from-parse5\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 to transform from [`parse5`][parse5]s AST.\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  * [`fromParse5(tree[, options])`](#fromparse5tree-options)\n  * [`Options`](#options)\n  * [`Space`](#space-1)\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 can turn a parse5 tree into a hast tree.\n\n## When should I use this?\n\nYou can use this package when using `parse5` as an HTML parser and wanting to\nwork with hast.\n\nThe utility [`hast-util-to-parse5`][hast-util-to-parse5] does the inverse of\nthis utility.\nIt generates `parse5`s AST again.\n\nThe utility [`hast-util-from-html`][hast-util-from-html] wraps this utility and\n`parse5` to both parse HTML and generate hast from it.\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-parse5\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {fromParse5} from \"https://esm.sh/hast-util-from-parse5@8\"\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n<script type=\"module\">\n  import {fromParse5} from \"https://esm.sh/hast-util-from-parse5@8?bundle\"\n</script>\n```\n\n## Use\n\nSay our document `example.html` contains:\n\n```html\n<!doctype html><title>Hello!</title><h1 id=\"world\">World!<!--after-->\n```\n\n…and our module `example.js` looks as follows:\n\n```js\nimport {fromParse5} from 'hast-util-from-parse5'\nimport {parse} from 'parse5'\nimport {read} from 'to-vfile'\nimport {inspect} from 'unist-util-inspect'\n\nconst file = await read('example.html')\nconst p5ast = parse(String(file), {sourceCodeLocationInfo: true})\nconst hast = fromParse5(p5ast, {file})\n\nconsole.log(inspect(hast))\n```\n\n…now running `node example.js` yields:\n\n```text\nroot[2] (1:1-2:1, 0-70)\n│ data: {\"quirksMode\":false}\n├─0 doctype (1:1-1:16, 0-15)\n└─1 element<html>[2]\n    │ properties: {}\n    ├─0 element<head>[1]\n    │   │ properties: {}\n    │   └─0 element<title>[1] (1:16-1:37, 15-36)\n    │       │ properties: {}\n    │       └─0 text \"Hello!\" (1:23-1:29, 22-28)\n    └─1 element<body>[1]\n        │ properties: {}\n        └─0 element<h1>[3] (1:37-2:1, 36-70)\n            │ properties: {\"id\":\"world\"}\n            ├─0 text \"World!\" (1:52-1:58, 51-57)\n            ├─1 comment \"after\" (1:58-1:70, 57-69)\n            └─2 text \"\\n\" (1:70-2:1, 69-70)\n```\n\n## API\n\nThis package exports the identifier [`fromParse5`][api-from-parse5].\nThere is no default export.\n\n### `fromParse5(tree[, options])`\n\nTransform a `parse5` AST to hast.\n\n###### Parameters\n\n* `tree` ([`Parse5Node`][parse5-node])\n  — `parse5` tree to transform\n* `options` ([`Options`][api-options], optional)\n  — configuration\n\n###### Returns\n\nhast tree ([`HastNode`][hast-node]).\n\n### `Options`\n\nConfiguration (TypeScript type).\n\n##### Fields\n\n###### `file`\n\nFile used to add positional info to nodes ([`VFile`][vfile], optional).\n\nIf given, the file should represent the original HTML source.\n\n###### `space`\n\nWhich space the document is in ([`Space`][api-space], default: `'html'`).\n\nWhen an `<svg>` element is found in the HTML space, this package already\nautomatically switches to and from the SVG space when entering and exiting\nit.\n\n###### `verbose`\n\nWhether to add extra positional info about starting tags, closing tags,\nand attributes to elements (`boolean`, default: `false`).\n\n> 👉 **Note**: only used when `file` is given.\n\nFor the following HTML:\n\n```html\n<img src=\"http://example.com/fav.ico\" alt=\"foo\" title=\"bar\">\n```\n\nThe verbose info would looks as follows:\n\n```js\n{\n  type: 'element',\n  tagName: 'img',\n  properties: {src: 'http://example.com/fav.ico', alt: 'foo', title: 'bar'},\n  children: [],\n  data: {\n    position: {\n      opening: {\n        start: {line: 1, column: 1, offset: 0},\n        end: {line: 1, column: 61, offset: 60}\n      },\n      closing: null,\n      properties: {\n        src: {\n          start: {line: 1, column: 6, offset: 5},\n          end: {line: 1, column: 38, offset: 37}\n        },\n        alt: {\n          start: {line: 1, column: 39, offset: 38},\n          end: {line: 1, column: 48, offset: 47}\n        },\n        title: {\n          start: {line: 1, column: 49, offset: 48},\n          end: {line: 1, column: 60, offset: 59}\n        }\n      }\n    }\n  },\n  position: {\n    start: {line: 1, column: 1, offset: 0},\n    end: {line: 1, column: 61, offset: 60}\n  }\n}\n```\n\n### `Space`\n\nNamespace (TypeScript type).\n\n###### Type\n\n```ts\ntype Space = 'html' | 'svg'\n```\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types [`Options`][api-options] and\n[`Space`][api-space].\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, `hast-util-from-parse5@^8`,\ncompatible with Node.js 16.\n\n## Security\n\nUse of `hast-util-from-parse5` can open you up to a\n[cross-site scripting (XSS)][xss] attack if Parse5’s AST is unsafe.\n\n## Related\n\n* [`hast-util-to-parse5`](https://github.com/syntax-tree/hast-util-to-parse5)\n  — transform hast to Parse5’s AST\n* [`hast-util-to-nlcst`](https://github.com/syntax-tree/hast-util-to-nlcst)\n  — transform hast to nlcst\n* [`hast-util-to-mdast`](https://github.com/syntax-tree/hast-util-to-mdast)\n  — transform hast to mdast\n* [`hast-util-to-xast`](https://github.com/syntax-tree/hast-util-to-xast)\n  — transform hast to xast\n* [`mdast-util-to-hast`](https://github.com/syntax-tree/mdast-util-to-hast)\n  — transform mdast to hast\n* [`mdast-util-to-nlcst`](https://github.com/syntax-tree/mdast-util-to-nlcst)\n  — transform mdast to nlcst\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] © [Titus Wormer][author]\n\n<!-- Definitions -->\n\n[build-badge]: https://github.com/syntax-tree/hast-util-from-parse5/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/hast-util-from-parse5/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-from-parse5.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/hast-util-from-parse5\n\n[downloads-badge]: https://img.shields.io/npm/dm/hast-util-from-parse5.svg\n\n[downloads]: https://www.npmjs.com/package/hast-util-from-parse5\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=hast-util-from-parse5\n\n[size]: https://bundlejs.com/?q=hast-util-from-parse5\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://wooorm.com\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[parse5]: https://github.com/inikulin/parse5\n\n[parse5-node]: https://github.com/inikulin/parse5/blob/master/packages/parse5/lib/tree-adapters/default.ts\n\n[vfile]: https://github.com/vfile/vfile\n\n[hast-util-to-parse5]: https://github.com/syntax-tree/hast-util-to-parse5\n\n[hast]: https://github.com/syntax-tree/hast\n\n[hast-util-from-html]: https://github.com/syntax-tree/hast-util-from-html\n\n[hast-node]: https://github.com/syntax-tree/hast#nodes\n\n[api-from-parse5]: #fromparse5tree-options\n\n[api-options]: #options\n\n[api-space]: #space-1\n","publish_time":1732005888306,"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"},{"name":"kmck","email":"keith@mcknig.ht"}],"_cnpm_publish_time":1732005888306,"dist-tags":{"latest":"8.0.4"}}