@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/browser/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entry interface for Hive post data
|
|
3
|
+
*/
|
|
1
4
|
interface Entry {
|
|
2
5
|
author?: string;
|
|
3
6
|
permlink?: string;
|
|
@@ -29,4 +32,4 @@ declare const SECTION_LIST: string[];
|
|
|
29
32
|
|
|
30
33
|
declare function isValidPermlink(permlink: string): boolean;
|
|
31
34
|
|
|
32
|
-
export { SECTION_LIST, catchPostImage, isValidPermlink, getPostBodySummary as postBodySummary, proxifyImageSrc, markdown2Html as renderPostBody, setCacheSize, setProxyBase };
|
|
35
|
+
export { type Entry, SECTION_LIST, catchPostImage, isValidPermlink, getPostBodySummary as postBodySummary, proxifyImageSrc, markdown2Html as renderPostBody, setCacheSize, setProxyBase };
|
package/dist/browser/index.js
CHANGED
|
@@ -57,7 +57,7 @@ var SECTION_LIST = [
|
|
|
57
57
|
];
|
|
58
58
|
|
|
59
59
|
// src/consts/regexes.const.ts
|
|
60
|
-
var IMG_REGEX = /(https?:\/\/.*\.(?:tiff?|jpe?g|gif|png|svg|ico|heic|webp))(.*)/gim;
|
|
60
|
+
var IMG_REGEX = /(https?:\/\/.*\.(?:tiff?|jpe?g|gif|png|svg|ico|heic|webp|arw))(.*)/gim;
|
|
61
61
|
var IPFS_REGEX = /^https?:\/\/[^/]+\/(ip[fn]s)\/([^/?#]+)/gim;
|
|
62
62
|
var POST_REGEX = /^https?:\/\/(.*)\/(.*)\/(@[\w.\d-]+)\/(.*)/i;
|
|
63
63
|
var CCC_REGEX = /^https?:\/\/(.*)\/ccc\/([\w.\d-]+)\/(.*)/i;
|
|
@@ -182,7 +182,7 @@ function createDoc(html) {
|
|
|
182
182
|
if (html.trim() === "") {
|
|
183
183
|
return null;
|
|
184
184
|
}
|
|
185
|
-
const doc = DOMParser.parseFromString(html
|
|
185
|
+
const doc = DOMParser.parseFromString(`<body>${html}</body>`, "text/html");
|
|
186
186
|
return doc;
|
|
187
187
|
}
|
|
188
188
|
function makeEntryCacheKey(entry) {
|
|
@@ -856,7 +856,7 @@ function a(el, forApp, webp, parentDomain = "ecency.com") {
|
|
|
856
856
|
const imgEls2 = el.getElementsByTagName("img");
|
|
857
857
|
if (imgEls2.length === 1 || el.textContent.trim() === href) {
|
|
858
858
|
if ((match[1] || match[2]) && match[3]) {
|
|
859
|
-
const videoHref = `https://
|
|
859
|
+
const videoHref = `https://3speak.tv/embed?v=${match[3]}`;
|
|
860
860
|
el.setAttribute("class", "markdown-video-link markdown-video-link-speak");
|
|
861
861
|
el.removeAttribute("href");
|
|
862
862
|
el.setAttribute("data-embed-src", videoHref);
|
|
@@ -989,10 +989,7 @@ function iframe(el, parentDomain = "ecency.com") {
|
|
|
989
989
|
return;
|
|
990
990
|
}
|
|
991
991
|
if (src.match(SPEAK_EMBED_REGEX)) {
|
|
992
|
-
let normalizedSrc = src.replace(/3speak\.[a-z]+/i, "
|
|
993
|
-
if (!/[?&]mode=iframe/.test(normalizedSrc)) {
|
|
994
|
-
normalizedSrc = `${normalizedSrc}${normalizedSrc.includes("?") ? "&" : "?"}mode=iframe`;
|
|
995
|
-
}
|
|
992
|
+
let normalizedSrc = src.replace(/3speak\.[a-z]+/i, "3speak.tv");
|
|
996
993
|
const hasAutoplay = /[?&]autoplay=/.test(normalizedSrc);
|
|
997
994
|
const s = hasAutoplay ? normalizedSrc : `${normalizedSrc}&autoplay=true`;
|
|
998
995
|
el.setAttribute("src", s);
|
|
@@ -1277,6 +1274,20 @@ function getLolightInstance() {
|
|
|
1277
1274
|
}
|
|
1278
1275
|
return lolight;
|
|
1279
1276
|
}
|
|
1277
|
+
function fixBlockLevelTagsInParagraphs(html) {
|
|
1278
|
+
const blockTags = "center|div|table|figure|section|article|aside|header|footer|nav|main";
|
|
1279
|
+
const openingPattern = new RegExp(`<p>(<(?:${blockTags})(?:\\s[^>]*)?>)<\\/p>`, "gi");
|
|
1280
|
+
html = html.replace(openingPattern, "$1");
|
|
1281
|
+
const closingPattern = new RegExp(`<p>(<\\/(?:${blockTags})>)<\\/p>`, "gi");
|
|
1282
|
+
html = html.replace(closingPattern, "$1");
|
|
1283
|
+
const startPattern = new RegExp(`<p>(<(?:${blockTags})(?:\\s[^>]*)?>)(?:<br>)?\\s*`, "gi");
|
|
1284
|
+
html = html.replace(startPattern, "$1<p>");
|
|
1285
|
+
const endPattern = new RegExp(`\\s*(?:<br>)?\\s*(<\\/(?:${blockTags})>)<\\/p>`, "gi");
|
|
1286
|
+
html = html.replace(endPattern, "</p>$1");
|
|
1287
|
+
html = html.replace(/<p>\s*<\/p>/g, "");
|
|
1288
|
+
html = html.replace(/<p><br>\s*<\/p>/g, "");
|
|
1289
|
+
return html;
|
|
1290
|
+
}
|
|
1280
1291
|
function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
|
|
1281
1292
|
input = input.replace(new RegExp("https://leofinance.io/threads/view/", "g"), "/@");
|
|
1282
1293
|
input = input.replace(new RegExp("https://leofinance.io/posts/", "g"), "/@");
|
|
@@ -1335,6 +1346,7 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
|
|
|
1335
1346
|
}
|
|
1336
1347
|
try {
|
|
1337
1348
|
output = md.render(input);
|
|
1349
|
+
output = fixBlockLevelTagsInParagraphs(output);
|
|
1338
1350
|
const doc = DOMParser.parseFromString(`<body id="root">${output}</body>`, "text/html");
|
|
1339
1351
|
traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain);
|
|
1340
1352
|
output = serializer.serializeToString(doc);
|