@ecency/render-helper 2.4.4 → 2.4.6
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 +24 -12
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +45 -13
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +24 -12
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.mjs
CHANGED
|
@@ -4,8 +4,10 @@ import multihash from 'multihashes';
|
|
|
4
4
|
import querystring from 'querystring';
|
|
5
5
|
import { Remarkable } from 'remarkable';
|
|
6
6
|
import { linkify as linkify$1 } from 'remarkable/linkify';
|
|
7
|
-
import { LRUCache } from 'lru-cache';
|
|
8
7
|
import he from 'he';
|
|
8
|
+
import * as htmlparser2 from 'htmlparser2';
|
|
9
|
+
import * as domSerializerModule from 'dom-serializer';
|
|
10
|
+
import { LRUCache } from 'lru-cache';
|
|
9
11
|
|
|
10
12
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
11
13
|
get: (a2, b) => (typeof require !== "undefined" ? require : a2)[b]
|
|
@@ -57,7 +59,7 @@ var SECTION_LIST = [
|
|
|
57
59
|
];
|
|
58
60
|
|
|
59
61
|
// src/consts/regexes.const.ts
|
|
60
|
-
var IMG_REGEX = /(https?:\/\/.*\.(?:tiff?|jpe?g|gif|png|svg|ico|heic|webp))(.*)/gim;
|
|
62
|
+
var IMG_REGEX = /(https?:\/\/.*\.(?:tiff?|jpe?g|gif|png|svg|ico|heic|webp|arw))(.*)/gim;
|
|
61
63
|
var IPFS_REGEX = /^https?:\/\/[^/]+\/(ip[fn]s)\/([^/?#]+)/gim;
|
|
62
64
|
var POST_REGEX = /^https?:\/\/(.*)\/(.*)\/(@[\w.\d-]+)\/(.*)/i;
|
|
63
65
|
var CCC_REGEX = /^https?:\/\/(.*)\/ccc\/([\w.\d-]+)\/(.*)/i;
|
|
@@ -185,7 +187,7 @@ function createDoc(html) {
|
|
|
185
187
|
if (html.trim() === "") {
|
|
186
188
|
return null;
|
|
187
189
|
}
|
|
188
|
-
const doc = DOMParser.parseFromString(html
|
|
190
|
+
const doc = DOMParser.parseFromString(`<body>${html}</body>`, "text/html");
|
|
189
191
|
return doc;
|
|
190
192
|
}
|
|
191
193
|
function makeEntryCacheKey(entry) {
|
|
@@ -859,7 +861,7 @@ function a(el, forApp, webp, parentDomain = "ecency.com") {
|
|
|
859
861
|
const imgEls2 = el.getElementsByTagName("img");
|
|
860
862
|
if (imgEls2.length === 1 || el.textContent.trim() === href) {
|
|
861
863
|
if ((match[1] || match[2]) && match[3]) {
|
|
862
|
-
const videoHref = `https://
|
|
864
|
+
const videoHref = `https://3speak.tv/embed?v=${match[3]}`;
|
|
863
865
|
el.setAttribute("class", "markdown-video-link markdown-video-link-speak");
|
|
864
866
|
el.removeAttribute("href");
|
|
865
867
|
el.setAttribute("data-embed-src", videoHref);
|
|
@@ -992,10 +994,7 @@ function iframe(el, parentDomain = "ecency.com") {
|
|
|
992
994
|
return;
|
|
993
995
|
}
|
|
994
996
|
if (src.match(SPEAK_EMBED_REGEX)) {
|
|
995
|
-
let normalizedSrc = src.replace(/3speak\.[a-z]+/i, "
|
|
996
|
-
if (!/[?&]mode=iframe/.test(normalizedSrc)) {
|
|
997
|
-
normalizedSrc = `${normalizedSrc}${normalizedSrc.includes("?") ? "&" : "?"}mode=iframe`;
|
|
998
|
-
}
|
|
997
|
+
let normalizedSrc = src.replace(/3speak\.[a-z]+/i, "3speak.tv");
|
|
999
998
|
const hasAutoplay = /[?&]autoplay=/.test(normalizedSrc);
|
|
1000
999
|
const s = hasAutoplay ? normalizedSrc : `${normalizedSrc}&autoplay=true`;
|
|
1001
1000
|
el.setAttribute("src", s);
|
|
@@ -1269,6 +1268,7 @@ function traverse(node, forApp, depth = 0, webp = false, state = { firstImageFou
|
|
|
1269
1268
|
function cleanReply(s) {
|
|
1270
1269
|
return (s ? s.split("\n").filter((item) => item.toLowerCase().includes("posted using [partiko") === false).filter((item) => item.toLowerCase().includes("posted using [dapplr") === false).filter((item) => item.toLowerCase().includes("posted using [leofinance") === false).filter((item) => item.toLowerCase().includes("posted via [neoxian") === false).filter((item) => item.toLowerCase().includes("posted using [neoxian") === false).filter((item) => item.toLowerCase().includes("posted with [stemgeeks") === false).filter((item) => item.toLowerCase().includes("posted using [bilpcoin") === false).filter((item) => item.toLowerCase().includes("posted using [inleo") === false).filter((item) => item.toLowerCase().includes("posted using [sportstalksocial]") === false).filter((item) => item.toLowerCase().includes("<center><sub>[posted using aeneas.blog") === false).filter((item) => item.toLowerCase().includes("<center><sub>posted via [proofofbrain.io") === false).filter((item) => item.toLowerCase().includes("<center>posted on [hypnochain") === false).filter((item) => item.toLowerCase().includes("<center><sub>posted via [weedcash.network") === false).filter((item) => item.toLowerCase().includes("<center>posted on [naturalmedicine.io") === false).filter((item) => item.toLowerCase().includes("<center><sub>posted via [musicforlife.io") === false).filter((item) => item.toLowerCase().includes("if the truvvl embed is unsupported by your current frontend, click this link to view this story") === false).filter((item) => item.toLowerCase().includes("<center><em>posted from truvvl") === false).filter((item) => item.toLowerCase().includes('view this post <a href="https://travelfeed.io/') === false).filter((item) => item.toLowerCase().includes("read this post on travelfeed.io for the best experience") === false).filter((item) => item.toLowerCase().includes('posted via <a href="https://www.dporn.co/"') === false).filter((item) => item.toLowerCase().includes("\u25B6\uFE0F [watch on 3speak](https://3speak") === false).filter((item) => item.toLowerCase().includes("<sup><sub>posted via [inji.com]") === false).filter((item) => item.toLowerCase().includes("view this post on [liketu]") === false).filter((item) => item.toLowerCase().includes("[via Inbox]") === false).join("\n") : "").replace('Posted via <a href="https://d.buzz" data-link="promote-link">D.Buzz</a>', "").replace('<div class="pull-right"><a href="/@hive.engage"></a></div>', "").replace('<div><a href="https://engage.hivechain.app"></a></div>', "").replace(`<div class="text-center"><img src="https://cdn.steemitimages.com/DQmNp6YwAm2qwquALZw8PdcovDorwaBSFuxQ38TrYziGT6b/A-20.png"><a href="https://bit.ly/actifit-app"><img src="https://cdn.steemitimages.com/DQmQqfpSmcQtfrHAtzfBtVccXwUL9vKNgZJ2j93m8WNjizw/l5.png"></a><a href="https://bit.ly/actifit-ios"><img src="https://cdn.steemitimages.com/DQmbWy8KzKT1UvCvznUTaFPw6wBUcyLtBT5XL9wdbB7Hfmn/l6.png"></a></div>`, "");
|
|
1271
1270
|
}
|
|
1271
|
+
var domSerializer = domSerializerModule.default || domSerializerModule;
|
|
1272
1272
|
var lolight = null;
|
|
1273
1273
|
function getLolightInstance() {
|
|
1274
1274
|
if (!lolight) {
|
|
@@ -1280,6 +1280,20 @@ function getLolightInstance() {
|
|
|
1280
1280
|
}
|
|
1281
1281
|
return lolight;
|
|
1282
1282
|
}
|
|
1283
|
+
function fixBlockLevelTagsInParagraphs(html) {
|
|
1284
|
+
const blockTags = "center|div|table|figure|section|article|aside|header|footer|nav|main";
|
|
1285
|
+
const openingPattern = new RegExp(`<p>(<(?:${blockTags})(?:\\s[^>]*)?>)<\\/p>`, "gi");
|
|
1286
|
+
html = html.replace(openingPattern, "$1");
|
|
1287
|
+
const closingPattern = new RegExp(`<p>(<\\/(?:${blockTags})>)<\\/p>`, "gi");
|
|
1288
|
+
html = html.replace(closingPattern, "$1");
|
|
1289
|
+
const startPattern = new RegExp(`<p>(<(?:${blockTags})(?:\\s[^>]*)?>)(?:<br>)?\\s*`, "gi");
|
|
1290
|
+
html = html.replace(startPattern, "$1<p>");
|
|
1291
|
+
const endPattern = new RegExp(`\\s*(?:<br>)?\\s*(<\\/(?:${blockTags})>)<\\/p>`, "gi");
|
|
1292
|
+
html = html.replace(endPattern, "</p>$1");
|
|
1293
|
+
html = html.replace(/<p>\s*<\/p>/g, "");
|
|
1294
|
+
html = html.replace(/<p><br>\s*<\/p>/g, "");
|
|
1295
|
+
return html;
|
|
1296
|
+
}
|
|
1283
1297
|
function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
|
|
1284
1298
|
input = input.replace(new RegExp("https://leofinance.io/threads/view/", "g"), "/@");
|
|
1285
1299
|
input = input.replace(new RegExp("https://leofinance.io/posts/", "g"), "/@");
|
|
@@ -1338,6 +1352,7 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
|
|
|
1338
1352
|
}
|
|
1339
1353
|
try {
|
|
1340
1354
|
output = md.render(input);
|
|
1355
|
+
output = fixBlockLevelTagsInParagraphs(output);
|
|
1341
1356
|
const doc = DOMParser.parseFromString(`<body id="root">${output}</body>`, "text/html");
|
|
1342
1357
|
traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain);
|
|
1343
1358
|
output = serializer.serializeToString(doc);
|
|
@@ -1345,8 +1360,6 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
|
|
|
1345
1360
|
try {
|
|
1346
1361
|
output = md.render(input);
|
|
1347
1362
|
const preSanitized = sanitizeHtml(output);
|
|
1348
|
-
const htmlparser2 = __require("htmlparser2");
|
|
1349
|
-
const domSerializer = __require("dom-serializer").default;
|
|
1350
1363
|
const dom = htmlparser2.parseDocument(preSanitized, {
|
|
1351
1364
|
// lenient options - don't throw on malformed HTML
|
|
1352
1365
|
lowerCaseTags: false,
|
|
@@ -1357,8 +1370,7 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
|
|
|
1357
1370
|
traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain);
|
|
1358
1371
|
output = serializer.serializeToString(doc);
|
|
1359
1372
|
} catch (fallbackError) {
|
|
1360
|
-
const
|
|
1361
|
-
const escapedContent = he2.encode(output || md.render(input));
|
|
1373
|
+
const escapedContent = he.encode(output || md.render(input));
|
|
1362
1374
|
output = `<p dir="auto">${escapedContent}</p>`;
|
|
1363
1375
|
}
|
|
1364
1376
|
}
|