Gathering detailed insights and metrics for hast-util-excerpt
Gathering detailed insights and metrics for hast-util-excerpt
Gathering detailed insights and metrics for hast-util-excerpt
Gathering detailed insights and metrics for hast-util-excerpt
npm install hast-util-excerpt
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
2 Stars
33 Commits
8 Watching
1 Branches
10 Contributors
Updated on 15 Mar 2023
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-5.1%
2,070
Compared to previous day
Last week
-7.4%
11,395
Compared to previous week
Last month
1%
53,529
Compared to previous month
Last year
18.8%
665,393
Compared to previous year
hast utility to truncate the tree to a comment.
This package is a utility that takes a hast (HTML) syntax tree and truncates it to a comment, while otherwise preserving the tree structure.
This is a small utility useful when you need to create a shorter version of a potentially long document, and want authors to be able to mark where that version ends.
This utility is similar to hast-util-truncate
, which
truncates a tree to a certain number of characters.
The rehype plugin
rehype-infer-description-meta
wraps both this utility and hast-util-truncate
to figure out a description of
a document, for use with rehype-meta
.
This package is ESM only. In Node.js (version 16+), install with npm:
1npm install hast-util-excerpt
In Deno with esm.sh
:
1import {excerpt} from 'https://esm.sh/hast-util-excerpt@2'
In browsers with esm.sh
:
1<script type="module"> 2 import {excerpt} from 'https://esm.sh/hast-util-excerpt@2?bundle' 3</script>
Say our module example.js
looks as follows:
1import {u} from 'unist-builder' 2import {h} from 'hastscript' 3import {excerpt} from 'hast-util-excerpt' 4 5const tree = h('p', [ 6 'Lorem ipsum dolor sit amet, ', 7 h('em', 'consectetur'), 8 'adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', 9 u('comment', 'more'), 10 'Ut enim ad minim veniam, quis nostrud' 11]) 12 13console.log(excerpt(tree));
…now running node example.js
yields:
1{ 2 type: 'element', 3 tagName: 'p', 4 properties: {}, 5 children: [ 6 {type: 'text', value: 'Lorem ipsum dolor sit amet, '}, 7 { 8 type: 'element', 9 tagName: 'em', 10 properties: {}, 11 children: [Array] 12 }, 13 { 14 type: 'text', 15 value: 16 'adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' 17 } 18 ] 19}
This package exports the identifier excerpt
.
There is no default export.
excerpt(tree[, options])
Truncate tree
to a certain comment.
Truncated clone of tree
(Node
) when a comment is found, undefined
otherwise.
Options
Configuration (TypeScript type).
comment
Comment value to search for (string
, default: 'more'
).
maxSearchSize
How far to search for the comment before bailing (number
, default: 2048
).
The goal of this project is to find user-defined explicit excerpts, that are
assumed to be somewhat reasonably placed.
This option prevents searching giant documents for some comment that probably
won’t be found at the end.
ignore
Nodes to exclude from the resulting tree (Array<Node>
).
These are not counted towards size
.
The syntax tree is hast.
This package is fully typed with TypeScript.
It exports the additional type Options
.
Projects maintained by the unified collective are compatible with maintained versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line, hast-util-excerpt@^2
,
compatible with Node.js 16.
Use of hast-util-excerpt
should be safe if the tree is already safe and
you’re not using user content in options.
When in doubt, use hast-util-sanitize
.
hast-util-truncate
— truncate the tree to a number of charactersrehype-infer-description-meta
— infer file metadata from the contents of the documentrehype-meta
— add metadata to the head of a documentSee contributing.md
in syntax-tree/.github
for
ways to get started.
See support.md
for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
No vulnerabilities found.
No security vulnerabilities found.