@ecency/render-helper 2.4.18 → 2.4.20

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.
@@ -1288,9 +1288,10 @@ function traverse(node, forApp, depth = 0, state = { firstImageFound: false }, p
1288
1288
  if (!node || !node.childNodes) {
1289
1289
  return;
1290
1290
  }
1291
- Array.from(Array(node.childNodes.length).keys()).forEach((i) => {
1292
- const child = node.childNodes[i];
1293
- if (!child) return;
1291
+ let child = node.firstChild;
1292
+ while (child) {
1293
+ const next = child.nextSibling;
1294
+ const prev = child.previousSibling;
1294
1295
  if (child.nodeName.toLowerCase() === "a") {
1295
1296
  a(child, forApp, parentDomain, seoContext);
1296
1297
  }
@@ -1306,11 +1307,16 @@ function traverse(node, forApp, depth = 0, state = { firstImageFound: false }, p
1306
1307
  if (child.nodeName.toLowerCase() === "p") {
1307
1308
  p(child);
1308
1309
  }
1309
- const currentChild = node.childNodes[i];
1310
- if (currentChild) {
1311
- traverse(currentChild, forApp, depth + 1, state, parentDomain, seoContext);
1310
+ if (child.parentNode) {
1311
+ traverse(child, forApp, depth + 1, state, parentDomain, seoContext);
1312
+ } else {
1313
+ const possibleReplacement = next ? next.previousSibling : node.lastChild;
1314
+ if (possibleReplacement && possibleReplacement !== prev && possibleReplacement.parentNode === node) {
1315
+ traverse(possibleReplacement, forApp, depth + 1, state, parentDomain, seoContext);
1316
+ }
1312
1317
  }
1313
- });
1318
+ child = next;
1319
+ }
1314
1320
  }
1315
1321
 
1316
1322
  // src/methods/clean-reply.method.ts