UNPKG

webforai

Version:

A library that provides a web interface for AI

39 lines (38 loc) 1.37 kB
import type { Nodes as Hast } from "hast"; import type { Nodes as Mdast } from "mdast"; import { type ExtractorSelectors } from "./extractors"; export type HtmlToMdastOptions = { /** * An array of extractors to extract specific elements from the HTML. * You can define your own functions in addition to the Extractor provided as a preset. */ extractors?: ExtractorSelectors; /** Whether to convert links to plain text. */ linkAsText?: boolean; /** Whether to convert tables to plain text. */ tableAsText?: boolean; /** Whether to hide images. */ hideImage?: boolean; /** The language of the HTML. */ lang?: string; /** The URL of the HTML. */ url?: string; }; /** * Converts an HTML string or HAST tree to an MDAST tree. * * @param htmlOrHast - The HTML string or HAST tree to convert. * @param options - {@link HtmlToMdastOptions} to customize the conversion. * @returns The MDAST tree. * * @example * ```ts * import { htmlToMdast } from 'webforai'; * * const html = '<h1>Hello, world!</h1>'; * const mdast = htmlToMdast(html); * * console.log(mdast); // Output: { type: 'root', children: [ { type: 'heading', depth: 1, children: [ { type: 'text', value: 'Hello, world!' } ] } ] } * ``` */ export declare const htmlToMdast: (htmlOrHast: string | Hast, options?: HtmlToMdastOptions) => Mdast;