1 | export interface NodeAttributes {
|
2 | [attribute: string]: string;
|
3 | }
|
4 |
|
5 | export type NodeContent = Array<Node | PostHTMLTree | PostHTMLTree[]>;
|
6 |
|
7 |
|
8 |
|
9 | export interface Node<T = string, A = NodeAttributes> {
|
10 | tag?: T;
|
11 | attrs?: A;
|
12 | content?: NodeContent;
|
13 | }
|
14 |
|
15 | type Matcher = string | RegExp | object;
|
16 | type Expression = Matcher | Matcher[];
|
17 | type CallbackNode = (node: Node) => Node | Node[];
|
18 |
|
19 | export interface PostHTMLTree {
|
20 | walk: (cb: CallbackNode) => PostHTMLTree;
|
21 | match: (expression: Expression, cb: CallbackNode) => CallbackNode;
|
22 | }
|
23 |
|
24 | export interface PostHTMLOptions {
|
25 | sync?: boolean;
|
26 | parser?: Function;
|
27 | render?: Function;
|
28 | skipParse?: boolean;
|
29 | }
|
30 |
|
31 | type Plugin<T> = (tree: PostHTMLTree) => void | PostHTMLTree | ThisType<T>;
|
32 |
|
33 | interface Result<M> {
|
34 | html: string;
|
35 | tree: PostHTMLTree;
|
36 | messages: M[];
|
37 | }
|
38 |
|
39 | declare class PostHTML<T, M> {
|
40 | version: string;
|
41 | name: 'posthtml';
|
42 | plugins: Plugin<T>[];
|
43 | messages: M[];
|
44 | use<T>(plugins: Plugin<T> | Plugin<T>[]): this;
|
45 | process(html: string, options?: PostHTMLOptions): Promise<Result<M>>;
|
46 | }
|
47 |
|
48 | declare function posthtml<T, M>(plugins?: Plugin<T>[]): PostHTML<T, M>;
|
49 |
|
50 | export default posthtml;
|