{"_id":"hast-util-excerpt","_rev":"4337469","name":"hast-util-excerpt","description":"hast utility to excerpt the tree to a comment","dist-tags":{"latest":"2.0.0"},"maintainers":[{"name":"kmck","email":"keith@mcknig.ht"},{"name":"wooorm","email":"tituswormer@gmail.com"}],"time":{"modified":"2026-04-08T09:55:28.000Z","created":"2021-09-09T17:43:21.350Z","2.0.0":"2023-08-08T10:31:10.829Z","1.0.2":"2023-01-05T13:37:38.374Z","1.0.1":"2021-09-10T06:28:11.721Z","1.0.0":"2021-09-09T17:43:21.350Z"},"users":{},"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},"repository":{"type":"git","url":"git+https://github.com/syntax-tree/hast-util-excerpt.git"},"versions":{"2.0.0":{"name":"hast-util-excerpt","version":"2.0.0","description":"hast utility to excerpt the tree to a comment","license":"MIT","keywords":["unist","hast","hast-util","util","utility","html","excerpt","excerpt","summary"],"repository":{"type":"git","url":"git+https://github.com/syntax-tree/hast-util-excerpt.git"},"bugs":{"url":"https://github.com/syntax-tree/hast-util-excerpt/issues"},"funding":{"type":"opencollective","url":"https://opencollective.com/unified"},"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"}],"sideEffects":false,"type":"module","exports":"./index.js","dependencies":{"@types/hast":"^3.0.0","hast-util-truncate":"^2.0.0"},"devDependencies":{"@types/node":"^20.0.0","c8":"^8.0.0","hast-util-select":"^6.0.0","hastscript":"^8.0.0","mdast-util-from-markdown":"^2.0.0","mdast-util-mdx":"^3.0.0","mdast-util-to-hast":"^13.0.0","micromark-extension-mdxjs":"^2.0.0","prettier":"^3.0.0","remark-cli":"^11.0.0","remark-preset-wooorm":"^9.0.0","type-coverage":"^2.0.0","typescript":"^5.0.0","unist-builder":"^4.0.0","unist-util-remove-position":"^5.0.0","xo":"^0.55.0"},"scripts":{"prepack":"npm run build && npm run format","build":"tsc --build --clean && tsc --build && type-coverage","format":"remark . -qfo && prettier . -w --log-level warn && xo --fix","test-api":"node --conditions development test.js","test-coverage":"c8 --100 --reporter lcov npm run test-api","test":"npm run build && npm run format && npm run test-coverage"},"prettier":{"bracketSpacing":false,"semi":false,"singleQuote":true,"tabWidth":2,"trailingComma":"none","useTabs":false},"remarkConfig":{"plugins":["remark-preset-wooorm"]},"typeCoverage":{"atLeast":100,"detail":true,"ignoreCatch":true,"strict":true},"xo":{"prettier":true},"gitHead":"4578e0aaa552776da31eb25c622daf72c3844611","types":"./index.d.ts","homepage":"https://github.com/syntax-tree/hast-util-excerpt#readme","_id":"hast-util-excerpt@2.0.0","_nodeVersion":"20.0.0","_npmVersion":"9.7.2","dist":{"shasum":"0702350f1886a1ea3601f52ae976ea68f3b8a045","size":5365,"noattachment":false,"key":"/hast-util-excerpt/-/hast-util-excerpt-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/hast-util-excerpt/download/hast-util-excerpt-2.0.0.tgz"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"maintainers":[{"name":"kmck","email":"keith@mcknig.ht"},{"name":"wooorm","email":"tituswormer@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hast-util-excerpt_2.0.0_1691490670628_0.24562008006268066"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-08-08T10:31:10.829Z","publish_time":1691490670829,"_source_registry_name":"default","_cnpm_publish_time":1691490670829},"1.0.2":{"name":"hast-util-excerpt","version":"1.0.2","description":"hast utility to excerpt the tree to a comment","license":"MIT","keywords":["unist","hast","hast-util","util","utility","html","excerpt","excerpt","summary"],"repository":{"type":"git","url":"git+https://github.com/syntax-tree/hast-util-excerpt.git"},"bugs":{"url":"https://github.com/syntax-tree/hast-util-excerpt/issues"},"funding":{"type":"opencollective","url":"https://opencollective.com/unified"},"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"}],"sideEffects":false,"type":"module","main":"index.js","types":"index.d.ts","dependencies":{"@types/hast":"^2.0.0","hast-util-truncate":"^1.0.0"},"devDependencies":{"@types/node":"^18.0.0","c8":"^7.0.0","hast-util-select":"^5.0.0","hastscript":"^7.0.0","mdast-util-from-markdown":"^1.0.0","mdast-util-mdx":"^2.0.0","mdast-util-to-hast":"^12.0.0","micromark-extension-mdxjs":"^1.0.0","prettier":"^2.0.0","remark-cli":"^11.0.0","remark-preset-wooorm":"^9.0.0","type-coverage":"^2.0.0","typescript":"^4.0.0","unist-builder":"^3.0.0","unist-util-remove-position":"^4.0.0","xo":"^0.53.0"},"scripts":{"prepack":"npm run build && npm run format","build":"tsc --build --clean && tsc --build && type-coverage","format":"remark . -qfo && prettier . -w --loglevel warn && xo --fix","test-api":"node --conditions development test.js","test-coverage":"c8 --check-coverage --100 --reporter lcov npm run test-api","test":"npm run build && npm run format && npm run test-coverage"},"prettier":{"tabWidth":2,"useTabs":false,"singleQuote":true,"bracketSpacing":false,"semi":false,"trailingComma":"none"},"xo":{"prettier":true},"remarkConfig":{"plugins":["preset-wooorm"]},"typeCoverage":{"atLeast":100,"detail":true,"strict":true,"ignoreCatch":true},"gitHead":"15e137c53792e1ca92a27b8605ce61f31c3801e2","homepage":"https://github.com/syntax-tree/hast-util-excerpt#readme","_id":"hast-util-excerpt@1.0.2","_nodeVersion":"19.3.0","_npmVersion":"9.2.0","dist":{"shasum":"8e321ede9b6f6e0f69fd9851efc3ef5cfb5dd8e6","size":5268,"noattachment":false,"key":"/hast-util-excerpt/-/hast-util-excerpt-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/hast-util-excerpt/download/hast-util-excerpt-1.0.2.tgz"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"maintainers":[{"name":"kmck","email":"keith@mcknig.ht"},{"name":"wooorm","email":"tituswormer@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hast-util-excerpt_1.0.2_1672925858187_0.417719055543071"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-01-05T14:37:17.199Z","publish_time":1672925858374,"_cnpm_publish_time":1672925858374},"1.0.1":{"name":"hast-util-excerpt","version":"1.0.1","description":"hast utility to excerpt the tree to a comment","license":"MIT","keywords":["unist","hast","hast-util","util","utility","html","excerpt","excerpt","summary"],"repository":{"type":"git","url":"git+https://github.com/syntax-tree/hast-util-excerpt.git"},"bugs":{"url":"https://github.com/syntax-tree/hast-util-excerpt/issues"},"funding":{"type":"opencollective","url":"https://opencollective.com/unified"},"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"}],"sideEffects":false,"type":"module","main":"index.js","types":"index.d.ts","dependencies":{"@types/hast":"^2.0.0","hast-util-truncate":"^1.0.0"},"devDependencies":{"@types/acorn":"^4.0.6","@types/tape":"^4.0.0","c8":"^7.0.0","hast-util-select":"^5.0.0","hastscript":"^7.0.0","mdast-util-from-markdown":"^1.0.0","mdast-util-mdx":"^1.0.0","mdast-util-to-hast":"^11.0.0","micromark-extension-mdxjs":"^1.0.0","prettier":"^2.0.0","remark-cli":"^10.0.0","remark-preset-wooorm":"^9.0.0","rimraf":"^3.0.0","tape":"^5.0.0","type-coverage":"^2.0.0","typescript":"^4.0.0","unist-builder":"^3.0.0","unist-util-remove-position":"^4.0.0","xo":"^0.44.0"},"scripts":{"prepack":"npm run build && npm run format","build":"rimraf \"*.d.ts\" && tsc && type-coverage","format":"remark . -qfo && prettier . -w --loglevel warn && xo --fix","test-api":"node test.js","test-coverage":"c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js","test":"npm run build && npm run format && npm run test-coverage"},"prettier":{"tabWidth":2,"useTabs":false,"singleQuote":true,"bracketSpacing":false,"semi":false,"trailingComma":"none"},"xo":{"prettier":true},"remarkConfig":{"plugins":["preset-wooorm"]},"typeCoverage":{"atLeast":100,"detail":true,"strict":true,"ignoreCatch":true},"gitHead":"80087a0e63829f26527f4dbe246320199b9d4ed7","homepage":"https://github.com/syntax-tree/hast-util-excerpt#readme","_id":"hast-util-excerpt@1.0.1","_nodeVersion":"16.9.0","_npmVersion":"7.21.1","dist":{"shasum":"6d32dbcde8d945c6ddb0a4b204f9a78018fcc175","size":4307,"noattachment":false,"key":"/hast-util-excerpt/-/hast-util-excerpt-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/hast-util-excerpt/download/hast-util-excerpt-1.0.1.tgz"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"maintainers":[{"name":"kmck","email":"keith@mcknig.ht"},{"name":"wooorm","email":"tituswormer@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hast-util-excerpt_1.0.1_1631255291581_0.7248350847544709"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2021-12-20T14:33:39.380Z","publish_time":1631255291721,"_cnpm_publish_time":1631255291721},"1.0.0":{"name":"hast-util-excerpt","version":"1.0.0","description":"hast utility to excerpt the tree to a comment","license":"MIT","keywords":["unist","hast","hast-util","util","utility","html","excerpt","excerpt","summary"],"repository":{"type":"git","url":"git+https://github.com/syntax-tree/hast-util-excerpt.git"},"bugs":{"url":"https://github.com/syntax-tree/hast-util-excerpt/issues"},"funding":{"type":"opencollective","url":"https://opencollective.com/unified"},"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"}],"sideEffects":false,"type":"module","main":"index.js","types":"index.d.ts","dependencies":{"@types/hast":"^2.0.0","hast-util-truncate":"^1.0.0"},"devDependencies":{"@types/acorn":"^4.0.6","@types/tape":"^4.0.0","c8":"^7.0.0","hast-util-select":"^5.0.0","hastscript":"^7.0.0","mdast-util-from-markdown":"^1.0.0","mdast-util-mdx":"^1.0.0","mdast-util-to-hast":"^11.0.0","micromark-extension-mdxjs":"^1.0.0","prettier":"^2.0.0","remark-cli":"^10.0.0","remark-preset-wooorm":"^9.0.0","rimraf":"^3.0.0","tape":"^5.0.0","type-coverage":"^2.0.0","typescript":"^4.0.0","unist-builder":"^3.0.0","unist-util-remove-position":"^4.0.0","xo":"^0.44.0"},"scripts":{"prepack":"npm run build && npm run format","build":"rimraf \"*.d.ts\" && tsc && type-coverage","format":"remark . -qfo && prettier . -w --loglevel warn && xo --fix","test-api":"node test.js","test-coverage":"c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js","test":"npm run build && npm run format && npm run test-coverage"},"prettier":{"tabWidth":2,"useTabs":false,"singleQuote":true,"bracketSpacing":false,"semi":false,"trailingComma":"none"},"xo":{"prettier":true},"remarkConfig":{"plugins":["preset-wooorm"]},"typeCoverage":{"atLeast":100,"detail":true,"strict":true,"ignoreCatch":true},"gitHead":"81c48ec154b282ffdd458ee701f8f62db88c5685","homepage":"https://github.com/syntax-tree/hast-util-excerpt#readme","_id":"hast-util-excerpt@1.0.0","_nodeVersion":"16.9.0","_npmVersion":"7.21.1","dist":{"shasum":"b76e9b0d4fc17944281a5ad2fcb2533d4231c6d3","size":4319,"noattachment":false,"key":"/hast-util-excerpt/-/hast-util-excerpt-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/hast-util-excerpt/download/hast-util-excerpt-1.0.0.tgz"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"maintainers":[{"name":"kmck","email":"keith@mcknig.ht"},{"name":"wooorm","email":"tituswormer@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hast-util-excerpt_1.0.0_1631209401171_0.5950419337170276"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2021-12-20T14:33:38.502Z","publish_time":1631209401350,"_cnpm_publish_time":1631209401350}},"readme":"# hast-util-excerpt\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 truncate the tree to a comment.\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    *   [`excerpt(tree[, options])`](#excerpttree-options)\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 takes a [hast][] (HTML) syntax tree and truncates\nit to a comment, while otherwise preserving the tree structure.\n\n## When should I use this?\n\nThis is a small utility useful when you need to create a shorter version of a\npotentially long document, and want authors to be able to mark where that\nversion ends.\n\nThis utility is similar to [`hast-util-truncate`][hast-util-truncate], which\ntruncates a tree to a certain number of characters.\n\nThe rehype plugin\n[`rehype-infer-description-meta`][rehype-infer-description-meta]\nwraps both this utility and `hast-util-truncate` to figure out a description of\na document, for use with [`rehype-meta`][rehype-meta].\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-excerpt\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {excerpt} from 'https://esm.sh/hast-util-excerpt@2'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n<script type=\"module\">\n  import {excerpt} from 'https://esm.sh/hast-util-excerpt@2?bundle'\n</script>\n```\n\n## Use\n\nSay our module `example.js` looks as follows:\n\n```js\nimport {u} from 'unist-builder'\nimport {h} from 'hastscript'\nimport {excerpt} from 'hast-util-excerpt'\n\nconst tree = h('p', [\n  'Lorem ipsum dolor sit amet, ',\n  h('em', 'consectetur'),\n  'adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',\n  u('comment', 'more'),\n  'Ut enim ad minim veniam, quis nostrud'\n])\n\nconsole.log(excerpt(tree));\n```\n\n…now running `node example.js` yields:\n\n```js\n{\n  type: 'element',\n  tagName: 'p',\n  properties: {},\n  children: [\n    {type: 'text', value: 'Lorem ipsum dolor sit amet, '},\n    {\n      type: 'element',\n      tagName: 'em',\n      properties: {},\n      children: [Array]\n    },\n    {\n      type: 'text',\n      value:\n        'adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'\n    }\n  ]\n}\n```\n\n## API\n\nThis package exports the identifier [`excerpt`][api-excerpt].\nThere is no default export.\n\n### `excerpt(tree[, options])`\n\nTruncate `tree` to a certain comment.\n\n###### Parameters\n\n*   `tree` ([`Node`][node])\n    — tree to truncate\n*   `options` ([`Options`][api-options])\n    — configuration (optional)\n\n###### Returns\n\nTruncated clone of `tree` ([`Node`][node]) when a comment is found, `undefined`\notherwise.\n\n### `Options`\n\nConfiguration (TypeScript type).\n\n##### Fields\n\n###### `comment`\n\nComment value to search for (`string`, default: `'more'`).\n\n###### `maxSearchSize`\n\nHow far to search for the comment before bailing (`number`, default: `2048`).\nThe goal of this project is to find user-defined explicit excerpts, that are\nassumed to be somewhat reasonably placed.\nThis option prevents searching giant documents for some comment that probably\nwon’t be found at the end.\n\n###### `ignore`\n\nNodes to exclude from the resulting tree ([`Array<Node>`][node]).\nThese are not counted towards `size`.\n\n## Syntax tree\n\nThe syntax tree is [hast][].\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, `hast-util-excerpt@^2`,\ncompatible with Node.js 16.\n\n## Security\n\nUse of `hast-util-excerpt` should be safe if the tree is already safe and\nyou’re not using user content in options.\nWhen in doubt, use [`hast-util-sanitize`][hast-util-sanitize].\n\n## Related\n\n*   [`hast-util-truncate`](https://github.com/syntax-tree/hast-util-truncate)\n    — truncate the tree to a number of characters\n*   [`rehype-infer-description-meta`][rehype-infer-description-meta]\n    — infer file metadata from the contents of the document\n*   [`rehype-meta`][rehype-meta]\n    — add metadata to the head of a document\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-excerpt/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/hast-util-excerpt/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-excerpt.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/hast-util-excerpt\n\n[downloads-badge]: https://img.shields.io/npm/dm/hast-util-excerpt.svg\n\n[downloads]: https://www.npmjs.com/package/hast-util-excerpt\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-excerpt\n\n[size]: https://bundlejs.com/?q=hast-util-excerpt\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[hast]: https://github.com/syntax-tree/hast\n\n[hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize\n\n[hast-util-truncate]: https://github.com/syntax-tree/hast-util-truncate\n\n[rehype-infer-description-meta]: https://github.com/rehypejs/rehype-infer-description-meta\n\n[rehype-meta]: https://github.com/rehypejs/rehype-meta\n\n[node]: https://github.com/syntax-tree/hast#nodes\n\n[api-excerpt]: #excerpttree-options\n\n[api-options]: #options\n","_attachments":{},"homepage":"https://github.com/syntax-tree/hast-util-excerpt#readme","bugs":{"url":"https://github.com/syntax-tree/hast-util-excerpt/issues"},"license":"MIT"}