@ecency/render-helper 2.4.25 → 2.4.27
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/dist/browser/index.d.ts +8 -2
- package/dist/browser/index.js +82 -40
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +82 -40
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +82 -40
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.cjs
CHANGED
|
@@ -462,7 +462,7 @@ var addLineBreakBeforePostLink = (el, forApp, isInline) => {
|
|
|
462
462
|
el.parentNode.insertBefore(br, el);
|
|
463
463
|
}
|
|
464
464
|
};
|
|
465
|
-
function a(el, forApp, parentDomain = "ecency.com", seoContext) {
|
|
465
|
+
function a(el, forApp, parentDomain = "ecency.com", seoContext, renderOptions) {
|
|
466
466
|
if (!el || !el.parentNode) {
|
|
467
467
|
return;
|
|
468
468
|
}
|
|
@@ -471,7 +471,7 @@ function a(el, forApp, parentDomain = "ecency.com", seoContext) {
|
|
|
471
471
|
return;
|
|
472
472
|
}
|
|
473
473
|
const className = el.getAttribute("class");
|
|
474
|
-
if (["markdown-author-link", "markdown-tag-link"].
|
|
474
|
+
if (className && (["markdown-author-link", "markdown-tag-link"].includes(className) || className.includes("er-author") || className.includes("er-tag"))) {
|
|
475
475
|
return;
|
|
476
476
|
}
|
|
477
477
|
if (href && href.trim().toLowerCase().startsWith("javascript:")) {
|
|
@@ -811,14 +811,29 @@ function a(el, forApp, parentDomain = "ecency.com", seoContext) {
|
|
|
811
811
|
if (startTime) {
|
|
812
812
|
el.setAttribute("data-start-time", startTime);
|
|
813
813
|
}
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
814
|
+
if (renderOptions?.embedVideosDirectly) {
|
|
815
|
+
const wrapper = el.ownerDocument.createElement("span");
|
|
816
|
+
wrapper.setAttribute("class", "er-youtube-frame");
|
|
817
|
+
wrapper.setAttribute("style", "display:block");
|
|
818
|
+
const iframe2 = el.ownerDocument.createElement("iframe");
|
|
819
|
+
iframe2.setAttribute("class", "youtube-player");
|
|
820
|
+
iframe2.setAttribute("src", embedSrc);
|
|
821
|
+
iframe2.setAttribute("title", "YouTube video");
|
|
822
|
+
iframe2.setAttribute("allow", "accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture; web-share");
|
|
823
|
+
iframe2.setAttribute("allowfullscreen", "");
|
|
824
|
+
wrapper.appendChild(iframe2);
|
|
825
|
+
el.appendChild(wrapper);
|
|
826
|
+
el.setAttribute("class", "markdown-video-link markdown-video-link-youtube er-youtube");
|
|
827
|
+
} else {
|
|
828
|
+
const thumbImg = el.ownerDocument.createElement("img");
|
|
829
|
+
thumbImg.setAttribute("class", "no-replace video-thumbnail");
|
|
830
|
+
thumbImg.setAttribute("itemprop", "thumbnailUrl");
|
|
831
|
+
thumbImg.setAttribute("src", thumbnail);
|
|
832
|
+
const play = el.ownerDocument.createElement("span");
|
|
833
|
+
play.setAttribute("class", "markdown-video-play");
|
|
834
|
+
el.appendChild(thumbImg);
|
|
835
|
+
el.appendChild(play);
|
|
836
|
+
}
|
|
822
837
|
return;
|
|
823
838
|
}
|
|
824
839
|
match = href.match(VIMEO_REGEX);
|
|
@@ -940,21 +955,36 @@ function a(el, forApp, parentDomain = "ecency.com", seoContext) {
|
|
|
940
955
|
if (el.textContent.trim() === href) {
|
|
941
956
|
el.textContent = "";
|
|
942
957
|
}
|
|
943
|
-
if (
|
|
944
|
-
const
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
958
|
+
if (renderOptions?.embedVideosDirectly) {
|
|
959
|
+
const wrapper = el.ownerDocument.createElement("span");
|
|
960
|
+
wrapper.setAttribute("class", "er-speak-frame");
|
|
961
|
+
wrapper.setAttribute("style", "display:block");
|
|
962
|
+
const iframe2 = el.ownerDocument.createElement("iframe");
|
|
963
|
+
iframe2.setAttribute("class", "speak-iframe");
|
|
964
|
+
iframe2.setAttribute("src", videoHref);
|
|
965
|
+
iframe2.setAttribute("title", "3Speak video");
|
|
966
|
+
iframe2.setAttribute("allow", "accelerometer; encrypted-media; gyroscope; picture-in-picture; web-share");
|
|
967
|
+
iframe2.setAttribute("allowfullscreen", "");
|
|
968
|
+
wrapper.appendChild(iframe2);
|
|
969
|
+
el.appendChild(wrapper);
|
|
970
|
+
el.setAttribute("class", "markdown-video-link markdown-video-link-speak er-speak");
|
|
971
|
+
} else {
|
|
972
|
+
if (imgEls2.length === 1) {
|
|
973
|
+
const src = imgEls2[0].getAttribute("src");
|
|
974
|
+
if (src) {
|
|
975
|
+
const thumbnail = proxifyImageSrc(src.replace(/\s+/g, ""), 0, 0, "match");
|
|
976
|
+
const thumbImg = el.ownerDocument.createElement("img");
|
|
977
|
+
thumbImg.setAttribute("class", "no-replace video-thumbnail");
|
|
978
|
+
thumbImg.setAttribute("itemprop", "thumbnailUrl");
|
|
979
|
+
thumbImg.setAttribute("src", thumbnail);
|
|
980
|
+
el.appendChild(thumbImg);
|
|
981
|
+
el.removeChild(imgEls2[0]);
|
|
982
|
+
}
|
|
953
983
|
}
|
|
984
|
+
const play = el.ownerDocument.createElement("span");
|
|
985
|
+
play.setAttribute("class", "markdown-video-play");
|
|
986
|
+
el.appendChild(play);
|
|
954
987
|
}
|
|
955
|
-
const play = el.ownerDocument.createElement("span");
|
|
956
|
-
play.setAttribute("class", "markdown-video-play");
|
|
957
|
-
el.appendChild(play);
|
|
958
988
|
return;
|
|
959
989
|
}
|
|
960
990
|
}
|
|
@@ -1216,24 +1246,33 @@ function p(el) {
|
|
|
1216
1246
|
}
|
|
1217
1247
|
|
|
1218
1248
|
// src/methods/linkify.method.ts
|
|
1219
|
-
function linkify(content, forApp) {
|
|
1249
|
+
function linkify(content, forApp, renderOptions) {
|
|
1220
1250
|
content = content.replace(/(^|\s|>)(#[-a-z\d]+)/gi, (tag) => {
|
|
1221
1251
|
if (/#[\d]+$/.test(tag)) return tag;
|
|
1222
1252
|
const preceding = /^\s|>/.test(tag) ? tag[0] : "";
|
|
1223
1253
|
tag = tag.replace(">", "");
|
|
1224
1254
|
const tag2 = tag.trim().substring(1);
|
|
1225
1255
|
const tagLower = tag2.toLowerCase();
|
|
1226
|
-
|
|
1227
|
-
|
|
1256
|
+
if (!forApp) {
|
|
1257
|
+
return `${preceding}<a class="er-tag er-tag-link" href="/trending/${tagLower}">${tag.trim()}</a>`;
|
|
1258
|
+
}
|
|
1259
|
+
return `${preceding}<a class="markdown-tag-link" data-tag="${tagLower}">${tag.trim()}</a>`;
|
|
1228
1260
|
});
|
|
1261
|
+
const authorPlaceholders = [];
|
|
1229
1262
|
content = content.replace(
|
|
1230
1263
|
/(^|[^a-zA-Z0-9_!#$%&*@@/]|(^|[^a-zA-Z0-9_+~.-/]))[@@]([a-z][-.a-z\d^/]+[a-z\d])/gi,
|
|
1231
1264
|
(match, preceeding1, preceeding2, user) => {
|
|
1232
1265
|
const userLower = user.toLowerCase();
|
|
1233
1266
|
const preceedings = (preceeding1 || "") + (preceeding2 || "");
|
|
1234
1267
|
if (userLower.indexOf("/") === -1 && isValidUsername(user)) {
|
|
1235
|
-
|
|
1236
|
-
|
|
1268
|
+
if (!forApp) {
|
|
1269
|
+
const avatarSrc = `https://images.ecency.com/u/${userLower}/avatar/small`;
|
|
1270
|
+
const html = `${preceedings}<a class="er-author er-author-link" href="/@${userLower}"><img class="er-author-link-image" src="${avatarSrc}" alt="${userLower}"/><span class="er-author-link-content"><span class="er-author-link-label">Hive account</span><span>@${userLower}</span></span></a>`;
|
|
1271
|
+
const placeholder = `\u200C${authorPlaceholders.length}\u200C`;
|
|
1272
|
+
authorPlaceholders.push({ placeholder, html });
|
|
1273
|
+
return placeholder;
|
|
1274
|
+
}
|
|
1275
|
+
return `${preceedings}<a class="markdown-author-link" data-author="${userLower}">@${user}</a>`;
|
|
1237
1276
|
} else {
|
|
1238
1277
|
return match;
|
|
1239
1278
|
}
|
|
@@ -1276,6 +1315,9 @@ function linkify(content, forApp) {
|
|
|
1276
1315
|
firstImageUsed = true;
|
|
1277
1316
|
return createImageHTML(imglink, isLCP);
|
|
1278
1317
|
});
|
|
1318
|
+
authorPlaceholders.forEach(({ placeholder, html }) => {
|
|
1319
|
+
content = content.replace(placeholder, html);
|
|
1320
|
+
});
|
|
1279
1321
|
return content;
|
|
1280
1322
|
}
|
|
1281
1323
|
|
|
@@ -1290,7 +1332,7 @@ function hasAncestor(node, tagNames) {
|
|
|
1290
1332
|
}
|
|
1291
1333
|
return false;
|
|
1292
1334
|
}
|
|
1293
|
-
function text(node, forApp) {
|
|
1335
|
+
function text(node, forApp, renderOptions) {
|
|
1294
1336
|
if (!node || !node.parentNode) {
|
|
1295
1337
|
return;
|
|
1296
1338
|
}
|
|
@@ -1371,7 +1413,7 @@ function text(node, forApp) {
|
|
|
1371
1413
|
}
|
|
1372
1414
|
|
|
1373
1415
|
// src/methods/traverse.method.ts
|
|
1374
|
-
function traverse(node, forApp, depth = 0, state = { firstImageFound: false }, parentDomain = "ecency.com", seoContext) {
|
|
1416
|
+
function traverse(node, forApp, depth = 0, state = { firstImageFound: false }, parentDomain = "ecency.com", seoContext, renderOptions) {
|
|
1375
1417
|
if (!node || !node.childNodes) {
|
|
1376
1418
|
return;
|
|
1377
1419
|
}
|
|
@@ -1380,7 +1422,7 @@ function traverse(node, forApp, depth = 0, state = { firstImageFound: false }, p
|
|
|
1380
1422
|
const next = child.nextSibling;
|
|
1381
1423
|
const prev = child.previousSibling;
|
|
1382
1424
|
if (child.nodeName.toLowerCase() === "a") {
|
|
1383
|
-
a(child, forApp, parentDomain, seoContext);
|
|
1425
|
+
a(child, forApp, parentDomain, seoContext, renderOptions);
|
|
1384
1426
|
}
|
|
1385
1427
|
if (child.nodeName.toLowerCase() === "iframe") {
|
|
1386
1428
|
iframe(child, parentDomain, forApp);
|
|
@@ -1395,11 +1437,11 @@ function traverse(node, forApp, depth = 0, state = { firstImageFound: false }, p
|
|
|
1395
1437
|
p(child);
|
|
1396
1438
|
}
|
|
1397
1439
|
if (child.parentNode) {
|
|
1398
|
-
traverse(child, forApp, depth + 1, state, parentDomain, seoContext);
|
|
1440
|
+
traverse(child, forApp, depth + 1, state, parentDomain, seoContext, renderOptions);
|
|
1399
1441
|
} else {
|
|
1400
1442
|
const possibleReplacement = next ? next.previousSibling : node.lastChild;
|
|
1401
1443
|
if (possibleReplacement && possibleReplacement !== prev && possibleReplacement.parentNode === node) {
|
|
1402
|
-
traverse(possibleReplacement, forApp, depth + 1, state, parentDomain, seoContext);
|
|
1444
|
+
traverse(possibleReplacement, forApp, depth + 1, state, parentDomain, seoContext, renderOptions);
|
|
1403
1445
|
}
|
|
1404
1446
|
}
|
|
1405
1447
|
child = next;
|
|
@@ -1452,7 +1494,7 @@ function fixBlockLevelTagsInParagraphs(html) {
|
|
|
1452
1494
|
html = html.replace(/<p><br>\s*<\/p>/g, "");
|
|
1453
1495
|
return html;
|
|
1454
1496
|
}
|
|
1455
|
-
function markdownToHTML(input, forApp, parentDomain = "ecency.com", seoContext) {
|
|
1497
|
+
function markdownToHTML(input, forApp, parentDomain = "ecency.com", seoContext, renderOptions) {
|
|
1456
1498
|
input = input.replace(new RegExp("https://leofinance.io/threads/view/", "g"), "/@");
|
|
1457
1499
|
input = input.replace(new RegExp("https://leofinance.io/posts/", "g"), "/@");
|
|
1458
1500
|
input = input.replace(new RegExp("https://leofinance.io/threads/", "g"), "/@");
|
|
@@ -1512,7 +1554,7 @@ function markdownToHTML(input, forApp, parentDomain = "ecency.com", seoContext)
|
|
|
1512
1554
|
output = md.render(input);
|
|
1513
1555
|
output = fixBlockLevelTagsInParagraphs(output);
|
|
1514
1556
|
const doc = DOMParser.parseFromString(`<body id="root">${removeDuplicateAttributes(output)}</body>`, "text/html");
|
|
1515
|
-
traverse(doc, forApp, 0, { firstImageFound: false }, parentDomain, seoContext);
|
|
1557
|
+
traverse(doc, forApp, 0, { firstImageFound: false }, parentDomain, seoContext, renderOptions);
|
|
1516
1558
|
output = serializer.serializeToString(doc);
|
|
1517
1559
|
} catch (error) {
|
|
1518
1560
|
try {
|
|
@@ -1525,7 +1567,7 @@ function markdownToHTML(input, forApp, parentDomain = "ecency.com", seoContext)
|
|
|
1525
1567
|
});
|
|
1526
1568
|
const repairedHtml = domSerializer(dom.children);
|
|
1527
1569
|
const doc = DOMParser.parseFromString(`<body id="root">${removeDuplicateAttributes(repairedHtml)}</body>`, "text/html");
|
|
1528
|
-
traverse(doc, forApp, 0, { firstImageFound: false }, parentDomain, seoContext);
|
|
1570
|
+
traverse(doc, forApp, 0, { firstImageFound: false }, parentDomain, seoContext, renderOptions);
|
|
1529
1571
|
output = serializer.serializeToString(doc);
|
|
1530
1572
|
} catch (fallbackError) {
|
|
1531
1573
|
const escapedContent = he2__default.default.encode(output || md.render(input));
|
|
@@ -1553,18 +1595,18 @@ function cacheSet(key, value) {
|
|
|
1553
1595
|
}
|
|
1554
1596
|
|
|
1555
1597
|
// src/markdown-2-html.ts
|
|
1556
|
-
function markdown2Html(obj, forApp = true, _webp = false, parentDomain = "ecency.com", seoContext) {
|
|
1598
|
+
function markdown2Html(obj, forApp = true, _webp = false, parentDomain = "ecency.com", seoContext, renderOptions) {
|
|
1557
1599
|
if (typeof obj === "string") {
|
|
1558
1600
|
const cleanedStr = cleanReply(obj);
|
|
1559
|
-
return markdownToHTML(cleanedStr, forApp, parentDomain, seoContext);
|
|
1601
|
+
return markdownToHTML(cleanedStr, forApp, parentDomain, seoContext, renderOptions);
|
|
1560
1602
|
}
|
|
1561
|
-
const key = `${makeEntryCacheKey(obj)}-md-${forApp ? "app" : "site"}-${parentDomain}${seoContext ? `-seo${seoContext.authorReputation ?? ""}-${seoContext.postPayout ?? ""}` : ""}`;
|
|
1603
|
+
const key = `${makeEntryCacheKey(obj)}-md-${forApp ? "app" : "site"}-${parentDomain}${seoContext ? `-seo${seoContext.authorReputation ?? ""}-${seoContext.postPayout ?? ""}` : ""}${renderOptions?.embedVideosDirectly ? "-embed" : ""}`;
|
|
1562
1604
|
const item = cacheGet(key);
|
|
1563
1605
|
if (item) {
|
|
1564
1606
|
return item;
|
|
1565
1607
|
}
|
|
1566
1608
|
const cleanBody = cleanReply(obj.body);
|
|
1567
|
-
const res = markdownToHTML(cleanBody, forApp, parentDomain, seoContext);
|
|
1609
|
+
const res = markdownToHTML(cleanBody, forApp, parentDomain, seoContext, renderOptions);
|
|
1568
1610
|
cacheSet(key, res);
|
|
1569
1611
|
return res;
|
|
1570
1612
|
}
|