UNPKG

995 BTypeScriptView Raw
1// TypeScript Version: 3.3
2
3import * as React from 'react';
4import { DomElement } from 'domhandler';
5import domToReact from './lib/dom-to-react';
6import htmlToDOM from 'html-dom-parser';
7
8export interface HTMLReactParserOptions {
9 // TODO: Replace `object` by type for objects like `{ type: 'h1', props: { children: 'Heading' } }`
10 replace(domNode: DomElement): React.ReactElement | object | undefined | false;
11 library?: object;
12}
13
14/**
15 * Converts HTML string to React elements.
16 *
17 * @param html - The HTML string to parse to React.
18 * @param options - The parser options.
19 * @return - When parsed with HTML string, returns React elements; otherwise, returns string or empty array.
20 */
21declare function HTMLReactParser(
22 html: string,
23 options?: HTMLReactParserOptions
24):
25 | string
26 | React.DetailedReactHTMLElement<{}, HTMLElement>
27 | Array<React.DetailedReactHTMLElement<{}, HTMLElement>>;
28
29export { DomElement, domToReact, htmlToDOM };
30
31export default HTMLReactParser;