@ecency/render-helper 2.4.25 → 2.4.26
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 +75 -40
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +75 -40
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +75 -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,15 +1246,17 @@ 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
|
});
|
|
1229
1261
|
content = content.replace(
|
|
1230
1262
|
/(^|[^a-zA-Z0-9_!#$%&*@@/]|(^|[^a-zA-Z0-9_+~.-/]))[@@]([a-z][-.a-z\d^/]+[a-z\d])/gi,
|
|
@@ -1232,8 +1264,11 @@ function linkify(content, forApp) {
|
|
|
1232
1264
|
const userLower = user.toLowerCase();
|
|
1233
1265
|
const preceedings = (preceeding1 || "") + (preceeding2 || "");
|
|
1234
1266
|
if (userLower.indexOf("/") === -1 && isValidUsername(user)) {
|
|
1235
|
-
|
|
1236
|
-
|
|
1267
|
+
if (!forApp) {
|
|
1268
|
+
const avatarSrc = `https://images.ecency.com/u/${userLower}/avatar/small`;
|
|
1269
|
+
return `${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>`;
|
|
1270
|
+
}
|
|
1271
|
+
return `${preceedings}<a class="markdown-author-link" data-author="${userLower}">@${user}</a>`;
|
|
1237
1272
|
} else {
|
|
1238
1273
|
return match;
|
|
1239
1274
|
}
|
|
@@ -1290,7 +1325,7 @@ function hasAncestor(node, tagNames) {
|
|
|
1290
1325
|
}
|
|
1291
1326
|
return false;
|
|
1292
1327
|
}
|
|
1293
|
-
function text(node, forApp) {
|
|
1328
|
+
function text(node, forApp, renderOptions) {
|
|
1294
1329
|
if (!node || !node.parentNode) {
|
|
1295
1330
|
return;
|
|
1296
1331
|
}
|
|
@@ -1371,7 +1406,7 @@ function text(node, forApp) {
|
|
|
1371
1406
|
}
|
|
1372
1407
|
|
|
1373
1408
|
// src/methods/traverse.method.ts
|
|
1374
|
-
function traverse(node, forApp, depth = 0, state = { firstImageFound: false }, parentDomain = "ecency.com", seoContext) {
|
|
1409
|
+
function traverse(node, forApp, depth = 0, state = { firstImageFound: false }, parentDomain = "ecency.com", seoContext, renderOptions) {
|
|
1375
1410
|
if (!node || !node.childNodes) {
|
|
1376
1411
|
return;
|
|
1377
1412
|
}
|
|
@@ -1380,7 +1415,7 @@ function traverse(node, forApp, depth = 0, state = { firstImageFound: false }, p
|
|
|
1380
1415
|
const next = child.nextSibling;
|
|
1381
1416
|
const prev = child.previousSibling;
|
|
1382
1417
|
if (child.nodeName.toLowerCase() === "a") {
|
|
1383
|
-
a(child, forApp, parentDomain, seoContext);
|
|
1418
|
+
a(child, forApp, parentDomain, seoContext, renderOptions);
|
|
1384
1419
|
}
|
|
1385
1420
|
if (child.nodeName.toLowerCase() === "iframe") {
|
|
1386
1421
|
iframe(child, parentDomain, forApp);
|
|
@@ -1395,11 +1430,11 @@ function traverse(node, forApp, depth = 0, state = { firstImageFound: false }, p
|
|
|
1395
1430
|
p(child);
|
|
1396
1431
|
}
|
|
1397
1432
|
if (child.parentNode) {
|
|
1398
|
-
traverse(child, forApp, depth + 1, state, parentDomain, seoContext);
|
|
1433
|
+
traverse(child, forApp, depth + 1, state, parentDomain, seoContext, renderOptions);
|
|
1399
1434
|
} else {
|
|
1400
1435
|
const possibleReplacement = next ? next.previousSibling : node.lastChild;
|
|
1401
1436
|
if (possibleReplacement && possibleReplacement !== prev && possibleReplacement.parentNode === node) {
|
|
1402
|
-
traverse(possibleReplacement, forApp, depth + 1, state, parentDomain, seoContext);
|
|
1437
|
+
traverse(possibleReplacement, forApp, depth + 1, state, parentDomain, seoContext, renderOptions);
|
|
1403
1438
|
}
|
|
1404
1439
|
}
|
|
1405
1440
|
child = next;
|
|
@@ -1452,7 +1487,7 @@ function fixBlockLevelTagsInParagraphs(html) {
|
|
|
1452
1487
|
html = html.replace(/<p><br>\s*<\/p>/g, "");
|
|
1453
1488
|
return html;
|
|
1454
1489
|
}
|
|
1455
|
-
function markdownToHTML(input, forApp, parentDomain = "ecency.com", seoContext) {
|
|
1490
|
+
function markdownToHTML(input, forApp, parentDomain = "ecency.com", seoContext, renderOptions) {
|
|
1456
1491
|
input = input.replace(new RegExp("https://leofinance.io/threads/view/", "g"), "/@");
|
|
1457
1492
|
input = input.replace(new RegExp("https://leofinance.io/posts/", "g"), "/@");
|
|
1458
1493
|
input = input.replace(new RegExp("https://leofinance.io/threads/", "g"), "/@");
|
|
@@ -1512,7 +1547,7 @@ function markdownToHTML(input, forApp, parentDomain = "ecency.com", seoContext)
|
|
|
1512
1547
|
output = md.render(input);
|
|
1513
1548
|
output = fixBlockLevelTagsInParagraphs(output);
|
|
1514
1549
|
const doc = DOMParser.parseFromString(`<body id="root">${removeDuplicateAttributes(output)}</body>`, "text/html");
|
|
1515
|
-
traverse(doc, forApp, 0, { firstImageFound: false }, parentDomain, seoContext);
|
|
1550
|
+
traverse(doc, forApp, 0, { firstImageFound: false }, parentDomain, seoContext, renderOptions);
|
|
1516
1551
|
output = serializer.serializeToString(doc);
|
|
1517
1552
|
} catch (error) {
|
|
1518
1553
|
try {
|
|
@@ -1525,7 +1560,7 @@ function markdownToHTML(input, forApp, parentDomain = "ecency.com", seoContext)
|
|
|
1525
1560
|
});
|
|
1526
1561
|
const repairedHtml = domSerializer(dom.children);
|
|
1527
1562
|
const doc = DOMParser.parseFromString(`<body id="root">${removeDuplicateAttributes(repairedHtml)}</body>`, "text/html");
|
|
1528
|
-
traverse(doc, forApp, 0, { firstImageFound: false }, parentDomain, seoContext);
|
|
1563
|
+
traverse(doc, forApp, 0, { firstImageFound: false }, parentDomain, seoContext, renderOptions);
|
|
1529
1564
|
output = serializer.serializeToString(doc);
|
|
1530
1565
|
} catch (fallbackError) {
|
|
1531
1566
|
const escapedContent = he2__default.default.encode(output || md.render(input));
|
|
@@ -1553,18 +1588,18 @@ function cacheSet(key, value) {
|
|
|
1553
1588
|
}
|
|
1554
1589
|
|
|
1555
1590
|
// src/markdown-2-html.ts
|
|
1556
|
-
function markdown2Html(obj, forApp = true, _webp = false, parentDomain = "ecency.com", seoContext) {
|
|
1591
|
+
function markdown2Html(obj, forApp = true, _webp = false, parentDomain = "ecency.com", seoContext, renderOptions) {
|
|
1557
1592
|
if (typeof obj === "string") {
|
|
1558
1593
|
const cleanedStr = cleanReply(obj);
|
|
1559
|
-
return markdownToHTML(cleanedStr, forApp, parentDomain, seoContext);
|
|
1594
|
+
return markdownToHTML(cleanedStr, forApp, parentDomain, seoContext, renderOptions);
|
|
1560
1595
|
}
|
|
1561
|
-
const key = `${makeEntryCacheKey(obj)}-md-${forApp ? "app" : "site"}-${parentDomain}${seoContext ? `-seo${seoContext.authorReputation ?? ""}-${seoContext.postPayout ?? ""}` : ""}`;
|
|
1596
|
+
const key = `${makeEntryCacheKey(obj)}-md-${forApp ? "app" : "site"}-${parentDomain}${seoContext ? `-seo${seoContext.authorReputation ?? ""}-${seoContext.postPayout ?? ""}` : ""}${renderOptions?.embedVideosDirectly ? "-embed" : ""}`;
|
|
1562
1597
|
const item = cacheGet(key);
|
|
1563
1598
|
if (item) {
|
|
1564
1599
|
return item;
|
|
1565
1600
|
}
|
|
1566
1601
|
const cleanBody = cleanReply(obj.body);
|
|
1567
|
-
const res = markdownToHTML(cleanBody, forApp, parentDomain, seoContext);
|
|
1602
|
+
const res = markdownToHTML(cleanBody, forApp, parentDomain, seoContext, renderOptions);
|
|
1568
1603
|
cacheSet(key, res);
|
|
1569
1604
|
return res;
|
|
1570
1605
|
}
|