Skip to content

Commit

Permalink
Update README with an example usage of the replace option
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Aug 22, 2016
1 parent 7bcff2a commit 4ce37b0
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,33 @@ ReactDOM.render(
);
```

### Options

#### replace(domNode)

```js
var Parser = require('html-react-parser');
var React = require('react');
var ReactDOM = require('react-dom');

var reactElement = Parser('<div><p id="main">replace me</p></div>', {
replace: function(domNode) {
if (domNode.attribs && domNode.attribs.id === 'main') {
// element is replaced only if a valid React element is returned
return React.createElement('span', { style: { fontSize: '42px' } }, 'replaced!');
}
}
});

ReactDOM.render(
reactElement,
document.getElementById('replace')
);
// <div><span style="font-size: 42px;">replaced!</span></div>
```

The object properties of `domNode` is the same as the output from `require('htmlparser2').parseDOM`.

## Testing

```sh
Expand Down

0 comments on commit 4ce37b0

Please sign in to comment.