@ecency/render-helper 2.4.4 → 2.4.5
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 +4 -1
- package/dist/browser/index.js +19 -7
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +19 -7
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +19 -7
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.cjs
CHANGED
|
@@ -66,7 +66,7 @@ var SECTION_LIST = [
|
|
|
66
66
|
];
|
|
67
67
|
|
|
68
68
|
// src/consts/regexes.const.ts
|
|
69
|
-
var IMG_REGEX = /(https?:\/\/.*\.(?:tiff?|jpe?g|gif|png|svg|ico|heic|webp))(.*)/gim;
|
|
69
|
+
var IMG_REGEX = /(https?:\/\/.*\.(?:tiff?|jpe?g|gif|png|svg|ico|heic|webp|arw))(.*)/gim;
|
|
70
70
|
var IPFS_REGEX = /^https?:\/\/[^/]+\/(ip[fn]s)\/([^/?#]+)/gim;
|
|
71
71
|
var POST_REGEX = /^https?:\/\/(.*)\/(.*)\/(@[\w.\d-]+)\/(.*)/i;
|
|
72
72
|
var CCC_REGEX = /^https?:\/\/(.*)\/ccc\/([\w.\d-]+)\/(.*)/i;
|
|
@@ -194,7 +194,7 @@ function createDoc(html) {
|
|
|
194
194
|
if (html.trim() === "") {
|
|
195
195
|
return null;
|
|
196
196
|
}
|
|
197
|
-
const doc = DOMParser.parseFromString(html
|
|
197
|
+
const doc = DOMParser.parseFromString(`<body>${html}</body>`, "text/html");
|
|
198
198
|
return doc;
|
|
199
199
|
}
|
|
200
200
|
function makeEntryCacheKey(entry) {
|
|
@@ -868,7 +868,7 @@ function a(el, forApp, webp, parentDomain = "ecency.com") {
|
|
|
868
868
|
const imgEls2 = el.getElementsByTagName("img");
|
|
869
869
|
if (imgEls2.length === 1 || el.textContent.trim() === href) {
|
|
870
870
|
if ((match[1] || match[2]) && match[3]) {
|
|
871
|
-
const videoHref = `https://
|
|
871
|
+
const videoHref = `https://3speak.tv/embed?v=${match[3]}`;
|
|
872
872
|
el.setAttribute("class", "markdown-video-link markdown-video-link-speak");
|
|
873
873
|
el.removeAttribute("href");
|
|
874
874
|
el.setAttribute("data-embed-src", videoHref);
|
|
@@ -1001,10 +1001,7 @@ function iframe(el, parentDomain = "ecency.com") {
|
|
|
1001
1001
|
return;
|
|
1002
1002
|
}
|
|
1003
1003
|
if (src.match(SPEAK_EMBED_REGEX)) {
|
|
1004
|
-
let normalizedSrc = src.replace(/3speak\.[a-z]+/i, "
|
|
1005
|
-
if (!/[?&]mode=iframe/.test(normalizedSrc)) {
|
|
1006
|
-
normalizedSrc = `${normalizedSrc}${normalizedSrc.includes("?") ? "&" : "?"}mode=iframe`;
|
|
1007
|
-
}
|
|
1004
|
+
let normalizedSrc = src.replace(/3speak\.[a-z]+/i, "3speak.tv");
|
|
1008
1005
|
const hasAutoplay = /[?&]autoplay=/.test(normalizedSrc);
|
|
1009
1006
|
const s = hasAutoplay ? normalizedSrc : `${normalizedSrc}&autoplay=true`;
|
|
1010
1007
|
el.setAttribute("src", s);
|
|
@@ -1289,6 +1286,20 @@ function getLolightInstance() {
|
|
|
1289
1286
|
}
|
|
1290
1287
|
return lolight;
|
|
1291
1288
|
}
|
|
1289
|
+
function fixBlockLevelTagsInParagraphs(html) {
|
|
1290
|
+
const blockTags = "center|div|table|figure|section|article|aside|header|footer|nav|main";
|
|
1291
|
+
const openingPattern = new RegExp(`<p>(<(?:${blockTags})(?:\\s[^>]*)?>)<\\/p>`, "gi");
|
|
1292
|
+
html = html.replace(openingPattern, "$1");
|
|
1293
|
+
const closingPattern = new RegExp(`<p>(<\\/(?:${blockTags})>)<\\/p>`, "gi");
|
|
1294
|
+
html = html.replace(closingPattern, "$1");
|
|
1295
|
+
const startPattern = new RegExp(`<p>(<(?:${blockTags})(?:\\s[^>]*)?>)(?:<br>)?\\s*`, "gi");
|
|
1296
|
+
html = html.replace(startPattern, "$1<p>");
|
|
1297
|
+
const endPattern = new RegExp(`\\s*(?:<br>)?\\s*(<\\/(?:${blockTags})>)<\\/p>`, "gi");
|
|
1298
|
+
html = html.replace(endPattern, "</p>$1");
|
|
1299
|
+
html = html.replace(/<p>\s*<\/p>/g, "");
|
|
1300
|
+
html = html.replace(/<p><br>\s*<\/p>/g, "");
|
|
1301
|
+
return html;
|
|
1302
|
+
}
|
|
1292
1303
|
function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
|
|
1293
1304
|
input = input.replace(new RegExp("https://leofinance.io/threads/view/", "g"), "/@");
|
|
1294
1305
|
input = input.replace(new RegExp("https://leofinance.io/posts/", "g"), "/@");
|
|
@@ -1347,6 +1358,7 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
|
|
|
1347
1358
|
}
|
|
1348
1359
|
try {
|
|
1349
1360
|
output = md.render(input);
|
|
1361
|
+
output = fixBlockLevelTagsInParagraphs(output);
|
|
1350
1362
|
const doc = DOMParser.parseFromString(`<body id="root">${output}</body>`, "text/html");
|
|
1351
1363
|
traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain);
|
|
1352
1364
|
output = serializer.serializeToString(doc);
|