@resee-movies/utilities - v1.0.2
    Preparing search index...

    Function generateTableOfContents

    • Generates a Table of Contents from a variety of source material.

      • An HTML element.
      • A string containing HTML content.
      • An object array such as those generated by Codex or CodeMirror.

      An object will be returned that contains the following properties:

      • tableOfContents: A hierarchical representation of the source contents headers that can be used to generate a ToC.

      • contentSource: The object that headings were derived from, possibly modified to include id attributes on headings so that there is a valid target to anchor to. A string or HTMLElement will be modified in this manner, but not a TableOfContentsObjectSource array (see contentMap).

      • contentMap: If the provided source is a TableOfContentsObjectSource array, then this property will contain a WeakMap instance whose keys are objects of that source array, and whose values are TableOfContents objects. This is done to avoid mutating the source objects themselves, as they might be immutable. Then rendering the source into HTML, contentMap can be used to associate the element with a TableOfContents entry, whose slug property should be used as the ID of the new element.

      Type Parameters

      Parameters

      Returns GenerateTableOfContentsReturn<S>