//#region src/lib/tree.d.ts type Compare = (current: T, next: T) => boolean; //#endregion //#region src/lib/toc-item.d.ts type TocItem = { level: number; text: string; id: string; href: string; source: TSource; children: TocItem[]; }; //#endregion //#region src/lib/dom-list.d.ts type DomListOptions = { type?: "ol" | "ul"; render?: (items: TocItem[], context: DomListRenderContext) => Element; }; type DomListRenderContext = { document: Document; createLink: (item: TocItem) => HTMLAnchorElement; renderList: (items: TocItem[]) => HTMLOListElement | HTMLUListElement; }; /** * Given TOC items extracted from DOM headings, creates a new list of anchors * that point to those headings. * * @param items Array of nested TOC items. * @param options Options object. * @param options.type Type of DOM element to use. * @param options.render Custom renderer for the full TOC output. * @returns A new list element. * @example * * const items = [ * { * level: 1, * text: 'First', * id: '1', * href: '#1', * source: document.createElement('h1'), * children: [ * { * level: 2, * text: 'Second', * id: '2', * href: '#2', * source: document.createElement('h2'), * children: [], * }, * ], * }, * { * level: 1, * text: 'Third', * id: '3', * href: '#3', * source: document.createElement('h1'), * children: [], * }, * ] * * domList(items) * // =>
    * //
  1. First * //
      * //
    1. Second
    2. * //
    * //
  2. * //
  3. Third
  4. * //
*/ declare function domList(items: TocItem[], options?: DomListOptions): Element; //#endregion //#region src/lib/dom-toc.d.ts type DomRoot = string | Element; type DomTarget = string | Element; type DomHeadingsInput = string | Iterable; type DomItemsOptions = { compare?: Compare; root?: DomRoot; headings?: DomHeadingsInput; text?: (element: Element) => string; id?: (text: string, element: Element) => string; }; type DomTocOptions = DomItemsOptions & DomListOptions & { target?: DomTarget; }; /** * Extract TOC items from headings in the DOM. * * @param options Options object. * @param options.compare Function used to compare hierarchy of heading * elements. * @param options.root Root element or selector used to query headings. * @param options.headings Heading selector or iterable of heading elements. * @param options.text Function used to generate the visible heading text. * @param options.id Function used to generate the heading id. * @returns TOC items generated from the headings. */ declare function domItems(options?: DomItemsOptions): TocItem[]; /** * Handy function to automagically generate a table of contents based on the * document and optional heading inputs, and attach it somewhere in the DOM. * * @param options Options object. * @param options.root Root element or selector used to query headings. * @param options.headings Heading selector or iterable of heading elements. * @param options.target Target element or selector where the TOC will be * attached. * @param options.render Custom renderer forwarded to `domList`. * @returns The generated list element attached to the target. * @example * * domToc() * // =>
    * //
  1. First * //
      * //
    1. Second
    2. * //
    * //
  2. * //
  3. Third
  4. * //
*/ declare function domToc(options?: DomTocOptions): Element; //#endregion //#region src/lib/md-list.d.ts type MdListOptions = { type?: "ol" | "ul"; }; /** * Given TOC items extracted from markdown headings, creates a markdown list of * references that point to those headings. * * @param items Array of nested TOC items. * @param options Options object. * @param options.type Type of list to use, ordered or unordered. * @param depth Initial indentation depth. * @returns A new markdown list. * @example * * const items = [ * { * level: 1, * text: 'First', * id: 'first', * href: '#first', * source: '# First', * children: [ * { * level: 2, * text: 'Second', * id: 'second', * href: '#second', * source: '## Second', * children: [ * { * level: 3, * text: 'Third', * id: 'third', * href: '#third', * source: '### Third', * children: [], * }, * ], * }, * ], * }, * ] * * mdList(items) * // => "1. [First](#first)\n 1. [Second](#second)\n 1. [Third](#third)" * * mdList(items, { type: 'ul' }) * // => "* [First](#first)\n * [Second](#second)\n * [Third](#third)" */ declare function mdList(items: TocItem[], options?: MdListOptions, depth?: number): string; //#endregion //#region src/lib/md-toc.d.ts type MdItemsOptions = { compare?: Compare; headings?: RegExp | ((text: string) => string[]); text?: (heading: string) => string; id?: (text: string, heading: string) => string; }; type MdTocOptions = MdListOptions & MdItemsOptions & { target?: RegExp; }; /** * Extract TOC items from markdown headings. * * @param input Markdown text. * @param options Options object. * @param options.compare Function used to compare hierarchy of headings. * @param options.headings Regex or function used to extract headings from * `text`. * @param options.text Function used to generate the visible heading text. * @param options.id Function used to generate the heading id. * @returns TOC items generated from the headings. */ declare function mdItems(input: string, options?: MdItemsOptions): TocItem[]; /** * Handy function to automagically generate a table of contents for a markdown * document. * * @param text Markdown text. * @param options Options object. * @param options.compare Function used to compare hierarchy of headings. * @param options.headings Regex or function used to extract headings from * `text`. * @param options.target Regex to search for text to be replaced with the table * of contents. * @returns The input text with a markdown list inserted at `target`. * @example * * const mdText = ` * * TOC * * # First * * Bla bla Bla. * * ## Second * * Bla. * * # Third * * End. * ` * * mdToc(mdText) * // => "\n\n1. [First](#first)\n 1. [Second](#second)\n2. [Third](#third)\n\n# First\n\nBla bla Bla.\n\n## Second\n\nBla.\n\n# Third\n\nEnd.\n" */ declare function mdToc(text: string, options?: MdTocOptions): string; //#endregion export { type DomHeadingsInput, type DomItemsOptions, type DomListOptions, type DomListRenderContext, type DomRoot, type DomTarget, type DomTocOptions, type MdItemsOptions, type MdListOptions, type MdTocOptions, type TocItem, domItems, domList, domToc, mdItems, mdList, mdToc }; //# sourceMappingURL=index.d.ts.map