forked from remarkablemark/html-react-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
25 lines (22 loc) · 844 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 domParserOptionsDefault = { 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, domParserOptions = {}) {
if (typeof html !== 'string') {
throw new TypeError('First argument must be a string');
}
return domToReact(htmlToDOM(html, { ...domParserOptionsDefault, domParserOptions }), options);
}
/**
* Export HTML to React parser.
*/
module.exports = HTMLReactParser;