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 55- npm install
66script :
77- npm run lint
8+ - npm run dtslint
89- npm run cover
910- npm run build
1011- npm run benchmark
Original file line number Diff line number Diff line change @@ -9,8 +9,8 @@ export default HTMLReactParser;
99type ReactElement = React . DetailedReactHTMLElement < { } , HTMLElement > ;
1010
1111export 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 ;
1414}
1515
1616/**
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' ;
22import * as React from 'react' ;
33
44// $ExpectType string | DetailedReactHTMLElement<{}, HTMLElement> | DetailedReactHTMLElement<{}, HTMLElement>[]
@@ -16,13 +16,16 @@ parse('<p id="replace">text</p>', {
1616} ) ;
1717
1818// 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 ) ;
2326
2427// Return domhandler node
25- parse ( '<a href="#">Heading</a>' , {
28+ parse ( '<a id="header" href="#">Heading</a>' , {
2629 replace : node => {
2730 if ( node . attribs && node . attribs . id === 'header' ) {
2831 return {
You can’t perform that action at this time.
0 commit comments