UNPKG

hast-util-excerpt

Version:
40 lines (39 loc) 1.32 kB
/** * Truncate `tree` to a certain comment. * * @template {Nodes} Tree * Tree kind. * @param {Tree} tree * Tree to truncate. * @param {Readonly<Options> | null | undefined} [options] * Configuration (optional). * @returns {Tree | undefined} * Truncated clone of `tree` when a comment is found, `undefined` otherwise. */ export function excerpt<Tree extends import("hast").Nodes>(tree: Tree, options?: Readonly<Options> | null | undefined): Tree | undefined; export type Nodes = import('hast').Nodes; export type RootContent = import('hast').RootContent; /** * Configuration. */ export type Options = { /** * Comment value to search for (default: `'more'`). */ comment?: string | null | undefined; /** * Nodes to exclude from the resulting tree (default: `[]`). * * These are not counted towards `size`. */ ignore?: Array<RootContent> | null | undefined; /** * How far to search for the comment before bailing (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. */ maxSearchSize?: number | null | undefined; };