html-react-parser 4.2.1 → 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 +5 -5
- package/dist/html-react-parser.js +35 -32
- 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 +15 -10
- package/package.json +15 -15
package/README.md
CHANGED
|
@@ -155,7 +155,7 @@ The `replace` callback's first argument is [domhandler](https://github.com/fb55/
|
|
|
155
155
|
|
|
156
156
|
```js
|
|
157
157
|
parse('<br>', {
|
|
158
|
-
replace: domNode => {
|
|
158
|
+
replace: (domNode) => {
|
|
159
159
|
console.dir(domNode, { depth: null });
|
|
160
160
|
}
|
|
161
161
|
});
|
|
@@ -186,7 +186,7 @@ The element is replaced if a **valid** React element is returned:
|
|
|
186
186
|
|
|
187
187
|
```jsx
|
|
188
188
|
parse('<p id="replace">text</p>', {
|
|
189
|
-
replace: domNode => {
|
|
189
|
+
replace: (domNode) => {
|
|
190
190
|
if (domNode.attribs && domNode.attribs.id === 'replace') {
|
|
191
191
|
return <span>replaced</span>;
|
|
192
192
|
}
|
|
@@ -202,7 +202,7 @@ For TypeScript projects, you may need to check that `domNode` is an instance of
|
|
|
202
202
|
import { HTMLReactParserOptions, Element } from 'html-react-parser';
|
|
203
203
|
|
|
204
204
|
const options: HTMLReactParserOptions = {
|
|
205
|
-
replace: domNode => {
|
|
205
|
+
replace: (domNode) => {
|
|
206
206
|
if (domNode instanceof Element && domNode.attribs) {
|
|
207
207
|
// ...
|
|
208
208
|
}
|
|
@@ -281,7 +281,7 @@ const html = `
|
|
|
281
281
|
`;
|
|
282
282
|
|
|
283
283
|
const options = {
|
|
284
|
-
replace: domNode => {
|
|
284
|
+
replace: (domNode) => {
|
|
285
285
|
if (domNode.attribs && domNode.name === 'main') {
|
|
286
286
|
const props = attributesToProps(domNode.attribs);
|
|
287
287
|
return <div {...props} />;
|
|
@@ -437,7 +437,7 @@ For the `replace` option, you may need to do the following:
|
|
|
437
437
|
import { Element } from 'domhandler/lib/node';
|
|
438
438
|
|
|
439
439
|
parse('<br class="remove">', {
|
|
440
|
-
replace: domNode => {
|
|
440
|
+
replace: (domNode) => {
|
|
441
441
|
if (domNode instanceof Element && domNode.attribs.class === 'remove') {
|
|
442
442
|
return <></>;
|
|
443
443
|
}
|
|
@@ -2222,7 +2222,7 @@
|
|
|
2222
2222
|
|
|
2223
2223
|
var utilities$3 = {};
|
|
2224
2224
|
|
|
2225
|
-
utilities$3
|
|
2225
|
+
Object.defineProperty(utilities$3, "__esModule", { value: true });
|
|
2226
2226
|
utilities$3.camelCase = void 0;
|
|
2227
2227
|
var CUSTOM_PROPERTY_REGEX = /^--[a-zA-Z0-9-]+$/;
|
|
2228
2228
|
var HYPHEN_REGEX = /-([a-z])/g;
|
|
@@ -2254,27 +2254,25 @@
|
|
|
2254
2254
|
};
|
|
2255
2255
|
utilities$3.camelCase = camelCase;
|
|
2256
2256
|
|
|
2257
|
-
(function (
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
exports["default"] = StyleToJS;
|
|
2277
|
-
} (cjs));
|
|
2257
|
+
var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
2258
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
2259
|
+
};
|
|
2260
|
+
Object.defineProperty(cjs, "__esModule", { value: true });
|
|
2261
|
+
var style_to_object_1 = __importDefault(styleToObjectExports);
|
|
2262
|
+
var utilities_1 = utilities$3;
|
|
2263
|
+
function StyleToJS(style, options) {
|
|
2264
|
+
var output = {};
|
|
2265
|
+
if (!style || typeof style !== 'string') {
|
|
2266
|
+
return output;
|
|
2267
|
+
}
|
|
2268
|
+
(0, style_to_object_1.default)(style, function (property, value) {
|
|
2269
|
+
if (property && value) {
|
|
2270
|
+
output[(0, utilities_1.camelCase)(property, options)] = value;
|
|
2271
|
+
}
|
|
2272
|
+
});
|
|
2273
|
+
return output;
|
|
2274
|
+
}
|
|
2275
|
+
cjs.default = StyleToJS;
|
|
2278
2276
|
|
|
2279
2277
|
var React$1 = require$$0__default["default"];
|
|
2280
2278
|
var styleToJS = cjs.default;
|
|
@@ -2314,16 +2312,6 @@
|
|
|
2314
2312
|
return result;
|
|
2315
2313
|
}
|
|
2316
2314
|
|
|
2317
|
-
/**
|
|
2318
|
-
* Check if a given tag is a custom component.
|
|
2319
|
-
*
|
|
2320
|
-
* @see {@link https://github.com/facebook/react/blob/v16.6.3/packages/react-dom/src/shared/isCustomComponent.js}
|
|
2321
|
-
*
|
|
2322
|
-
* @param {string} tagName - The name of the html tag.
|
|
2323
|
-
* @param {object} props - The props being passed to the element.
|
|
2324
|
-
* @returns - Whether tag is custom component.
|
|
2325
|
-
*/
|
|
2326
|
-
|
|
2327
2315
|
var RESERVED_SVG_MATHML_ELEMENTS = new Set([
|
|
2328
2316
|
'annotation-xml',
|
|
2329
2317
|
'color-profile',
|
|
@@ -2335,6 +2323,15 @@
|
|
|
2335
2323
|
'missing-glyph'
|
|
2336
2324
|
]);
|
|
2337
2325
|
|
|
2326
|
+
/**
|
|
2327
|
+
* Check if a given tag is a custom component.
|
|
2328
|
+
*
|
|
2329
|
+
* @see {@link https://github.com/facebook/react/blob/v16.6.3/packages/react-dom/src/shared/isCustomComponent.js}
|
|
2330
|
+
*
|
|
2331
|
+
* @param {string} tagName - The name of the html tag.
|
|
2332
|
+
* @param {object} props - The props being passed to the element.
|
|
2333
|
+
* @returns {boolean} - Whether tag is custom component.
|
|
2334
|
+
*/
|
|
2338
2335
|
function isCustomComponent(tagName, props) {
|
|
2339
2336
|
if (tagName.indexOf('-') === -1) {
|
|
2340
2337
|
return props && typeof props.is === 'string';
|
|
@@ -2399,6 +2396,12 @@
|
|
|
2399
2396
|
return !ELEMENTS_WITH_NO_TEXT_CHILDREN.has(node.name);
|
|
2400
2397
|
}
|
|
2401
2398
|
|
|
2399
|
+
/**
|
|
2400
|
+
* Returns the first argument as is.
|
|
2401
|
+
*
|
|
2402
|
+
* @param {any} arg - The argument to be returned.
|
|
2403
|
+
* @returns {any} The input argument `arg`.
|
|
2404
|
+
*/
|
|
2402
2405
|
function returnFirstArg(arg) {
|
|
2403
2406
|
return arg;
|
|
2404
2407
|
}
|