{"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},"bugs":{"url":"https://github.com/syntax-tree/hast-util-to-html/issues"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"}],"dependencies":{"@types/hast":"^3.0.0","@types/unist":"^3.0.0","ccount":"^2.0.0","comma-separated-tokens":"^2.0.0","hast-util-whitespace":"^3.0.0","html-void-elements":"^3.0.0","mdast-util-to-hast":"^13.0.0","property-information":"^7.0.0","space-separated-tokens":"^2.0.0","stringify-entities":"^4.0.0","zwitch":"^2.0.4"},"description":"hast utility to serialize to HTML","devDependencies":{"@types/node":"^22.0.0","c8":"^10.0.0","hastscript":"^9.0.0","prettier":"^3.0.0","remark-cli":"^12.0.0","remark-preset-wooorm":"^11.0.0","type-coverage":"^2.0.0","typescript":"^5.0.0","xo":"^0.60.0"},"exports":"./index.js","funding":{"type":"opencollective","url":"https://opencollective.com/unified"},"keywords":["hast-util","hast","html","serialize","stringify","tostring","unist","utility","util"],"license":"MIT","name":"hast-util-to-html","prettier":{"bracketSpacing":false,"semi":false,"singleQuote":true,"tabWidth":2,"trailingComma":"none","useTabs":false},"remarkConfig":{"plugins":["remark-preset-wooorm",["remark-lint-no-html",false]]},"repository":{"type":"git","url":"git+https://github.com/syntax-tree/hast-util-to-html.git"},"scripts":{"build":"tsc --build --clean && tsc --build && type-coverage","format":"remark --frail --output --quiet -- . && 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":"9.0.5","xo":{"overrides":[{"files":["test/**/*.js"],"rules":{"no-await-in-loop":"off"}}],"prettier":true,"rules":{"complexity":"off","unicorn/prefer-at":"off","unicorn/prefer-string-replace-all":"off"}},"_id":"hast-util-to-html@9.0.5","gitHead":"d115f5beab200c819699e1db9d7eb7b5b1009a21","types":"./index.d.ts","homepage":"https://github.com/syntax-tree/hast-util-to-html#readme","_nodeVersion":"23.1.0","_npmVersion":"11.1.0","dist":{"integrity":"sha512-OguPdidb+fbHQSU4Q4ZiLKnzWo8Wwsf5bZfbvu7//a9oTYoqD/fWpe96NuHkoS9h0ccGOTe0C4NGXdtS0iObOw==","shasum":"ccc673a55bb8e85775b08ac28380f72d47167005","tarball":"http://registry-npm.ywwl.com/hast-util-to-html/download/hast-util-to-html-9.0.5.tgz","fileCount":42,"unpackedSize":71798,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDch7pNepqiT/E/+ijRlWPAk19zb/3L6PI3mP6d1Z4rjwIgKsH3R3FXpqVYxzYlg9WuG+v6+J8bp4xKgjw2Uq4CT4Y="}],"size":17715,"noattachment":false,"key":"/hast-util-to-html/-/hast-util-to-html-9.0.5.tgz"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"},{"name":"kmck","email":"keith@mcknig.ht"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/hast-util-to-html_9.0.5_1739972086934_0.8231511887228842"},"_hasShrinkwrap":false,"readme":"# hast-util-to-html\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 serialize hast as HTML.\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  * [`toHtml(tree[, options])`](#tohtmltree-options)\n  * [`CharacterReferences`](#characterreferences)\n  * [`Options`](#options)\n  * [`Quote`](#quote-1)\n  * [`Space`](#space-1)\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 turns a hast tree into a string of HTML.\n\n## When should I use this?\n\nYou can use this utility when you want to get the serialized HTML that is\nrepresented by the syntax tree,\neither because you’re done with the syntax tree,\nor because you’re integrating with another tool that does not support syntax\ntrees.\n\nThis utility has many options to configure how the HTML is serialized.\nThese options help when building tools that make output pretty (such as\nformatters) or ugly (such as minifiers).\n\nThe utility [`hast-util-from-html`][github-hast-util-from-html] does the\ninverse of this utility.\nIt turns HTML into hast.\n\nThe rehype plugin [`rehype-stringify`][github-rehype-stringify] wraps this\nutility to also serialize HTML at a higher-level (easier) abstraction.\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-html\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {toHtml} from 'https://esm.sh/hast-util-to-html@9'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n<script type=\"module\">\n  import {toHtml} from 'https://esm.sh/hast-util-to-html@9?bundle'\n</script>\n```\n\n## Use\n\n```js\nimport {h} from 'hastscript'\nimport {toHtml} from 'hast-util-to-html'\n\nconst tree = h('.alpha', [\n  'bravo ',\n  h('b', 'charlie'),\n  ' delta ',\n  h('a.echo', {download: true}, 'foxtrot')\n])\n\nconsole.log(toHtml(tree))\n```\n\nYields:\n\n```html\n<div class=\"alpha\">bravo <b>charlie</b> delta <a class=\"echo\" download>foxtrot</a></div>\n```\n\n## API\n\nThis package exports the identifier [`toHtml`][api-to-html].\nThere is no default export.\n\n### `toHtml(tree[, options])`\n\nSerialize hast as HTML.\n\n###### Parameters\n\n* `tree`\n  ([`Node`][github-hast-nodes] or `Array<Node>`)\n  — tree to serialize\n* `options`\n  ([`Options`][api-options], optional)\n  — configuration\n\n###### Returns\n\nSerialized HTML (`string`).\n\n### `CharacterReferences`\n\nHow to serialize character references (TypeScript type).\n\n##### Fields\n\n###### `useNamedReferences`\n\nPrefer named character references (`&amp;`) where possible\n(`boolean`, default: `false`).\n\n###### `omitOptionalSemicolons`\n\nWhether to omit semicolons when possible\n(`boolean`, default: `false`).\n\n> ⚠️ **Note**:\n> this creates what HTML calls “parse errors” but is otherwise still valid HTML:\n> don’t use this except when building a minifier;\n> omitting semicolons is possible for certain named and numeric references in\n> some cases.\n\n###### `useShortestReferences`\n\nPrefer the shortest possible reference,\nif that results in less bytes\n(`boolean`, default: `false`).\n\n> ⚠️ **Note**:\n> `useNamedReferences` can be omitted when using `useShortestReferences`.\n\n### `Options`\n\nConfiguration (TypeScript type).\n\n##### Fields\n\n###### `allowDangerousCharacters`\n\nDo not encode some characters which cause XSS vulnerabilities in older browsers\n(`boolean`, default: `false`).\n\n> ⚠️ **Danger**:\n> only set this if you completely trust the content.\n\n###### `allowDangerousHtml`\n\nAllow `raw` nodes and insert them as raw HTML\n(`boolean`, default: `false`).\n\nWhen `false`,\n`Raw` nodes are encoded.\n\n> ⚠️ **Danger**:\n> only set this if you completely trust the content.\n\n###### `allowParseErrors`\n\nDo not encode characters which cause parse errors\n(even though they work),\nto save bytes\n(`boolean`, default: `false`).\n\nNot used in the SVG space.\n\n> 👉 **Note**:\n> intentionally creates parse errors in markup\n> (how parse errors are handled is well defined,\n> so this works but isn’t pretty).\n\n###### `bogusComments`\n\nUse “bogus comments” instead of comments to save byes:\n`<?charlie>` instead of `<!--charlie-->`\n(`boolean`, default: `false`).\n\n> 👉 **Note**:\n> intentionally creates parse errors in markup\n> (how parse errors are handled is well defined,\n> so this works but isn’t pretty).\n\n###### `characterReferences`\n\nConfigure how to serialize character references\n([`CharacterReferences`][api-character-references], optional).\n\n###### `closeEmptyElements`\n\nClose SVG elements without any content with slash (`/`) on the opening tag\ninstead of an end tag:\n`<circle />` instead of `<circle></circle>`\n(`boolean`, default: `false`).\n\nSee `tightSelfClosing` to control whether a space is used before the slash.\n\nNot used in the HTML space.\n\n###### `closeSelfClosing`\n\nClose self-closing nodes with an extra slash (`/`):\n`<img />` instead of `<img>`\n(`boolean`, default: `false`).\n\nSee `tightSelfClosing` to control whether a space is used before the slash.\n\nNot used in the SVG space.\n\n###### `collapseEmptyAttributes`\n\nCollapse empty attributes:\nget `class` instead of `class=\"\"`\n(`boolean`, default: `false`).\n\nNot used in the SVG space.\n\n> 👉 **Note**:\n> boolean attributes\n> (such as `hidden`)\n> are always collapsed.\n\n###### `omitOptionalTags`\n\nOmit optional opening and closing tags\n(`boolean`, default: `false`).\n\nFor example,\nin `<ol><li>one</li><li>two</li></ol>`,\nboth `</li>` closing tags can be omitted.\nThe first because it’s followed by another `li`,\nthe last because it’s followed by nothing.\n\nNot used in the SVG space.\n\n###### `preferUnquoted`\n\nLeave attributes unquoted if that results in less bytes\n(`boolean`, default: `false`).\n\nNot used in the SVG space.\n\n###### `quote`\n\nPreferred quote to use\n([`Quote`][api-quote], default: `'\"'`).\n\n###### `quoteSmart`\n\nUse the other quote if that results in less bytes\n(`boolean`, default: `false`).\n\n###### `space`\n\nWhich space the document is in\n([`Space`][api-space], default: `'html'`).\n\nWhen an `<svg>` element is found in the HTML space,\nthis package already automatically switches to and from the SVG space when\nentering and exiting it.\n\n> 👉 **Note**:\n> hast is not XML.\n> It supports SVG as embedded in HTML.\n> It does not support the features available in XML.\n> Passing SVG might break but fragments of modern SVG should be fine.\n> Use [`xast`][github-xast] if you need to support SVG as XML.\n\n###### `tightAttributes`\n\nJoin attributes together,\nwithout whitespace,\nif possible:\nget `class=\"a b\"title=\"c d\"` instead of `class=\"a b\" title=\"c d\"` to save bytes\n(`boolean`, default: `false`).\n\nNot used in the SVG space.\n\n> 👉 **Note**:\n> intentionally creates parse errors in markup\n> (how parse errors are handled is well defined,\n> so this works but isn’t pretty).\n\n###### `tightCommaSeparatedLists`\n\nJoin known comma-separated attribute values with just a comma (`,`),\ninstead of padding them on the right as well\n(`,␠`, where `␠` represents a space)\n(`boolean`, default: `false`).\n\n###### `tightDoctype`\n\nDrop unneeded spaces in doctypes:\n`<!doctypehtml>` instead of `<!doctype html>` to save bytes\n(`boolean`, default: `false`).\n\n> 👉 **Note**:\n> intentionally creates parse errors in markup\n> (how parse errors are handled is well defined,\n> so this works but isn’t pretty).\n\n###### `tightSelfClosing`\n\nDo not use an extra space when closing self-closing elements:\n`<img/>` instead of `<img />`\n(`boolean`, default: `false`).\n\n> 👉 **Note**:\n> only used if `closeSelfClosing: true` or `closeEmptyElements: true`.\n\n###### `upperDoctype`\n\nUse a `<!DOCTYPE…` instead of `<!doctype…`\n(`boolean`, default: `false`).\n\nUseless except for XHTML.\n\n###### `voids`\n\nTag names of elements to serialize without closing tag\n(`Array<string>`,\ndefault: [`html-void-elements`][github-html-void-elements]).\n\nNot used in the SVG space.\n\n> 👉 **Note**:\n> it’s highly unlikely that you want to pass this,\n> because hast is not for XML,\n> and HTML will not add more void elements.\n\n### `Quote`\n\nHTML quotes for attribute values (TypeScript type).\n\n###### Type\n\n```ts\ntype Quote = '\"' | \"'\"\n```\n\n### `Space`\n\nNamespace (TypeScript type).\n\n###### Type\n\n```ts\ntype Space = 'html' | 'svg'\n```\n\n## Syntax\n\nHTML is serialized according to WHATWG HTML (the living standard),\nwhich is also followed by browsers such as Chrome and Firefox.\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types\n[`CharacterReferences`][api-character-references],\n[`Options`][api-options],\n[`Quote`][api-quote],\nand\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,\nwe drop support for unmaintained versions of Node.\nThis means we try to keep the current release line,\n`hast-util-to-html@9`,\ncompatible with Node.js 16.\n\n## Security\n\nUse of `hast-util-to-html` 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\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[MIT][file-license] © [Titus Wormer][wooorm]\n\n<!-- Definitions -->\n\n[api-character-references]: #characterreferences\n\n[api-options]: #options\n\n[api-quote]: #quote-1\n\n[api-space]: #space-1\n\n[api-to-html]: #tohtmltree-options\n\n[badge-build-image]: https://github.com/syntax-tree/hast-util-to-html/workflows/main/badge.svg\n\n[badge-build-url]: https://github.com/syntax-tree/hast-util-to-html/actions\n\n[badge-coverage-image]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-to-html.svg\n\n[badge-coverage-url]: https://codecov.io/github/syntax-tree/hast-util-to-html\n\n[badge-downloads-image]: https://img.shields.io/npm/dm/hast-util-to-html.svg\n\n[badge-downloads-url]: https://www.npmjs.com/package/hast-util-to-html\n\n[badge-size-image]: https://img.shields.io/bundlejs/size/hast-util-to-html\n\n[badge-size-url]: https://bundlejs.com/?q=hast-util-to-html\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-html]: https://github.com/syntax-tree/hast-util-from-html\n\n[github-hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize\n\n[github-html-void-elements]: https://github.com/wooorm/html-void-elements\n\n[github-rehype-stringify]: https://github.com/rehypejs/rehype/tree/main/packages/rehype-stringify#readme\n\n[github-xast]: https://github.com/syntax-tree/xast\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[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\n[wooorm]: https://wooorm.com\n","publish_time":1739972087133,"_cnpm_publish_time":1739972087133,"dist-tags":{"latest":"9.0.6"}}