html-react-parser 0.13.0 → 0.14.3
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/CHANGELOG.md +26 -4
- package/README.md +80 -33
- package/dist/html-react-parser.js +115 -81
- 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 +2 -1
- package/index.js +2 -0
- package/lib/attributes-to-props.d.ts +11 -0
- package/lib/attributes-to-props.js +5 -29
- package/lib/dom-to-react.js +21 -15
- package/lib/utilities.js +19 -29
- package/package.json +27 -28
package/CHANGELOG.md
CHANGED
|
@@ -2,16 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
# [0.13.0](https://github.com/remarkablemark/html-react-parser/compare/v0.12.0...v0.13.0) (2020-06-07)
|
|
5
|
+
## [0.14.3](https://github.com/remarkablemark/html-react-parser/compare/v0.14.2...v0.14.3) (2020-12-12)
|
|
7
6
|
|
|
8
7
|
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **dom-to-react:** transform style to object for Web Components ([83efbce](https://github.com/remarkablemark/html-react-parser/commit/83efbce1123d3fb6d28b066cf60559a769e9a138)), closes [#188](https://github.com/remarkablemark/html-react-parser/issues/188)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
<a name="0.14.2"></a>
|
|
15
|
+
## [0.14.2](https://github.com/remarkablemark/html-react-parser/compare/v0.14.1...v0.14.2) (2020-11-23)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
<a name="0.14.1"></a>
|
|
20
|
+
## [0.14.1](https://github.com/remarkablemark/html-react-parser/compare/v0.14.0...v0.14.1) (2020-11-03)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## [0.14.0](https://github.com/remarkablemark/html-react-parser/compare/v0.13.0...v0.14.0) (2020-09-11)
|
|
25
|
+
|
|
9
26
|
### Features
|
|
10
27
|
|
|
11
|
-
|
|
12
|
-
|
|
28
|
+
- export attributesToProps ([00fbef2](https://github.com/remarkablemark/html-react-parser/commit/00fbef2))
|
|
29
|
+
- update readme ([76f8b0c](https://github.com/remarkablemark/html-react-parser/commit/76f8b0c))
|
|
30
|
+
|
|
31
|
+
## [0.13.0](https://github.com/remarkablemark/html-react-parser/compare/v0.12.0...v0.13.0) (2020-06-07)
|
|
13
32
|
|
|
33
|
+
### Features
|
|
14
34
|
|
|
35
|
+
- **dom-to-react:** add option `trim` that skips whitespace nodes ([413eaa0](https://github.com/remarkablemark/html-react-parser/commit/413eaa0))
|
|
36
|
+
- **index:** type `trim` in HTMLReactParserOptions ([be71b13](https://github.com/remarkablemark/html-react-parser/commit/be71b13))
|
|
15
37
|
|
|
16
38
|
## [0.12.0](https://github.com/remarkablemark/html-react-parser/compare/v0.11.1...v0.12.0) (2020-06-04)
|
|
17
39
|
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://nodei.co/npm/html-react-parser/)
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/html-react-parser)
|
|
6
|
-
[](https://github.com/remarkablemark/html-react-parser/actions?query=workflow%3Abuild)
|
|
7
7
|
[](https://coveralls.io/github/remarkablemark/html-react-parser?branch=master)
|
|
8
8
|
[](https://david-dm.org/remarkablemark/html-react-parser)
|
|
9
9
|
[](https://www.npmjs.com/package/html-react-parser)
|
|
@@ -17,16 +17,47 @@ HTMLReactParser(string[, options])
|
|
|
17
17
|
|
|
18
18
|
It converts an HTML string to one or more [React elements](https://reactjs.org/docs/react-api.html#creating-react-elements). There's also an option to [replace an element](#replacedomnode) with your own.
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
Example:
|
|
21
21
|
|
|
22
22
|
```js
|
|
23
|
-
|
|
23
|
+
const parse = require('html-react-parser');
|
|
24
24
|
parse('<div>text</div>'); // equivalent to `React.createElement('div', {}, 'text')`
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
[CodeSandbox](https://codesandbox.io/s/940pov1l4w) | [
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
[CodeSandbox](https://codesandbox.io/s/940pov1l4w) | [Repl.it](https://repl.it/@remarkablemark/html-react-parser) | [JSFiddle](https://jsfiddle.net/remarkablemark/7v86d800/) | [Examples](https://github.com/remarkablemark/html-react-parser/tree/master/examples)
|
|
28
|
+
|
|
29
|
+
<details>
|
|
30
|
+
<summary>Table of Contents</summary>
|
|
31
|
+
|
|
32
|
+
- [Install](#install)
|
|
33
|
+
- [Usage](#usage)
|
|
34
|
+
- [Options](#options)
|
|
35
|
+
- [replace(domNode)](#replacedomnode)
|
|
36
|
+
- [library](#library)
|
|
37
|
+
- [htmlparser2](#htmlparser2)
|
|
38
|
+
- [trim](#trim)
|
|
39
|
+
- [FAQ](#faq)
|
|
40
|
+
- [Is this XSS safe?](#is-this-xss-safe)
|
|
41
|
+
- [Does invalid HTML get sanitized?](#does-invalid-html-get-sanitized)
|
|
42
|
+
- [Are `<script>` tags parsed?](#are-script-tags-parsed)
|
|
43
|
+
- [Attributes aren't getting called](#attributes-arent-getting-called)
|
|
44
|
+
- [Parser throws an error](#parser-throws-an-error)
|
|
45
|
+
- [Is SSR supported?](#is-ssr-supported)
|
|
46
|
+
- [Elements aren't nested correctly](#elements-arent-nested-correctly)
|
|
47
|
+
- [Warning: validateDOMNesting(...): Whitespace text nodes cannot appear as a child of table](#warning-validatedomnesting-whitespace-text-nodes-cannot-appear-as-a-child-of-table)
|
|
48
|
+
- [Don't change case of tags](#dont-change-case-of-tags)
|
|
49
|
+
- [Benchmarks](#benchmarks)
|
|
50
|
+
- [Contributors](#contributors)
|
|
51
|
+
- [Code Contributors](#code-contributors)
|
|
52
|
+
- [Financial Contributors](#financial-contributors)
|
|
53
|
+
- [Individuals](#individuals)
|
|
54
|
+
- [Organizations](#organizations)
|
|
55
|
+
- [Support](#support)
|
|
56
|
+
- [License](#license)
|
|
57
|
+
|
|
58
|
+
</details>
|
|
59
|
+
|
|
60
|
+
## Install
|
|
30
61
|
|
|
31
62
|
[NPM](https://www.npmjs.com/package/html-react-parser):
|
|
32
63
|
|
|
@@ -53,7 +84,7 @@ $ yarn add html-react-parser
|
|
|
53
84
|
|
|
54
85
|
## Usage
|
|
55
86
|
|
|
56
|
-
Import the module:
|
|
87
|
+
Import or require the module:
|
|
57
88
|
|
|
58
89
|
```js
|
|
59
90
|
// ES Modules
|
|
@@ -176,13 +207,31 @@ const options = {
|
|
|
176
207
|
console.log(renderToStaticMarkup(parse(html, options)));
|
|
177
208
|
```
|
|
178
209
|
|
|
210
|
+
Use the exported attributesToProps method to convert DOM attributes to React Props:
|
|
211
|
+
|
|
212
|
+
```jsx
|
|
213
|
+
import React from 'react';
|
|
214
|
+
import parse, { attributesToProps } from 'html-react-parser';
|
|
215
|
+
|
|
216
|
+
const html = `
|
|
217
|
+
<hr class="prettify" style="background:#fff;text-align:center" />
|
|
218
|
+
`;
|
|
219
|
+
|
|
220
|
+
const options = {
|
|
221
|
+
replace: node => {
|
|
222
|
+
if (node.attribs && node.name === 'hr') {
|
|
223
|
+
const props = attributesToProps(node.attribs);
|
|
224
|
+
return <hr {...props} />;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
```
|
|
229
|
+
|
|
179
230
|
Output:
|
|
180
231
|
|
|
181
232
|
```html
|
|
182
233
|
<h1 style="font-size:42px">
|
|
183
|
-
<span style="color:hotpink">
|
|
184
|
-
keep me and make me pretty!
|
|
185
|
-
</span>
|
|
234
|
+
<span style="color:hotpink"> keep me and make me pretty! </span>
|
|
186
235
|
</h1>
|
|
187
236
|
```
|
|
188
237
|
|
|
@@ -226,7 +275,7 @@ parse('<br>', {
|
|
|
226
275
|
|
|
227
276
|
### htmlparser2
|
|
228
277
|
|
|
229
|
-
|
|
278
|
+
The default options passed to [htmlparser2](https://github.com/fb55/htmlparser2/tree/v3.10.1) are:
|
|
230
279
|
|
|
231
280
|
```js
|
|
232
281
|
{
|
|
@@ -235,9 +284,9 @@ This library passes the following options to [htmlparser2](https://github.com/fb
|
|
|
235
284
|
}
|
|
236
285
|
```
|
|
237
286
|
|
|
238
|
-
|
|
287
|
+
Since [v0.12.0](https://github.com/remarkablemark/html-react-parser/tree/v0.12.0), you can override the default options by passing [htmlparser2 options](https://github.com/fb55/htmlparser2/wiki/Parser-options).
|
|
239
288
|
|
|
240
|
-
|
|
289
|
+
Here's an example in which [`decodeEntities`](https://github.com/fb55/htmlparser2/wiki/Parser-options#option-decodeentities) and [`xmlMode`](https://github.com/fb55/htmlparser2/wiki/Parser-options#option-xmlmode) are enabled:
|
|
241
290
|
|
|
242
291
|
```js
|
|
243
292
|
parse('<p /><p />', {
|
|
@@ -248,9 +297,7 @@ parse('<p /><p />', {
|
|
|
248
297
|
});
|
|
249
298
|
```
|
|
250
299
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
> **Warning**: By overriding htmlparser2 options, there's a chance of breaking universal rendering. Do this at your own risk.
|
|
300
|
+
> **Warning**: `htmlparser2` is only applicable on the _server-side_ (Node.js) and not applicable on the _client-side_ (browser). By overriding `htmlparser2` options, there's a chance that universal rendering breaks. Do this at your own _risk_.
|
|
254
301
|
|
|
255
302
|
### trim
|
|
256
303
|
|
|
@@ -280,33 +327,33 @@ parse('<p> </p>', { trim: true }); // React.createElement('p')
|
|
|
280
327
|
|
|
281
328
|
## FAQ
|
|
282
329
|
|
|
283
|
-
#### Is this
|
|
330
|
+
#### Is this XSS safe?
|
|
284
331
|
|
|
285
332
|
No, this library is _**not**_ [XSS (cross-site scripting)](https://wikipedia.org/wiki/Cross-site_scripting) safe. See [#94](https://github.com/remarkablemark/html-react-parser/issues/94).
|
|
286
333
|
|
|
287
|
-
#### Does
|
|
334
|
+
#### Does invalid HTML get sanitized?
|
|
288
335
|
|
|
289
|
-
No, this library does _**not**_
|
|
336
|
+
No, this library does _**not**_ sanitize HTML. See [#124](https://github.com/remarkablemark/html-react-parser/issues/124), [#125](https://github.com/remarkablemark/html-react-parser/issues/125), and [#141](https://github.com/remarkablemark/html-react-parser/issues/141).
|
|
290
337
|
|
|
291
338
|
#### Are `<script>` tags parsed?
|
|
292
339
|
|
|
293
340
|
Although `<script>` tags and their contents are rendered on the server-side, they're not evaluated on the client-side. See [#98](https://github.com/remarkablemark/html-react-parser/issues/98).
|
|
294
341
|
|
|
295
|
-
####
|
|
342
|
+
#### Attributes aren't getting called
|
|
296
343
|
|
|
297
|
-
|
|
344
|
+
The reason why your HTML attributes aren't getting called is because [inline event handlers](https://developer.mozilla.org/docs/Web/Guide/Events/Event_handlers) (e.g., `onclick`) are parsed as a _string_ rather than a _function_. See [#73](https://github.com/remarkablemark/html-react-parser/issues/73).
|
|
298
345
|
|
|
299
|
-
####
|
|
346
|
+
#### Parser throws an error
|
|
300
347
|
|
|
301
|
-
|
|
348
|
+
If the parser throws an erorr, check if your arguments are valid. See ["Does invalid HTML get sanitized?"](#does-invalid-html-get-sanitized).
|
|
302
349
|
|
|
303
|
-
####
|
|
350
|
+
#### Is SSR supported?
|
|
304
351
|
|
|
305
|
-
Yes,
|
|
352
|
+
Yes, server-side rendering on Node.js is supported by this library. See [demo](https://repl.it/@remarkablemark/html-react-parser-SSR).
|
|
306
353
|
|
|
307
|
-
####
|
|
354
|
+
#### Elements aren't nested correctly
|
|
308
355
|
|
|
309
|
-
|
|
356
|
+
If your elements are nested incorrectly, check to make sure your [HTML markup is valid](https://validator.w3.org/). The HTML to DOM parsing will be affected if you're using self-closing syntax (`/>`) on non-void elements:
|
|
310
357
|
|
|
311
358
|
```js
|
|
312
359
|
parse('<div /><div />'); // returns single element instead of array of elements
|
|
@@ -314,13 +361,13 @@ parse('<div /><div />'); // returns single element instead of array of elements
|
|
|
314
361
|
|
|
315
362
|
See [#158](https://github.com/remarkablemark/html-react-parser/issues/158).
|
|
316
363
|
|
|
317
|
-
####
|
|
364
|
+
#### Warning: validateDOMNesting(...): Whitespace text nodes cannot appear as a child of table
|
|
318
365
|
|
|
319
|
-
Enable the [trim](
|
|
366
|
+
Enable the [trim](#trim) option. See [#155](https://github.com/remarkablemark/html-react-parser/issues/155).
|
|
320
367
|
|
|
321
|
-
#### Don't change case of tags
|
|
368
|
+
#### Don't change case of tags
|
|
322
369
|
|
|
323
|
-
Tags are lowercased by default. To prevent that from happening, pass the [htmlparser2 option](
|
|
370
|
+
Tags are lowercased by default. To prevent that from happening, pass the [htmlparser2 option](#htmlparser2):
|
|
324
371
|
|
|
325
372
|
```js
|
|
326
373
|
const options = {
|
|
@@ -387,10 +434,10 @@ Support this project with your organization. Your logo will show up here with a
|
|
|
387
434
|
## Support
|
|
388
435
|
|
|
389
436
|
- [GitHub Sponsors](https://b.remarkabl.org/github-sponsors)
|
|
390
|
-
- [Patreon](https://b.remarkabl.org/patreon)
|
|
391
437
|
- [Open Collective](https://b.remarkabl.org/open-collective-html-react-parser)
|
|
392
|
-
- [Ko-fi](https://b.remarkabl.org/ko-fi)
|
|
393
438
|
- [Tidelift](https://b.remarkabl.org/tidelift-html-react-parser)
|
|
439
|
+
- [Patreon](https://b.remarkabl.org/patreon)
|
|
440
|
+
- [Ko-fi](https://b.remarkabl.org/ko-fi)
|
|
394
441
|
- [Liberapay](https://b.remarkabl.org/liberapay)
|
|
395
442
|
- [Teepsring](https://b.remarkabl.org/teespring)
|
|
396
443
|
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['react'], factory) :
|
|
4
|
-
(global = global || self, global.HTMLReactParser = factory(global.React));
|
|
5
|
-
}(this, (function (
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.HTMLReactParser = factory(global.React));
|
|
5
|
+
}(this, (function (React) { 'use strict';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
8
10
|
|
|
9
11
|
var HTMLDOMPropertyConfig = {
|
|
10
12
|
Properties: {
|
|
@@ -604,6 +606,13 @@
|
|
|
604
606
|
)
|
|
605
607
|
};
|
|
606
608
|
|
|
609
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
610
|
+
|
|
611
|
+
function createCommonjsModule(fn) {
|
|
612
|
+
var module = { exports: {} };
|
|
613
|
+
return fn(module, module.exports), module.exports;
|
|
614
|
+
}
|
|
615
|
+
|
|
607
616
|
// http://www.w3.org/TR/CSS21/grammar.html
|
|
608
617
|
// https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027
|
|
609
618
|
var COMMENT_REGEX = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
|
|
@@ -903,32 +912,59 @@
|
|
|
903
912
|
|
|
904
913
|
var styleToObject = StyleToObject;
|
|
905
914
|
|
|
906
|
-
var
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
915
|
+
var utilities = createCommonjsModule(function (module, exports) {
|
|
916
|
+
exports.__esModule = true;
|
|
917
|
+
exports.camelCase = void 0;
|
|
918
|
+
var CUSTOM_PROPERTY_REGEX = /^--[a-zA-Z0-9-]+$/;
|
|
919
|
+
var HYPHEN_REGEX = /-([a-z])/g;
|
|
920
|
+
var NO_HYPHEN_REGEX = /^[^-]+$/;
|
|
921
|
+
var VENDOR_PREFIX_REGEX = /^-(webkit|moz|ms|o|khtml)-/;
|
|
922
|
+
var skipCamelCase = function (property) {
|
|
923
|
+
return !property ||
|
|
924
|
+
NO_HYPHEN_REGEX.test(property) ||
|
|
925
|
+
CUSTOM_PROPERTY_REGEX.test(property);
|
|
926
|
+
};
|
|
927
|
+
var capitalize = function (match, character) {
|
|
928
|
+
return character.toUpperCase();
|
|
929
|
+
};
|
|
930
|
+
var trimHyphen = function (match, prefix) { return prefix + "-"; };
|
|
931
|
+
var camelCase = function (property, options) {
|
|
932
|
+
if (options === void 0) { options = {}; }
|
|
933
|
+
if (skipCamelCase(property)) {
|
|
934
|
+
return property;
|
|
935
|
+
}
|
|
936
|
+
property = property.toLowerCase();
|
|
937
|
+
if (!options.reactCompat) {
|
|
938
|
+
property = property.replace(VENDOR_PREFIX_REGEX, trimHyphen);
|
|
939
|
+
}
|
|
940
|
+
return property.replace(HYPHEN_REGEX, capitalize);
|
|
941
|
+
};
|
|
942
|
+
exports.camelCase = camelCase;
|
|
943
|
+
});
|
|
919
944
|
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
return
|
|
923
|
-
|
|
945
|
+
var cjs = createCommonjsModule(function (module, exports) {
|
|
946
|
+
var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
947
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
948
|
+
};
|
|
949
|
+
exports.__esModule = true;
|
|
950
|
+
var style_to_object_1 = __importDefault(styleToObject);
|
|
924
951
|
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
952
|
+
function StyleToJS(style, options) {
|
|
953
|
+
var output = {};
|
|
954
|
+
if (!style || typeof style !== 'string') {
|
|
955
|
+
return output;
|
|
956
|
+
}
|
|
957
|
+
style_to_object_1["default"](style, function (property, value) {
|
|
958
|
+
if (property && value) {
|
|
959
|
+
output[utilities.camelCase(property, options)] = value;
|
|
960
|
+
}
|
|
930
961
|
});
|
|
962
|
+
return output;
|
|
931
963
|
}
|
|
964
|
+
exports["default"] = StyleToJS;
|
|
965
|
+
});
|
|
966
|
+
|
|
967
|
+
var styleToJS = cjs.default;
|
|
932
968
|
|
|
933
969
|
/**
|
|
934
970
|
* Swap key with value in an object.
|
|
@@ -1000,20 +1036,35 @@
|
|
|
1000
1036
|
}
|
|
1001
1037
|
}
|
|
1002
1038
|
|
|
1039
|
+
var styleToJSOptions = { reactCompat: true };
|
|
1040
|
+
|
|
1003
1041
|
/**
|
|
1004
|
-
*
|
|
1042
|
+
* Sets style prop.
|
|
1043
|
+
*
|
|
1044
|
+
* @param {null|undefined|string} style
|
|
1045
|
+
* @param {object} props
|
|
1046
|
+
*/
|
|
1047
|
+
function setStyleProp(style, props) {
|
|
1048
|
+
if (style === null || style === undefined) {
|
|
1049
|
+
return;
|
|
1050
|
+
}
|
|
1051
|
+
props.style = styleToJS(style, styleToJSOptions);
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
/**
|
|
1055
|
+
* @constant {boolean}
|
|
1005
1056
|
* @see {@link https://reactjs.org/blog/2017/09/08/dom-attributes-in-react-16.html}
|
|
1006
1057
|
*/
|
|
1007
|
-
var PRESERVE_CUSTOM_ATTRIBUTES =
|
|
1058
|
+
var PRESERVE_CUSTOM_ATTRIBUTES = React__default['default'].version.split('.')[0] >= 16;
|
|
1008
1059
|
|
|
1009
|
-
var utilities = {
|
|
1060
|
+
var utilities$1 = {
|
|
1010
1061
|
PRESERVE_CUSTOM_ATTRIBUTES: PRESERVE_CUSTOM_ATTRIBUTES,
|
|
1011
|
-
camelCase: camelCase,
|
|
1012
1062
|
invertObject: invertObject,
|
|
1013
|
-
isCustomComponent: isCustomComponent
|
|
1063
|
+
isCustomComponent: isCustomComponent,
|
|
1064
|
+
setStyleProp: setStyleProp
|
|
1014
1065
|
};
|
|
1015
1066
|
|
|
1016
|
-
var
|
|
1067
|
+
var setStyleProp$1 = utilities$1.setStyleProp;
|
|
1017
1068
|
|
|
1018
1069
|
var htmlProperties = reactProperty.html;
|
|
1019
1070
|
var svgProperties = reactProperty.svg;
|
|
@@ -1024,8 +1075,8 @@
|
|
|
1024
1075
|
/**
|
|
1025
1076
|
* Converts HTML/SVG DOM attributes to React props.
|
|
1026
1077
|
*
|
|
1027
|
-
* @param {
|
|
1028
|
-
* @return {
|
|
1078
|
+
* @param {object} [attributes={}] - HTML/SVG DOM attributes.
|
|
1079
|
+
* @return {object} - React props.
|
|
1029
1080
|
*/
|
|
1030
1081
|
function attributesToProps(attributes) {
|
|
1031
1082
|
attributes = attributes || {};
|
|
@@ -1065,58 +1116,37 @@
|
|
|
1065
1116
|
}
|
|
1066
1117
|
|
|
1067
1118
|
// preserve custom attribute if React >=16
|
|
1068
|
-
if (utilities.PRESERVE_CUSTOM_ATTRIBUTES) {
|
|
1119
|
+
if (utilities$1.PRESERVE_CUSTOM_ATTRIBUTES) {
|
|
1069
1120
|
props[attributeName] = attributeValue;
|
|
1070
1121
|
}
|
|
1071
1122
|
}
|
|
1072
1123
|
|
|
1073
|
-
//
|
|
1074
|
-
|
|
1075
|
-
props.style = cssToJs(attributes.style);
|
|
1076
|
-
}
|
|
1124
|
+
// transform inline style to object
|
|
1125
|
+
setStyleProp$1(attributes.style, props);
|
|
1077
1126
|
|
|
1078
1127
|
return props;
|
|
1079
1128
|
}
|
|
1080
1129
|
|
|
1081
|
-
/**
|
|
1082
|
-
* Converts inline CSS style to POJO (Plain Old JavaScript Object).
|
|
1083
|
-
*
|
|
1084
|
-
* @param {String} style - The inline CSS style.
|
|
1085
|
-
* @return {Object} - The style object.
|
|
1086
|
-
*/
|
|
1087
|
-
function cssToJs(style) {
|
|
1088
|
-
var styleObject = {};
|
|
1089
|
-
|
|
1090
|
-
if (style) {
|
|
1091
|
-
styleToObject(style, function (property, value) {
|
|
1092
|
-
// skip CSS comment
|
|
1093
|
-
if (property && value) {
|
|
1094
|
-
styleObject[camelCase$1(property)] = value;
|
|
1095
|
-
}
|
|
1096
|
-
});
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
|
-
return styleObject;
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
1130
|
var attributesToProps_1 = attributesToProps;
|
|
1103
1131
|
|
|
1132
|
+
var setStyleProp$2 = utilities$1.setStyleProp;
|
|
1133
|
+
|
|
1104
1134
|
/**
|
|
1105
1135
|
* Converts DOM nodes to React elements.
|
|
1106
1136
|
*
|
|
1107
|
-
* @param
|
|
1108
|
-
* @param
|
|
1109
|
-
* @param
|
|
1110
|
-
* @param
|
|
1111
|
-
* @return {
|
|
1137
|
+
* @param {DomElement[]} nodes - DOM nodes.
|
|
1138
|
+
* @param {object} [options={}] - Options.
|
|
1139
|
+
* @param {Function} [options.replace] - Replacer.
|
|
1140
|
+
* @param {object} [options.library] - Library (React/Preact/etc.).
|
|
1141
|
+
* @return {string|ReactElement|ReactElement[]}
|
|
1112
1142
|
*/
|
|
1113
1143
|
function domToReact(nodes, options) {
|
|
1114
1144
|
options = options || {};
|
|
1115
1145
|
|
|
1116
|
-
var
|
|
1117
|
-
var cloneElement =
|
|
1118
|
-
var createElement =
|
|
1119
|
-
var isValidElement =
|
|
1146
|
+
var library = options.library || React__default['default'];
|
|
1147
|
+
var cloneElement = library.cloneElement;
|
|
1148
|
+
var createElement = library.createElement;
|
|
1149
|
+
var isValidElement = library.isValidElement;
|
|
1120
1150
|
|
|
1121
1151
|
var result = [];
|
|
1122
1152
|
var node;
|
|
@@ -1161,8 +1191,10 @@
|
|
|
1161
1191
|
}
|
|
1162
1192
|
|
|
1163
1193
|
props = node.attribs;
|
|
1164
|
-
if (
|
|
1165
|
-
props
|
|
1194
|
+
if (skipAttributesToProps(node)) {
|
|
1195
|
+
setStyleProp$2(props.style, props);
|
|
1196
|
+
} else if (props) {
|
|
1197
|
+
props = attributesToProps_1(props);
|
|
1166
1198
|
}
|
|
1167
1199
|
|
|
1168
1200
|
children = null;
|
|
@@ -1208,16 +1240,17 @@
|
|
|
1208
1240
|
}
|
|
1209
1241
|
|
|
1210
1242
|
/**
|
|
1211
|
-
* Determines whether attributes should be
|
|
1243
|
+
* Determines whether DOM element attributes should be transformed to props.
|
|
1244
|
+
* Web Components should not have their attributes transformed except for `style`.
|
|
1212
1245
|
*
|
|
1213
|
-
* @param
|
|
1214
|
-
* @return {
|
|
1246
|
+
* @param {DomElement} node
|
|
1247
|
+
* @return {boolean}
|
|
1215
1248
|
*/
|
|
1216
|
-
function
|
|
1249
|
+
function skipAttributesToProps(node) {
|
|
1217
1250
|
return (
|
|
1218
|
-
utilities.PRESERVE_CUSTOM_ATTRIBUTES &&
|
|
1251
|
+
utilities$1.PRESERVE_CUSTOM_ATTRIBUTES &&
|
|
1219
1252
|
node.type === 'tag' &&
|
|
1220
|
-
utilities.isCustomComponent(node.name, node.attribs)
|
|
1253
|
+
utilities$1.isCustomComponent(node.name, node.attribs)
|
|
1221
1254
|
);
|
|
1222
1255
|
}
|
|
1223
1256
|
|
|
@@ -1421,7 +1454,7 @@
|
|
|
1421
1454
|
return /(MSIE |Trident\/|Edge\/)/.test(navigator.userAgent);
|
|
1422
1455
|
}
|
|
1423
1456
|
|
|
1424
|
-
var utilities$
|
|
1457
|
+
var utilities$2 = {
|
|
1425
1458
|
formatAttributes: formatAttributes,
|
|
1426
1459
|
formatDOM: formatDOM,
|
|
1427
1460
|
isIE: isIE
|
|
@@ -1438,8 +1471,8 @@
|
|
|
1438
1471
|
var VOID_ELEMENTS_REGEX = /<(area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)(.*?)\/?>/gi;
|
|
1439
1472
|
|
|
1440
1473
|
// detect IE browser
|
|
1441
|
-
var isIE9 = utilities$
|
|
1442
|
-
var isIE$1 = isIE9 || utilities$
|
|
1474
|
+
var isIE9 = utilities$2.isIE(9);
|
|
1475
|
+
var isIE$1 = isIE9 || utilities$2.isIE();
|
|
1443
1476
|
|
|
1444
1477
|
// falls back to `parseFromString` if `createHTMLDocument` cannot be used
|
|
1445
1478
|
var parseFromDocument = function () {
|
|
@@ -1610,8 +1643,8 @@
|
|
|
1610
1643
|
|
|
1611
1644
|
var domparser_1 = domparser;
|
|
1612
1645
|
|
|
1613
|
-
var formatDOM$1 = utilities$
|
|
1614
|
-
var isIE9$1 = utilities$
|
|
1646
|
+
var formatDOM$1 = utilities$2.formatDOM;
|
|
1647
|
+
var isIE9$1 = utilities$2.isIE(9);
|
|
1615
1648
|
|
|
1616
1649
|
var DIRECTIVE_REGEX = /<(![a-zA-Z\s]+)>/; // e.g., <!doctype html>
|
|
1617
1650
|
|
|
@@ -1678,6 +1711,7 @@
|
|
|
1678
1711
|
|
|
1679
1712
|
HTMLReactParser.domToReact = domToReact_1;
|
|
1680
1713
|
HTMLReactParser.htmlToDOM = htmlToDomClient;
|
|
1714
|
+
HTMLReactParser.attributesToProps = attributesToProps_1;
|
|
1681
1715
|
|
|
1682
1716
|
// support CommonJS and ES Modules
|
|
1683
1717
|
var htmlReactParser = HTMLReactParser;
|