{"id":13447308,"url":"https://github.com/syntax-tree/hast-util-to-text","last_synced_at":"2026-01-14T02:53:37.804Z","repository":{"id":49260442,"uuid":"188060051","full_name":"syntax-tree/hast-util-to-text","owner":"syntax-tree","description":"utility to get the plain-text value of a node according to the `innerText` algorithm","archived":false,"fork":false,"pushed_at":"2024-04-16T10:33:09.000Z","size":183,"stargazers_count":21,"open_issues_count":0,"forks_count":2,"subscribers_count":7,"default_branch":"main","last_synced_at":"2026-01-04T11:30:49.131Z","etag":null,"topics":["hast","hast-util","html","inner-text","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":"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":"2019-05-22T14:54:21.000Z","updated_at":"2025-06-03T11:03:54.000Z","dependencies_parsed_at":"2024-06-18T15:31:55.775Z","dependency_job_id":"0ad49820-ee22-4c9d-a9ec-f1053b0024c4","html_url":"https://github.com/syntax-tree/hast-util-to-text","commit_stats":{"total_commits":62,"total_committers":1,"mean_commits":62.0,"dds":0.0,"last_synced_commit":"5a9145138f3cf253adf38491d490434d5062f713"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/syntax-tree/hast-util-to-text","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-to-text","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-to-text/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-to-text/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-to-text/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-text/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-to-text/sbom","scorecard":{"id":863465,"data":{"date":"2025-08-11","repo":{"name":"github.com/syntax-tree/hast-util-to-text","commit":"d83363ab0ceafadabbd50d5373a881c3f8f3e1c9"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.1,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":0,"reason":"Found 2/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/bb.yml:1","Warn: no topLevel permission defined: .github/workflows/main.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: third-party GitHubAction not pinned by hash: .github/workflows/bb.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/syntax-tree/hast-util-to-text/bb.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/syntax-tree/hast-util-to-text/main.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/syntax-tree/hast-util-to-text/main.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/syntax-tree/hast-util-to-text/main.yml/main?enable=pin","Warn: npmCommand not pinned by hash: .github/workflows/main.yml:15","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 third-party GitHubAction dependencies pinned","Info:   0 out of   1 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: license:0","Info: FSF or OSI recognized license: MIT License: license:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: github.com/syntax-tree/.github/security.md:1","Info: Found linked content: github.com/syntax-tree/.github/security.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/syntax-tree/.github/security.md:1","Info: Found text in security policy: github.com/syntax-tree/.github/security.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 2 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-24T02:00:41.962Z","repository_id":49260442,"created_at":"2025-08-24T02:00:41.962Z","updated_at":"2025-08-24T02:00:41.962Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28408790,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T01:52:23.358Z","status":"online","status_checked_at":"2026-01-14T02:00:06.678Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["hast","hast-util","html","inner-text","syntax-tree","unist","util"],"created_at":"2024-07-31T05:01:13.480Z","updated_at":"2026-01-14T02:53:37.784Z","avatar_url":"https://github.com/syntax-tree.png","language":"JavaScript","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified"],"categories":["JavaScript","hast utilities"],"sub_categories":[],"readme":"# hast-util-to-text\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 get the plain-text value of a node.\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  * [`toText(tree[, options])`](#totexttree-options)\n  * [`Options`](#options)\n  * [`Whitespace`](#whitespace)\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 a [hast][] node and gets its plain-text\nvalue.\nIt is like the DOMs `Node#innerText`, which is a bit nicer than\n`Node#textContent`, because this turns `\u003cbr\u003e` elements into line breaks and\nuses `'\\t'` (tabs) between table cells.\n\nThere are some small deviations from the spec, because the DOM has knowledge of\nassociated CSS, and can take into account that elements have `display: none` or\n`text-transform` association with them, and this utility can’t do that.\n\n## When should I use this?\n\nThis is a small utility that is useful when you want a plain-text version of a\nnode that is close to how it’s “visible” to users.\n\nThis utility is similar to [`hast-util-to-string`][hast-util-to-string], which\nis simpler, and more like the `Node#textContent` algorithm discussed above.\n\nThere is also a package [`hast-util-from-text`][hast-util-from-text], which sort\nof does the inverse: it takes a string, sets that as text on the node, while\nturning line endings into `\u003cbr\u003e`s\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-to-text\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {toText} from 'https://esm.sh/hast-util-to-text@4'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {toText} from 'https://esm.sh/hast-util-to-text@4?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\n```js\nimport {h} from 'hastscript'\nimport {toText} from 'hast-util-to-text'\n\nconst tree = h('div', [\n  h('h1', {hidden: true}, 'Alpha.'),\n  h('article', [\n    h('p', ['Bravo', h('br'), 'charlie.']),\n    h('p', 'Delta echo \\t foxtrot.')\n  ])\n])\n\nconsole.log(toText(tree))\n```\n\nYields:\n\n```txt\nBravo\ncharlie.\n\nDelta echo foxtrot.\n```\n\n## API\n\nThis package exports the identifier [`toText`][api-to-text].\nThere is no default export.\n\n### `toText(tree[, options])`\n\nGet the plain-text value of a node.\n\n###### Parameters\n\n* `tree` ([`Node`][node])\n  — tree to turn into text\n* `options` ([`Options`][api-options], optional)\n  — configuration\n\n###### Returns\n\nSerialized `tree` (`string`).\n\n###### Algorithm\n\n* if `tree` is a [comment][], returns its `value`\n* if `tree` is a [text][], applies normal whitespace collapsing to its\n  `value`, as defined by the [CSS Text][css] spec\n* if `tree` is a [root][] or [element][], applies an algorithm similar to the\n  `innerText` getter as defined by [HTML][]\n\n###### Notes\n\n\u003e 👉 **Note**: the algorithm acts as if `tree` is being rendered, and as if\n\u003e we’re a CSS-supporting user agent, with scripting enabled.\n\n* if `tree` is an element that is not displayed (such as a `head`), we’ll\n  still use the `innerText` algorithm instead of switching to `textContent`\n* if descendants of `tree` are elements that are not displayed, they are\n  ignored\n* CSS is not considered, except for the default user agent style sheet\n* a line feed is collapsed instead of ignored in cases where Fullwidth, Wide,\n  or Halfwidth East Asian Width characters are used, the same goes for a case\n  with Chinese, Japanese, or Yi writing systems\n* replaced elements (such as `audio`) are treated like non-replaced elements\n\n### `Options`\n\nConfiguration (TypeScript type).\n\n##### Fields\n\n* `whitespace` ([`Whitespace`][api-whitespace], default: `'normal'`)\n  — default whitespace setting to use\n\n### `Whitespace`\n\nValid and useful whitespace values (from [CSS][]) (TypeScript type).\n\n##### Type\n\n```ts\ntype Whitespace = 'normal' | 'nowrap' | 'pre' | 'pre-wrap'\n```\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types [`Options`][api-options] and\n[`Whitespace`][api-whitespace].\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-to-text@^4`,\ncompatible with Node.js 16.\n\n## Security\n\n`hast-util-to-text` does not change the syntax tree so there are no\nopenings for [cross-site scripting (XSS)][xss] attacks.\n\n## Related\n\n* [`hast-util-to-string`\n  ](https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-to-string)\n  — get the plain-text value (`textContent`)\n* [`hast-util-from-text`](https://github.com/syntax-tree/hast-util-from-text)\n  — set the plain-text value (`innerText`)\n* [`hast-util-from-string`\n  ](https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-from-string)\n  — set the plain-text value (`textContent`)\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\u003c!-- Definitions --\u003e\n\n[build-badge]: https://github.com/syntax-tree/hast-util-to-text/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/hast-util-to-text/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-to-text.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/hast-util-to-text\n\n[downloads-badge]: https://img.shields.io/npm/dm/hast-util-to-text.svg\n\n[downloads]: https://www.npmjs.com/package/hast-util-to-text\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-to-text\n\n[size]: https://bundlejs.com/?q=hast-util-to-text\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[html]: https://html.spec.whatwg.org/multipage/dom.html#the-innertext-idl-attribute\n\n[css]: https://drafts.csswg.org/css-text/#white-space-phase-1\n\n[hast-util-to-string]: https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-to-string\n\n[hast-util-from-text]: https://github.com/syntax-tree/hast-util-from-text\n\n[hast]: https://github.com/syntax-tree/hast\n\n[node]: https://github.com/syntax-tree/hast#nodes\n\n[root]: https://github.com/syntax-tree/hast#root\n\n[comment]: https://github.com/syntax-tree/hast#comment\n\n[text]: https://github.com/syntax-tree/hast#text\n\n[element]: https://github.com/syntax-tree/hast#element\n\n[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting\n\n[api-to-text]: #totexttree-options\n\n[api-options]: #options\n\n[api-whitespace]: #whitespace\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fhast-util-to-text","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyntax-tree%2Fhast-util-to-text","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fhast-util-to-text/lists"}