File tree Expand file tree Collapse file tree 3 files changed +12
-8
lines changed Expand file tree Collapse file tree 3 files changed +12
-8
lines changed Original file line number Diff line number Diff line change 5
5
- npm install
6
6
script :
7
7
- npm run lint
8
+ - npm run dtslint
8
9
- npm run cover
9
10
- npm run build
10
11
- npm run benchmark
Original file line number Diff line number Diff line change @@ -9,8 +9,8 @@ export default HTMLReactParser;
9
9
type ReactElement = React . DetailedReactHTMLElement < { } , HTMLElement > ;
10
10
11
11
export interface HTMLReactParserOptions {
12
- // TODO: Specify return type. React.ReactElement | undefined | false is not enough
13
- replace ( domNode : DomNode ) : any ;
12
+ // TODO: Replace `object` by type for objects like `{ type: 'h1', props: { children: 'Heading' } }`
13
+ replace ( domNode : DomNode ) : React . ReactElement | object | undefined | false ;
14
14
}
15
15
16
16
/**
Original file line number Diff line number Diff line change 1
- import parse from 'html-dom-parser' ;
1
+ import parse , { HTMLReactParserOptions } from 'html-dom-parser' ;
2
2
import * as React from 'react' ;
3
3
4
4
// $ExpectType string | DetailedReactHTMLElement<{}, HTMLElement> | DetailedReactHTMLElement<{}, HTMLElement>[]
@@ -16,13 +16,16 @@ parse('<p id="replace">text</p>', {
16
16
} ) ;
17
17
18
18
// Return ReactElement
19
- parse ( '<p><br id="remove"></p>' , {
20
- replace : ( { attribs } ) =>
21
- attribs && attribs . id === 'remove' && < React . Fragment />
22
- } ) ;
19
+ const options : HTMLReactParserOptions = {
20
+ replace ( { attribs } ) {
21
+ return attribs && attribs . id === 'remove' && < React . Fragment /> ;
22
+ }
23
+ }
24
+
25
+ parse ( '<p><br id="remove"></p>' , options ) ;
23
26
24
27
// Return domhandler node
25
- parse ( '<a href="#">Heading</a>' , {
28
+ parse ( '<a id="header" href="#">Heading</a>' , {
26
29
replace : node => {
27
30
if ( node . attribs && node . attribs . id === 'header' ) {
28
31
return {
You can’t perform that action at this time.
0 commit comments