49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
|
|
import { Cheerio, CheerioAPI } from 'cheerio/slim';
|
||
|
|
import { IPureNode } from 'markmap-common';
|
||
|
|
export declare enum Levels {
|
||
|
|
None = 0,
|
||
|
|
H1 = 1,
|
||
|
|
H2 = 2,
|
||
|
|
H3 = 3,
|
||
|
|
H4 = 4,
|
||
|
|
H5 = 5,
|
||
|
|
H6 = 6,
|
||
|
|
Block = 7,
|
||
|
|
List = 8,
|
||
|
|
ListItem = 9
|
||
|
|
}
|
||
|
|
export interface IHtmlNode {
|
||
|
|
id: number;
|
||
|
|
tag: string;
|
||
|
|
html: string;
|
||
|
|
level: Levels;
|
||
|
|
parent: number;
|
||
|
|
childrenLevel: Levels;
|
||
|
|
children?: IHtmlNode[];
|
||
|
|
comments?: string[];
|
||
|
|
data?: Record<string, unknown>;
|
||
|
|
}
|
||
|
|
export interface IHtmlParserContext {
|
||
|
|
$node: Cheerio<any>;
|
||
|
|
$: CheerioAPI;
|
||
|
|
getContent($node: Cheerio<any>, preserveTag?: boolean): {
|
||
|
|
html?: string;
|
||
|
|
comments?: string[];
|
||
|
|
};
|
||
|
|
}
|
||
|
|
export interface IHtmlParserResult {
|
||
|
|
html?: string | null;
|
||
|
|
comments?: string[];
|
||
|
|
queue?: Cheerio<any>;
|
||
|
|
nesting?: boolean;
|
||
|
|
}
|
||
|
|
export type IHtmlParserSelectorRules = Record<string, (context: IHtmlParserContext) => IHtmlParserResult>;
|
||
|
|
export interface IHtmlParserOptions {
|
||
|
|
selector: string;
|
||
|
|
selectorRules: IHtmlParserSelectorRules;
|
||
|
|
}
|
||
|
|
export declare const defaultOptions: IHtmlParserOptions;
|
||
|
|
export declare function parseHtml(html: string, opts?: Partial<IHtmlParserOptions>): IHtmlNode;
|
||
|
|
export declare function convertNode(htmlRoot: IHtmlNode): IPureNode;
|
||
|
|
export declare function buildTree(html: string, opts?: Partial<IHtmlParserOptions>): IPureNode;
|