html-react-parser 4.2.0 → 4.2.2
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 +30 -10
- package/dist/html-react-parser.js +53 -49
- 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/lib/utilities.js +33 -27
- package/package.json +15 -15
package/lib/utilities.js
CHANGED
|
@@ -13,14 +13,12 @@ function invertObject(obj, override) {
|
|
|
13
13
|
throw new TypeError('First argument must be an object');
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
var key;
|
|
17
|
-
var value;
|
|
18
16
|
var isOverridePresent = typeof override === 'function';
|
|
19
17
|
var overrides = {};
|
|
20
18
|
var result = {};
|
|
21
19
|
|
|
22
|
-
for (key in obj) {
|
|
23
|
-
value = obj[key];
|
|
20
|
+
for (var key in obj) {
|
|
21
|
+
var value = obj[key];
|
|
24
22
|
|
|
25
23
|
if (isOverridePresent) {
|
|
26
24
|
overrides = override(key, value);
|
|
@@ -38,6 +36,17 @@ function invertObject(obj, override) {
|
|
|
38
36
|
return result;
|
|
39
37
|
}
|
|
40
38
|
|
|
39
|
+
var RESERVED_SVG_MATHML_ELEMENTS = new Set([
|
|
40
|
+
'annotation-xml',
|
|
41
|
+
'color-profile',
|
|
42
|
+
'font-face',
|
|
43
|
+
'font-face-src',
|
|
44
|
+
'font-face-uri',
|
|
45
|
+
'font-face-format',
|
|
46
|
+
'font-face-name',
|
|
47
|
+
'missing-glyph'
|
|
48
|
+
]);
|
|
49
|
+
|
|
41
50
|
/**
|
|
42
51
|
* Check if a given tag is a custom component.
|
|
43
52
|
*
|
|
@@ -45,33 +54,24 @@ function invertObject(obj, override) {
|
|
|
45
54
|
*
|
|
46
55
|
* @param {string} tagName - The name of the html tag.
|
|
47
56
|
* @param {object} props - The props being passed to the element.
|
|
48
|
-
* @returns - Whether tag is custom component.
|
|
57
|
+
* @returns {boolean} - Whether tag is custom component.
|
|
49
58
|
*/
|
|
50
59
|
function isCustomComponent(tagName, props) {
|
|
51
60
|
if (tagName.indexOf('-') === -1) {
|
|
52
61
|
return props && typeof props.is === 'string';
|
|
53
62
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
case 'annotation-xml':
|
|
61
|
-
case 'color-profile':
|
|
62
|
-
case 'font-face':
|
|
63
|
-
case 'font-face-src':
|
|
64
|
-
case 'font-face-uri':
|
|
65
|
-
case 'font-face-format':
|
|
66
|
-
case 'font-face-name':
|
|
67
|
-
case 'missing-glyph':
|
|
68
|
-
return false;
|
|
69
|
-
default:
|
|
70
|
-
return true;
|
|
63
|
+
// These are reserved SVG and MathML elements.
|
|
64
|
+
// We don't mind this whitelist too much because we expect it to never grow.
|
|
65
|
+
// The alternative is to track the namespace in a few places which is convoluted.
|
|
66
|
+
// https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
|
|
67
|
+
if (RESERVED_SVG_MATHML_ELEMENTS.has(tagName)) {
|
|
68
|
+
return false;
|
|
71
69
|
}
|
|
70
|
+
return true;
|
|
72
71
|
}
|
|
73
72
|
|
|
74
|
-
|
|
73
|
+
// styleToJSOptions
|
|
74
|
+
var STYLE_TO_JS_OPTIONS = { reactCompat: true };
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
77
|
* Sets style prop.
|
|
@@ -84,7 +84,7 @@ function setStyleProp(style, props) {
|
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
86
|
try {
|
|
87
|
-
props.style = styleToJS(style,
|
|
87
|
+
props.style = styleToJS(style, STYLE_TO_JS_OPTIONS);
|
|
88
88
|
} catch (err) {
|
|
89
89
|
props.style = {};
|
|
90
90
|
}
|
|
@@ -98,7 +98,7 @@ var PRESERVE_CUSTOM_ATTRIBUTES = React.version.split('.')[0] >= 16;
|
|
|
98
98
|
|
|
99
99
|
// Taken from
|
|
100
100
|
// https://github.com/facebook/react/blob/cae635054e17a6f107a39d328649137b83f25972/packages/react-dom/src/client/validateDOMNesting.js#L213
|
|
101
|
-
var
|
|
101
|
+
var ELEMENTS_WITH_NO_TEXT_CHILDREN = new Set([
|
|
102
102
|
'tr',
|
|
103
103
|
'tbody',
|
|
104
104
|
'thead',
|
|
@@ -117,19 +117,25 @@ var elementsWithNoTextChildren = new Set([
|
|
|
117
117
|
* @returns - Whether node can contain text nodes.
|
|
118
118
|
*/
|
|
119
119
|
function canTextBeChildOfNode(node) {
|
|
120
|
-
return !
|
|
120
|
+
return !ELEMENTS_WITH_NO_TEXT_CHILDREN.has(node.name);
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Returns the first argument as is.
|
|
125
|
+
*
|
|
126
|
+
* @param {any} arg - The argument to be returned.
|
|
127
|
+
* @returns {any} The input argument `arg`.
|
|
128
|
+
*/
|
|
123
129
|
function returnFirstArg(arg) {
|
|
124
130
|
return arg;
|
|
125
131
|
}
|
|
126
132
|
|
|
127
133
|
module.exports = {
|
|
128
134
|
PRESERVE_CUSTOM_ATTRIBUTES: PRESERVE_CUSTOM_ATTRIBUTES,
|
|
135
|
+
ELEMENTS_WITH_NO_TEXT_CHILDREN: ELEMENTS_WITH_NO_TEXT_CHILDREN,
|
|
129
136
|
invertObject: invertObject,
|
|
130
137
|
isCustomComponent: isCustomComponent,
|
|
131
138
|
setStyleProp: setStyleProp,
|
|
132
139
|
canTextBeChildOfNode: canTextBeChildOfNode,
|
|
133
|
-
elementsWithNoTextChildren: elementsWithNoTextChildren,
|
|
134
140
|
returnFirstArg: returnFirstArg
|
|
135
141
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "html-react-parser",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.2",
|
|
4
4
|
"description": "HTML to React parser.",
|
|
5
5
|
"author": "Mark <mark@remarkablemark.org>",
|
|
6
6
|
"main": "index.js",
|
|
@@ -52,34 +52,34 @@
|
|
|
52
52
|
"domhandler": "5.0.3",
|
|
53
53
|
"html-dom-parser": "4.0.0",
|
|
54
54
|
"react-property": "2.0.0",
|
|
55
|
-
"style-to-js": "1.1.
|
|
55
|
+
"style-to-js": "1.1.4"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@commitlint/cli": "17.
|
|
59
|
-
"@commitlint/config-conventional": "17.
|
|
60
|
-
"@rollup/plugin-commonjs": "25.0.
|
|
61
|
-
"@rollup/plugin-node-resolve": "15.1
|
|
58
|
+
"@commitlint/cli": "17.7.1",
|
|
59
|
+
"@commitlint/config-conventional": "17.7.0",
|
|
60
|
+
"@rollup/plugin-commonjs": "25.0.4",
|
|
61
|
+
"@rollup/plugin-node-resolve": "15.2.1",
|
|
62
62
|
"@size-limit/preset-big-lib": "8.2.6",
|
|
63
|
-
"@types/react": "18.2.
|
|
64
|
-
"@typescript-eslint/parser": "6.
|
|
63
|
+
"@types/react": "18.2.21",
|
|
64
|
+
"@typescript-eslint/parser": "6.5.0",
|
|
65
65
|
"benchmark": "2.1.4",
|
|
66
66
|
"dtslint": "4.2.1",
|
|
67
|
-
"eslint": "8.
|
|
67
|
+
"eslint": "8.48.0",
|
|
68
68
|
"eslint-plugin-prettier": "5.0.0",
|
|
69
69
|
"husky": "8.0.3",
|
|
70
|
-
"jest": "29.6.
|
|
71
|
-
"jest-environment-jsdom": "29.6.
|
|
72
|
-
"lint-staged": "
|
|
70
|
+
"jest": "29.6.4",
|
|
71
|
+
"jest-environment-jsdom": "29.6.4",
|
|
72
|
+
"lint-staged": "14.0.1",
|
|
73
73
|
"pinst": "3.0.0",
|
|
74
|
-
"preact": "10.
|
|
75
|
-
"prettier": "3.0.
|
|
74
|
+
"preact": "10.17.1",
|
|
75
|
+
"prettier": "3.0.3",
|
|
76
76
|
"react": "18.2.0",
|
|
77
77
|
"react-dom": "18.2.0",
|
|
78
78
|
"rimraf": "5.0.1",
|
|
79
79
|
"rollup": "2.79.1",
|
|
80
80
|
"rollup-plugin-terser": "7.0.2",
|
|
81
81
|
"size-limit": "8.2.6",
|
|
82
|
-
"typescript": "5.
|
|
82
|
+
"typescript": "5.2.2"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
85
|
"react": "0.14 || 15 || 16 || 17 || 18"
|