html-react-parser 4.2.0 → 4.2.1
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 +25 -5
- package/dist/html-react-parser.js +27 -26
- 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 +27 -26
- package/package.json +7 -7
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);
|
|
@@ -47,31 +45,34 @@ function invertObject(obj, override) {
|
|
|
47
45
|
* @param {object} props - The props being passed to the element.
|
|
48
46
|
* @returns - Whether tag is custom component.
|
|
49
47
|
*/
|
|
48
|
+
|
|
49
|
+
var RESERVED_SVG_MATHML_ELEMENTS = new Set([
|
|
50
|
+
'annotation-xml',
|
|
51
|
+
'color-profile',
|
|
52
|
+
'font-face',
|
|
53
|
+
'font-face-src',
|
|
54
|
+
'font-face-uri',
|
|
55
|
+
'font-face-format',
|
|
56
|
+
'font-face-name',
|
|
57
|
+
'missing-glyph'
|
|
58
|
+
]);
|
|
59
|
+
|
|
50
60
|
function isCustomComponent(tagName, props) {
|
|
51
61
|
if (tagName.indexOf('-') === -1) {
|
|
52
62
|
return props && typeof props.is === 'string';
|
|
53
63
|
}
|
|
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;
|
|
64
|
+
// These are reserved SVG and MathML elements.
|
|
65
|
+
// We don't mind this whitelist too much because we expect it to never grow.
|
|
66
|
+
// The alternative is to track the namespace in a few places which is convoluted.
|
|
67
|
+
// https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
|
|
68
|
+
if (RESERVED_SVG_MATHML_ELEMENTS.has(tagName)) {
|
|
69
|
+
return false;
|
|
71
70
|
}
|
|
71
|
+
return true;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
// styleToJSOptions
|
|
75
|
+
var STYLE_TO_JS_OPTIONS = { reactCompat: true };
|
|
75
76
|
|
|
76
77
|
/**
|
|
77
78
|
* Sets style prop.
|
|
@@ -84,7 +85,7 @@ function setStyleProp(style, props) {
|
|
|
84
85
|
return;
|
|
85
86
|
}
|
|
86
87
|
try {
|
|
87
|
-
props.style = styleToJS(style,
|
|
88
|
+
props.style = styleToJS(style, STYLE_TO_JS_OPTIONS);
|
|
88
89
|
} catch (err) {
|
|
89
90
|
props.style = {};
|
|
90
91
|
}
|
|
@@ -98,7 +99,7 @@ var PRESERVE_CUSTOM_ATTRIBUTES = React.version.split('.')[0] >= 16;
|
|
|
98
99
|
|
|
99
100
|
// Taken from
|
|
100
101
|
// https://github.com/facebook/react/blob/cae635054e17a6f107a39d328649137b83f25972/packages/react-dom/src/client/validateDOMNesting.js#L213
|
|
101
|
-
var
|
|
102
|
+
var ELEMENTS_WITH_NO_TEXT_CHILDREN = new Set([
|
|
102
103
|
'tr',
|
|
103
104
|
'tbody',
|
|
104
105
|
'thead',
|
|
@@ -117,7 +118,7 @@ var elementsWithNoTextChildren = new Set([
|
|
|
117
118
|
* @returns - Whether node can contain text nodes.
|
|
118
119
|
*/
|
|
119
120
|
function canTextBeChildOfNode(node) {
|
|
120
|
-
return !
|
|
121
|
+
return !ELEMENTS_WITH_NO_TEXT_CHILDREN.has(node.name);
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
function returnFirstArg(arg) {
|
|
@@ -126,10 +127,10 @@ function returnFirstArg(arg) {
|
|
|
126
127
|
|
|
127
128
|
module.exports = {
|
|
128
129
|
PRESERVE_CUSTOM_ATTRIBUTES: PRESERVE_CUSTOM_ATTRIBUTES,
|
|
130
|
+
ELEMENTS_WITH_NO_TEXT_CHILDREN: ELEMENTS_WITH_NO_TEXT_CHILDREN,
|
|
129
131
|
invertObject: invertObject,
|
|
130
132
|
isCustomComponent: isCustomComponent,
|
|
131
133
|
setStyleProp: setStyleProp,
|
|
132
134
|
canTextBeChildOfNode: canTextBeChildOfNode,
|
|
133
|
-
elementsWithNoTextChildren: elementsWithNoTextChildren,
|
|
134
135
|
returnFirstArg: returnFirstArg
|
|
135
136
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "html-react-parser",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "HTML to React parser.",
|
|
5
5
|
"author": "Mark <mark@remarkablemark.org>",
|
|
6
6
|
"main": "index.js",
|
|
@@ -60,19 +60,19 @@
|
|
|
60
60
|
"@rollup/plugin-commonjs": "25.0.3",
|
|
61
61
|
"@rollup/plugin-node-resolve": "15.1.0",
|
|
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.19",
|
|
64
|
+
"@typescript-eslint/parser": "6.3.0",
|
|
65
65
|
"benchmark": "2.1.4",
|
|
66
66
|
"dtslint": "4.2.1",
|
|
67
|
-
"eslint": "8.
|
|
67
|
+
"eslint": "8.46.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.
|
|
70
|
+
"jest": "29.6.2",
|
|
71
|
+
"jest-environment-jsdom": "29.6.2",
|
|
72
72
|
"lint-staged": "13.2.3",
|
|
73
73
|
"pinst": "3.0.0",
|
|
74
74
|
"preact": "10.16.0",
|
|
75
|
-
"prettier": "3.0.
|
|
75
|
+
"prettier": "3.0.1",
|
|
76
76
|
"react": "18.2.0",
|
|
77
77
|
"react-dom": "18.2.0",
|
|
78
78
|
"rimraf": "5.0.1",
|