Trilium Backend API
    Preparing search index...

    Interface CheerioAPI

    A querying function, bound to a document created from the provided markup.

    Also provides several helper methods for dealing with the document as a whole.

    interface CheerioAPI {
        fn: Cheerio<any>;
        load: (
            content: string | Buffer<ArrayBufferLike> | AnyNode | AnyNode[],
            options?: CheerioOptions,
            isDocument?: boolean,
        ) => CheerioAPI;
        contains(container: AnyNode, contained: AnyNode): boolean;
        extract<M extends ExtractMap>(this: CheerioAPI, map: M): ExtractedMap<M>;
        html(this: CheerioAPI, options?: CheerioOptions): string;
        html(
            this: CheerioAPI,
            dom?: BasicAcceptedElems<AnyNode>,
            options?: CheerioOptions,
        ): string;
        merge<T>(arr1: Writable<ArrayLike<T>>, arr2: ArrayLike<T>): ArrayLike<T>;
        parseHTML(
            this: CheerioAPI,
            data: string,
            context?: unknown,
            keepScripts?: boolean,
        ): AnyNode[];
        parseHTML(this: CheerioAPI, data?: ""): null;
        root(this: CheerioAPI): Cheerio<Document>;
        text(this: void | CheerioAPI, elements?: ArrayLike<AnyNode>): string;
        xml(this: CheerioAPI, dom?: BasicAcceptedElems<AnyNode>): string;
        <T extends AnyNode, S extends string>(
            selector?: S | BasicAcceptedElems<T>,
            context?: BasicAcceptedElems<AnyNode>,
            root?: BasicAcceptedElems<Document>,
            options?: CheerioOptions,
        ): Cheerio<S extends SelectorType ? Element : T>;
    }

    Hierarchy (View Summary)

    • This selector method is the starting point for traversing and manipulating the document. Like jQuery, it's the primary method for selecting elements in the document.

      selector searches within the context scope, which searches within the root scope.

      Type Parameters

      Parameters

      Returns Cheerio<S extends SelectorType ? Element : T>

      $('ul .pear').attr('class');
      //=> pear

      $('li[class=orange]').html();
      //=> Orange

      $('.apple', '#fruits').text();
      //=> Apple

      Optionally, you can also load HTML by passing the string as the selector:

      $('<ul id="fruits">...</ul>');
      

      Or the context:

      $('ul', '<ul id="fruits">...</ul>');
      

      Or as the root:

      $('li', 'ul', '<ul id="fruits">...</ul>');
      
    Index

    Deprecated

    load: (
        content: string | Buffer<ArrayBufferLike> | AnyNode | AnyNode[],
        options?: CheerioOptions,
        isDocument?: boolean,
    ) => CheerioAPI

    The .load static method defined on the "loaded" Cheerio factory function is deprecated. Users are encouraged to instead use the load function exported by the Cheerio module.

    Use the load function exported by the Cheerio module.

    const $ = cheerio.load('<h1>Hello, <span>world</span>.</h1>');
    

    Other

    fn: Cheerio<any>

    Mimic jQuery's prototype alias for plugin authors.

    Static

    • Checks to see if the contained DOM element is a descendant of the container DOM element.

      Parameters

      • container: AnyNode

        Potential parent node.

      • contained: AnyNode

        Potential child node.

      Returns boolean

      Indicates if the nodes contain one another.

      Cheerio.contains

    • Extract multiple values from a document, and store them in an object.

      Type Parameters

      Parameters

      • this: CheerioAPI
      • map: M

        An object containing key-value pairs. The keys are the names of the properties to be created on the object, and the values are the selectors to be used to extract the values.

      Returns ExtractedMap<M>

      An object containing the extracted values.

    • Parses a string into an array of DOM nodes. The context argument has no meaning for Cheerio, but it is maintained for API compatibility with jQuery.

      Parameters

      • this: CheerioAPI
      • data: string

        Markup that will be parsed.

      • Optionalcontext: unknown

        Will be ignored. If it is a boolean it will be used as the value of keepScripts.

      • OptionalkeepScripts: boolean

        If false all scripts will be removed.

      Returns AnyNode[]

      The parsed DOM.

      Cheerio.parseHTML

    • Parses a string into an array of DOM nodes. The context argument has no meaning for Cheerio, but it is maintained for API compatibility with jQuery.

      Parameters

      • this: CheerioAPI
      • Optionaldata: ""

        Markup that will be parsed.

      Returns null

      The parsed DOM.

      Cheerio.parseHTML

    • Sometimes you need to work with the top-level root element. To query it, you can use $.root().

      Parameters

      Returns Cheerio<Document>

      Cheerio instance wrapping the root node.

      $.root().append('<ul id="vegetables"></ul>').html();
      //=> <ul id="fruits">...</ul><ul id="vegetables"></ul>

      Cheerio.root

    • Render the document as text.

      This returns the textContent of the passed elements. The result will include the contents of <script> and <style> elements. To avoid this, use .prop('innerText') instead.

      Parameters

      Returns string

      The rendered document.