Skip to content

Commit f06707b

Browse files
docs(readme): document how to exclude nodes with replace
Resolves #56
1 parent aa5db48 commit f06707b

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ Parser('<p id="replace">text</p>', {
120120
});
121121
```
122122

123-
Here's an [example](https://repl.it/@remarkablemark/html-react-parser-replace-example) that replaces but keeps the children:
124-
```js
123+
Here's an [example](https://repl.it/@remarkablemark/html-react-parser-replace-example) of using `replace` to modify the children:
124+
```jsx
125125
// with ES6 and JSX
126126
import domToReact from 'html-react-parser/lib/dom-to-react';
127127

@@ -166,6 +166,17 @@ ReactDOMServer.renderToStaticMarkup(reactElement);
166166
</h1>
167167
```
168168

169+
Here's an [example](https://repl.it/@remarkablemark/html-react-parser-issue-56) of using `replace` to exclude an element:
170+
```js
171+
Parser('<p><br id="remove"></p>', {
172+
replace: ({ attribs }) => {
173+
if (attribs && attribs.id === 'remove') {
174+
return React.createElement(React.Fragment);
175+
}
176+
},
177+
});
178+
```
179+
169180
## Testing
170181

171182
```sh

0 commit comments

Comments
 (0)