Provides methods to generate links, code snippets, and documentation for code elements. These wrap around a collection of useful helpers originating from the doc utils. To create an instance, use makeDocContextForTypes (although if you are writing a wiki, you get such an instance).

interface GeneralDocContext {
    code(
        element: ElementIdOrRef,
        fmt?: Omit<FnElementInfo, "info" | "program">,
        filter?: ElementFilter,
    ): string;
    doc(element: ElementIdOrRef, filter?: Omit<ElementFilter, "file">): string;
    header(filename: string, purpose: string): Promise<string>;
    hierarchy(
        element: ElementIdOrRef,
        fmt?: Omit<PrintHierarchyArguments, "info" | "root" | "program">,
        filter?: ElementFilter,
    ): string;
    link(
        element: ElementIdOrRef,
        fmt?: LinkFormat,
        filter?: ElementFilter,
    ): string;
    linkFile(element: ElementIdOrRef): string;
    linkM<T extends NamedPrototype>(
        cls: T,
        element: ProtoKeys<T>,
        fmt?: LinkFormat & { hideClass?: boolean },
        filter?: ElementFilter,
    ): string;
    mermaid(element: ElementIdOrRef, inlineTypes?: string[]): string;
}

Methods

  • Returns the code snippet for a code element as markdown string.

    Parameters

    • element: ElementIdOrRef

      The element to create a code snippet for, the name can be qualified with :: to specify the class.

    • Optionalfmt: Omit<FnElementInfo, "info" | "program">

      Formatting options for the code snippet (see FnElementInfo)

    • Optionalfilter: ElementFilter

      An optional filter to further specify the element to get the code for, in case multiple elements with the same name exist.

    Returns string

    code(exampleFn.name, { dropLinesStart: 1, dropLinesEnd: 2  })
    

    Creates a code snippet for the exampleFn function in the code base, dropping the first and last two lines of the function definition. If, for example, the function looks like this:

    function exampleFn(a: number, b: number): number {
    // This is an example
    const result = a + b;
    return result;
    }

    The resulting code snippet will be (auto-gobbled by default):

    // This is an example
    const result = a + b;

    printCodeOfElement - for the underlying impl.

  • Returns the documentation for a code element as markdown string. If you want to, e.g., prefix all of these lines with indentation or > for blockquotes, use prefixLines.

    Parameters

    • element: ElementIdOrRef

      The element to create documentation for, the name can be qualified with :: to specify the class.

    • Optionalfilter: Omit<ElementFilter, "file">

      An optional filter to further specify the element to get the documentation for, in case multiple elements with the same name exist.

    Returns string

    doc(exampleFn.name)
    

    Creates the documentation for the exampleFn function in the code base as markdown string.

    • getDocumentationForType - for the underlying impl.
    • removeCommentSymbolsFromTypeScriptComment - to clean up TS doc comments.
  • Generates an auto-generation header for the wiki page.

    Parameters

    • filename: string

      The name of the file being generated. Probably use module.filename.

    • purpose: string

      The purpose of the file, e.g., 'wiki context for types'.

    Returns Promise<string>

  • Returns the hierarchy (e.g., class inheritance) for a code element as markdown string, including their documentation and snippets.

    Parameters

    • element: ElementIdOrRef

      The element to create a hierarchy for, the name can be qualified with :: to specify the class.

    • Optionalfmt: Omit<PrintHierarchyArguments, "info" | "root" | "program">

      Formatting options for the hierarchy (see PrintHierarchyArguments)

    • Optionalfilter: ElementFilter

      An optional filter to further specify the element to get the hierarchy for, in case multiple elements with the same name exist.

    Returns string

    hierarchy(MyClass.name, { maxDepth: 2 })
    

    Creates the hierarchy for the MyClass class in the code base, including up to two levels of inheritance.

    printHierarchy - for the underlying impl.

  • Generate a hyperlink to a code element in the wiki. If you want to reference the member of a class, use ClassName::MemberName as element name. For ease of use, you can also call linkM to create a link to a member.

    Parameters

    • element: ElementIdOrRef

      The element to create a link for, the name can be qualified with :: to specify the class. This causes the link to be usually printed as ClassName::ElementName. If you want to avoid showing the class name, use ::: as separator. Please note that for elements with a sensible (.name), you can also pass the function/constructor reference directly (e.g., link(MyClass)).

    • Optionalfmt: LinkFormat

      Formatting options for the link (see LinkFormat)

    • Optionalfilter: ElementFilter

      An optional filter to further specify the element to link to, in case multiple elements with the same name exist.

    Returns string

    link(registerPluginMaker.name)
    

    Creates a (markdown) link to the registerPluginMaker function in the code base and, if available, attaches the TS documentation as tooltip. By using the .name, the link text will be registerPluginMaker but respect, e.g., renaming refactorings done in the code base.

    • linkFile - to create a link using the file path as name.
    • shortLink - for the underlying impl.
    • dropGenericsFromTypeName - to clean up type names for display.
  • Generate a hyperlink to a type/element definition in the code base which is displayed using the file path as name

    Parameters

    • element: ElementIdOrRef

      The element to create a link for, the name can be qualified with :: to specify the class.

    Returns string

    linkFile(registerPluginMaker.name)
    

    Creates a (markdown) link to the registerPluginMaker function in the code base using the file path as link name.

    • GeneralWikiContext#link|link - to create a link with a custom name/using the type name by default.
    • linkFile - for the underlying impl.
  • Generates a mermaid diagram for the given code element, returned as markdown string.

    Parameters

    • element: ElementIdOrRef

      The element to create a mermaid diagram for, the name can be qualified with :: to specify the class.

    • OptionalinlineTypes: string[]

      Optional list of type names to inline in the mermaid diagram (instead of linking them out).

    Returns string