forked from remarkablemark/html-react-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
60 lines (51 loc) · 1.55 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// TypeScript Version: 5.0
/* eslint-disable no-undef, no-unused-vars */
import {
Comment,
Element,
Node,
ProcessingInstruction,
Text
} from 'domhandler';
import type { DomHandlerOptions } from 'domhandler';
import htmlToDOM from 'html-dom-parser';
import { ParserOptions } from 'htmlparser2';
import attributesToProps from './lib/attributes-to-props';
import domToReact from './lib/dom-to-react';
export { attributesToProps, domToReact, htmlToDOM };
export type HTMLParser2Options = ParserOptions & DomHandlerOptions;
export { Comment, Element, ProcessingInstruction, Text };
export type DOMNode = Comment | Element | Node | ProcessingInstruction | Text;
export interface HTMLReactParserOptions {
htmlparser2?: HTMLParser2Options;
library?: {
cloneElement: (
element: JSX.Element,
props?: object,
...children: any
) => JSX.Element;
createElement: (type: any, props?: object, ...children: any) => JSX.Element;
isValidElement: (element: any) => boolean;
[key: string]: any;
};
replace?: (
domNode: DOMNode
) => JSX.Element | object | void | undefined | null | false;
transform?: (
reactNode: JSX.Element | string,
domNode: DOMNode,
index: number
) => JSX.Element | string | null;
trim?: boolean;
}
/**
* Converts HTML string to JSX element(s).
*
* @param html - HTML string.
* @param options - Parser options.
* @returns - JSX element(s), empty array, or string.
*/
export default function HTMLReactParser(
html: string,
options?: HTMLReactParserOptions
): ReturnType<typeof domToReact>;