html-react-parser 5.0.11 → 5.1.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 +13 -0
- package/dist/html-react-parser.js +1 -1
- 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/dom-to-react.js +1 -1
- package/lib/dom-to-react.js.map +1 -1
- package/lib/types.d.ts +1 -1
- package/lib/types.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/dom-to-react.ts +1 -1
- package/src/types.ts +1 -0
package/README.md
CHANGED
|
@@ -196,6 +196,19 @@ parse('<p id="replace">text</p>', {
|
|
|
196
196
|
});
|
|
197
197
|
```
|
|
198
198
|
|
|
199
|
+
The second argument is the index:
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
parse('<br>', {
|
|
203
|
+
replace(domNode, index) {
|
|
204
|
+
console.assert(typeof index === 'number');
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
> [!NOTE]
|
|
210
|
+
> The index will restart at 0 when traversing the node's children so don't rely on index being a unique key.
|
|
211
|
+
|
|
199
212
|
#### replace with TypeScript
|
|
200
213
|
|
|
201
214
|
For TypeScript, you'll need to check that `domNode` is an instance of domhandler's `Element`:
|
|
@@ -2666,7 +2666,7 @@
|
|
|
2666
2666
|
var node = nodes[index];
|
|
2667
2667
|
// replace with custom React element (if present)
|
|
2668
2668
|
if (hasReplace) {
|
|
2669
|
-
var replaceElement = options.replace(node);
|
|
2669
|
+
var replaceElement = options.replace(node, index);
|
|
2670
2670
|
if (isValidElement(replaceElement)) {
|
|
2671
2671
|
// set "key" prop for sibling elements
|
|
2672
2672
|
// https://react.dev/learn/rendering-lists#rules-of-keys
|