/** * @since 0.0.1 */ import type { Option } from 'fp-ts/Option' import type { TagSpec } from './Internal/Tag/TagSpec' import type { ReaderOption } from './Internal/ReaderOption' import type { Selector } from './Select' import * as T from './Internal/Html/Tokenizer' export * from './Internal/ReaderOption' /** * @category model * @since 0.0.1 */ export declare type Scraper = ReaderOption /** * The `chroots` combinator takes a `Selector` and an inner `Scraper` and executes * the inner `scraper` as if it were scraping a document that consists solely of the * tags corresponding to the specified `selector`. * * The inner scraper is executed for each set of tags (possibly nested) matching * the given selector. * * @category combinators * @since 0.0.1 */ export declare const chroots: ( selector: Selector ) => (scraper: Scraper) => Scraper /** * The `chroot` combinator takes a `Selector` and an inner `Scraper` and executes * the inner `scraper` as if it were scraping a document that consists solely of the * tags corresponding to the specified `selector`. * * This function will only match the first set of tags that match the selector. To * match every set of tags, use `chroots`. * * @category combinators * @since 0.0.1 */ export declare const chroot: (selector: Selector) => (scraper: Scraper) => Scraper /** * The `matches` combinator takes a `Selector` and returns `void` if the specified * `selector` matches any node in the DOM. * * @category combinators * @since 0.0.1 */ export declare const matches: (selector: Selector) => Scraper /** * The `text` combinator takes a `Selector` and returns the inner text from * the set of tags matched by the specified `selector`. * * This function will only return the first set of tags matched by the * selector. To match every tag, use `texts`. * * @category combinators * @since 0.0.1 */ export declare const text: (selector: Selector) => Scraper /** * The `text` combinator takes a `Selector` and returns the inner text from * every set of tags (possibly nested) matched by the specified `selector`. * * @category combinators * @since 0.0.1 */ export declare const texts: (selector: Selector) => Scraper /** * The `attr` combinator takes an attribute `key` and a `Selector` and * returns the value of the attribute with the specified `key` for the * first opening tag that matches the specified `selector`. * * This function will only return the first opening tag matched by the * selector. To match every tag, use `attrs`. * * @category combinators * @since 0.0.1 */ export declare const attr: (key: string, selector: Selector) => Scraper /** * The `attrs` combinator takes an attribute `key` and a `Selector` and * returns the value of the attribute with the specified `key` for every * opening tag (possibly nested) that matches the specified `selector`. * * @category combinators * @since 0.0.1 */ export declare const attrs: (key: string, selector: Selector) => Scraper /** * The `html` combinator takes a `Selector` and returns the HTML string * representation of the tags matched by the specified `selector`. * * This function will only return the HTML string for the first tag * matched by the selector. To match every tag, use `htmls`. * * @category combinators * @since 0.0.1 */ export declare const html: (selector: Selector) => Scraper /** * The `htmls` combinator takes a `Selector` and returns the HTML string * representation of every set of tags (possibly nested) matched by the * specified `selector`. * * @category combinators * @since 0.0.1 */ export declare const htmls: (selector: Selector) => Scraper /** * The `innerHTML` combinator takes a `Selector` and returns the inner HTML * string representation of the tags matched by the specified `selector`. * In this case, *inner html* refers to the set of tags within, but not * including, the selected tags. * * This function will only return the HTML string for the first tag matched * by the selector. To match every tag, use `innerHTMLs`. * * @category combinators * @since 0.0.1 */ export declare const innerHTML: (selector: Selector) => Scraper /** * The `innerHTMLs` combinator takes a `Selector` and returns the inner HTML * string representation of every set of tags (possibly nested) matched by * the specified `selector`. In this case, *inner html* refers to the set of * tags within, but not including, the selected tags. * * @category combinators * @since 0.0.1 */ export declare const innerHTMLs: (selector: Selector) => Scraper /** * The `position` combinator is designed to be used to extract the position * of each HTML tag within the currently matched subtree. It is primarily * intended to be used in combination with the `chroots` combinator and the * `do`-notation helpers. * * For example, consider the following HTML: * * ```html *
*

First paragraph.

*

Second paragraph.

*

Third paragraph.

*
* ``` * * The `position` combinator can be used to determine the index of each `

` * tag tag within the `

` tag as follows: * * ```typescript * import { pipe } from 'fp-ts/function' * import * as S from 'scalpel-ts/Scraper' * import * as Select from 'scalpel-ts/Select' * * S.scrape( * pipe( * S.position, * S.bindTo('index'), * S.bind('content', () => S.texts(Select.tag('p'))), * S.chroots(pipe(Select.tag('article'), Select.nested(Select.tag('p')))) * ) * ) * // [ * // { index: 0, content: [ 'First paragraph.' ] }, * // { index: 1, content: [ 'Second paragraph.' ] }, * // { index: 2, content: [ 'Third paragraph.' ] } * // ] * ``` * * @category combinators * @since 0.0.1 */ export declare const position: Scraper /** * The `scrape` function executes a `Scraper` on a stream of `Token`s and produces * an optional value of type `A`. * * @category utils * @since 0.0.1 */ export declare const scrape: (scraper: Scraper) => (tags: ReadonlyArray) => Option