-
-
Notifications
You must be signed in to change notification settings - Fork 129
/
index.js
25 lines (22 loc) · 782 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var domToReact = require('./lib/dom-to-react');
var htmlToDOM = require('html-dom-parser');
// decode HTML entities by default for `htmlparser2`
var domParserOptions = { decodeEntities: true, lowerCaseAttributeNames: false };
/**
* Convert HTML string to React elements.
*
* @param {String} html - The HTML string.
* @param {Object} [options] - The additional options.
* @param {Function} [options.replace] - The replace method.
* @return {ReactElement|Array}
*/
function HTMLReactParser(html, options) {
if (typeof html !== 'string') {
throw new TypeError('First argument must be a string');
}
return domToReact(htmlToDOM(html, domParserOptions), options);
}
/**
* Export HTML to React parser.
*/
module.exports = HTMLReactParser;