html-react-parser 1.4.12 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/dist/html-react-parser.js +927 -740
- package/dist/html-react-parser.js.map +1 -1
- package/dist/html-react-parser.min.js +1 -1
- package/dist/html-react-parser.min.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +7 -7
- package/lib/attributes-to-props.d.ts +2 -2
- package/lib/attributes-to-props.js +3 -3
- package/lib/dom-to-react.d.ts +3 -3
- package/lib/dom-to-react.js +7 -7
- package/lib/utilities.js +7 -7
- package/package.json +20 -19
package/index.d.ts
CHANGED
|
@@ -43,9 +43,9 @@ export interface HTMLReactParserOptions {
|
|
|
43
43
|
/**
|
|
44
44
|
* Converts HTML string to JSX element(s).
|
|
45
45
|
*
|
|
46
|
-
* @param
|
|
47
|
-
* @param
|
|
48
|
-
* @
|
|
46
|
+
* @param html - HTML string.
|
|
47
|
+
* @param options - Parser options.
|
|
48
|
+
* @returns - JSX element(s), empty array, or string.
|
|
49
49
|
*/
|
|
50
50
|
export default function HTMLReactParser(
|
|
51
51
|
html: string,
|
package/index.js
CHANGED
|
@@ -12,12 +12,12 @@ var domParserOptions = { lowerCaseAttributeNames: false };
|
|
|
12
12
|
/**
|
|
13
13
|
* Converts HTML string to React elements.
|
|
14
14
|
*
|
|
15
|
-
* @param
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
18
|
-
* @param
|
|
19
|
-
* @param
|
|
20
|
-
* @
|
|
15
|
+
* @param {string} html - HTML string.
|
|
16
|
+
* @param {object} [options] - Parser options.
|
|
17
|
+
* @param {object} [options.htmlparser2] - htmlparser2 options.
|
|
18
|
+
* @param {object} [options.library] - Library for React, Preact, etc.
|
|
19
|
+
* @param {Function} [options.replace] - Replace method.
|
|
20
|
+
* @returns {JSX.Element|JSX.Element[]|string} - React element(s), empty array, or string.
|
|
21
21
|
*/
|
|
22
22
|
function HTMLReactParser(html, options) {
|
|
23
23
|
if (typeof html !== 'string') {
|
|
@@ -36,7 +36,7 @@ function HTMLReactParser(html, options) {
|
|
|
36
36
|
HTMLReactParser.domToReact = domToReact;
|
|
37
37
|
HTMLReactParser.htmlToDOM = htmlToDOM;
|
|
38
38
|
HTMLReactParser.attributesToProps = attributesToProps;
|
|
39
|
-
HTMLReactParser.Element = require('domhandler
|
|
39
|
+
HTMLReactParser.Element = require('domhandler').Element;
|
|
40
40
|
|
|
41
41
|
// support CommonJS and ES Modules
|
|
42
42
|
module.exports = HTMLReactParser;
|
|
@@ -9,7 +9,7 @@ export type Props = Record<string, string> & {
|
|
|
9
9
|
/**
|
|
10
10
|
* Converts HTML/SVG DOM attributes to React props.
|
|
11
11
|
*
|
|
12
|
-
* @param
|
|
13
|
-
* @
|
|
12
|
+
* @param attributes - HTML/SVG DOM attributes.
|
|
13
|
+
* @returns - React props.
|
|
14
14
|
*/
|
|
15
15
|
export default function attributesToProps(attributes: Attributes): Props;
|
|
@@ -4,8 +4,8 @@ var utilities = require('./utilities');
|
|
|
4
4
|
/**
|
|
5
5
|
* Converts HTML/SVG DOM attributes to React props.
|
|
6
6
|
*
|
|
7
|
-
* @param
|
|
8
|
-
* @
|
|
7
|
+
* @param {object} [attributes={}] - HTML/SVG DOM attributes.
|
|
8
|
+
* @returns - React props.
|
|
9
9
|
*/
|
|
10
10
|
module.exports = function attributesToProps(attributes) {
|
|
11
11
|
attributes = attributes || {};
|
|
@@ -79,7 +79,7 @@ module.exports = function attributesToProps(attributes) {
|
|
|
79
79
|
* Gets prop name from lowercased attribute name.
|
|
80
80
|
*
|
|
81
81
|
* @param {string} attributeName - Lowercased attribute name.
|
|
82
|
-
* @
|
|
82
|
+
* @returns - Prop name.
|
|
83
83
|
*/
|
|
84
84
|
function getPropName(attributeName) {
|
|
85
85
|
return reactProperty.possibleStandardNames[attributeName];
|
package/lib/dom-to-react.d.ts
CHANGED
|
@@ -7,9 +7,9 @@ export { DOMNode, HTMLReactParserOptions };
|
|
|
7
7
|
/**
|
|
8
8
|
* Converts DOM nodes to JSX element(s).
|
|
9
9
|
*
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
12
|
-
* @
|
|
10
|
+
* @param nodes - DOM nodes.
|
|
11
|
+
* @param options - Parser options.
|
|
12
|
+
* @returns - JSX element(s).
|
|
13
13
|
*/
|
|
14
14
|
export default function domToReact(
|
|
15
15
|
nodes: DOMNode[],
|
package/lib/dom-to-react.js
CHANGED
|
@@ -8,11 +8,11 @@ var canTextBeChildOfNode = utilities.canTextBeChildOfNode;
|
|
|
8
8
|
/**
|
|
9
9
|
* Converts DOM nodes to JSX element(s).
|
|
10
10
|
*
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
15
|
-
* @
|
|
11
|
+
* @param {DomElement[]} nodes - DOM nodes.
|
|
12
|
+
* @param {object} [options={}] - Options.
|
|
13
|
+
* @param {Function} [options.replace] - Replacer.
|
|
14
|
+
* @param {object} [options.library] - Library (React, Preact, etc.).
|
|
15
|
+
* @returns - String or JSX element(s).
|
|
16
16
|
*/
|
|
17
17
|
function domToReact(nodes, options) {
|
|
18
18
|
options = options || {};
|
|
@@ -125,8 +125,8 @@ function domToReact(nodes, options) {
|
|
|
125
125
|
* Determines whether DOM element attributes should be transformed to props.
|
|
126
126
|
* Web Components should not have their attributes transformed except for `style`.
|
|
127
127
|
*
|
|
128
|
-
* @param
|
|
129
|
-
* @
|
|
128
|
+
* @param {DomElement} node
|
|
129
|
+
* @returns - Whether node attributes should be converted to props.
|
|
130
130
|
*/
|
|
131
131
|
function skipAttributesToProps(node) {
|
|
132
132
|
return (
|
package/lib/utilities.js
CHANGED
|
@@ -4,9 +4,9 @@ var styleToJS = require('style-to-js').default;
|
|
|
4
4
|
/**
|
|
5
5
|
* Swap key with value in an object.
|
|
6
6
|
*
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
9
|
-
* @
|
|
7
|
+
* @param {object} obj - The object.
|
|
8
|
+
* @param {Function} [override] - The override method.
|
|
9
|
+
* @returns - The inverted object.
|
|
10
10
|
*/
|
|
11
11
|
function invertObject(obj, override) {
|
|
12
12
|
if (!obj || typeof obj !== 'object') {
|
|
@@ -44,8 +44,8 @@ function invertObject(obj, override) {
|
|
|
44
44
|
* @see {@link https://github.com/facebook/react/blob/v16.6.3/packages/react-dom/src/shared/isCustomComponent.js}
|
|
45
45
|
*
|
|
46
46
|
* @param {string} tagName - The name of the html tag.
|
|
47
|
-
* @param {
|
|
48
|
-
* @
|
|
47
|
+
* @param {object} props - The props being passed to the element.
|
|
48
|
+
* @returns - Whether tag is custom component.
|
|
49
49
|
*/
|
|
50
50
|
function isCustomComponent(tagName, props) {
|
|
51
51
|
if (tagName.indexOf('-') === -1) {
|
|
@@ -113,8 +113,8 @@ var elementsWithNoTextChildren = new Set([
|
|
|
113
113
|
/**
|
|
114
114
|
* Checks if the given node can contain text nodes
|
|
115
115
|
*
|
|
116
|
-
* @param {DomElement} node
|
|
117
|
-
* @returns
|
|
116
|
+
* @param {DomElement} node - Node.
|
|
117
|
+
* @returns - Whether node can contain text nodes.
|
|
118
118
|
*/
|
|
119
119
|
function canTextBeChildOfNode(node) {
|
|
120
120
|
return !elementsWithNoTextChildren.has(node.name);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "html-react-parser",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "HTML to React parser.",
|
|
5
5
|
"author": "Mark <mark@remarkablemark.org>",
|
|
6
6
|
"main": "index.js",
|
|
@@ -45,35 +45,36 @@
|
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"domhandler": "4.3.1",
|
|
48
|
-
"html-dom-parser": "
|
|
48
|
+
"html-dom-parser": "2.0.0",
|
|
49
49
|
"react-property": "2.0.0",
|
|
50
|
-
"style-to-js": "1.1.
|
|
50
|
+
"style-to-js": "1.1.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@commitlint/cli": "
|
|
54
|
-
"@commitlint/config-conventional": "
|
|
55
|
-
"@rollup/plugin-commonjs": "
|
|
56
|
-
"@rollup/plugin-node-resolve": "13.
|
|
53
|
+
"@commitlint/cli": "17.0.2",
|
|
54
|
+
"@commitlint/config-conventional": "17.0.2",
|
|
55
|
+
"@rollup/plugin-commonjs": "22.0.0",
|
|
56
|
+
"@rollup/plugin-node-resolve": "13.3.0",
|
|
57
57
|
"@size-limit/preset-big-lib": "7.0.8",
|
|
58
|
-
"@types/react": "18.0.
|
|
59
|
-
"@typescript-eslint/parser": "5.
|
|
58
|
+
"@types/react": "18.0.14",
|
|
59
|
+
"@typescript-eslint/parser": "5.28.0",
|
|
60
60
|
"benchmark": "2.1.4",
|
|
61
61
|
"dtslint": "4.2.1",
|
|
62
|
-
"eslint": "8.
|
|
62
|
+
"eslint": "8.18.0",
|
|
63
63
|
"eslint-plugin-prettier": "4.0.0",
|
|
64
|
-
"husky": "
|
|
65
|
-
"jest": "
|
|
66
|
-
"
|
|
64
|
+
"husky": "8.0.1",
|
|
65
|
+
"jest": "28.1.1",
|
|
66
|
+
"jest-environment-jsdom": "28.1.1",
|
|
67
|
+
"lint-staged": "13.0.2",
|
|
67
68
|
"pinst": "3.0.0",
|
|
68
|
-
"preact": "10.
|
|
69
|
-
"prettier": "2.
|
|
70
|
-
"react": "18.
|
|
71
|
-
"react-dom": "18.
|
|
69
|
+
"preact": "10.8.1",
|
|
70
|
+
"prettier": "2.7.1",
|
|
71
|
+
"react": "18.2.0",
|
|
72
|
+
"react-dom": "18.2.0",
|
|
72
73
|
"rimraf": "3.0.2",
|
|
73
|
-
"rollup": "2.
|
|
74
|
+
"rollup": "2.75.6",
|
|
74
75
|
"rollup-plugin-terser": "7.0.2",
|
|
75
76
|
"size-limit": "7.0.8",
|
|
76
|
-
"typescript": "4.
|
|
77
|
+
"typescript": "4.7.4"
|
|
77
78
|
},
|
|
78
79
|
"peerDependencies": {
|
|
79
80
|
"react": "0.14 || 15 || 16 || 17 || 18"
|