@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.
@@ -6,15 +6,37 @@ var multihash = require('multihashes');
6
6
  var querystring = require('querystring');
7
7
  var remarkable = require('remarkable');
8
8
  var linkify$1 = require('remarkable/linkify');
9
- var lruCache = require('lru-cache');
10
9
  var he = require('he');
10
+ var htmlparser2 = require('htmlparser2');
11
+ var domSerializerModule = require('dom-serializer');
12
+ var lruCache = require('lru-cache');
11
13
 
12
14
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
13
15
 
16
+ function _interopNamespace(e) {
17
+ if (e && e.__esModule) return e;
18
+ var n = Object.create(null);
19
+ if (e) {
20
+ Object.keys(e).forEach(function (k) {
21
+ if (k !== 'default') {
22
+ var d = Object.getOwnPropertyDescriptor(e, k);
23
+ Object.defineProperty(n, k, d.get ? d : {
24
+ enumerable: true,
25
+ get: function () { return e[k]; }
26
+ });
27
+ }
28
+ });
29
+ }
30
+ n.default = e;
31
+ return Object.freeze(n);
32
+ }
33
+
14
34
  var xss__default = /*#__PURE__*/_interopDefault(xss);
15
35
  var multihash__default = /*#__PURE__*/_interopDefault(multihash);
16
36
  var querystring__default = /*#__PURE__*/_interopDefault(querystring);
17
37
  var he__default = /*#__PURE__*/_interopDefault(he);
38
+ var htmlparser2__namespace = /*#__PURE__*/_interopNamespace(htmlparser2);
39
+ var domSerializerModule__namespace = /*#__PURE__*/_interopNamespace(domSerializerModule);
18
40
 
19
41
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
20
42
  get: (a2, b) => (typeof require !== "undefined" ? require : a2)[b]
@@ -66,7 +88,7 @@ var SECTION_LIST = [
66
88
  ];
67
89
 
68
90
  // src/consts/regexes.const.ts
69
- var IMG_REGEX = /(https?:\/\/.*\.(?:tiff?|jpe?g|gif|png|svg|ico|heic|webp))(.*)/gim;
91
+ var IMG_REGEX = /(https?:\/\/.*\.(?:tiff?|jpe?g|gif|png|svg|ico|heic|webp|arw))(.*)/gim;
70
92
  var IPFS_REGEX = /^https?:\/\/[^/]+\/(ip[fn]s)\/([^/?#]+)/gim;
71
93
  var POST_REGEX = /^https?:\/\/(.*)\/(.*)\/(@[\w.\d-]+)\/(.*)/i;
72
94
  var CCC_REGEX = /^https?:\/\/(.*)\/ccc\/([\w.\d-]+)\/(.*)/i;
@@ -194,7 +216,7 @@ function createDoc(html) {
194
216
  if (html.trim() === "") {
195
217
  return null;
196
218
  }
197
- const doc = DOMParser.parseFromString(html, "text/html");
219
+ const doc = DOMParser.parseFromString(`<body>${html}</body>`, "text/html");
198
220
  return doc;
199
221
  }
200
222
  function makeEntryCacheKey(entry) {
@@ -868,7 +890,7 @@ function a(el, forApp, webp, parentDomain = "ecency.com") {
868
890
  const imgEls2 = el.getElementsByTagName("img");
869
891
  if (imgEls2.length === 1 || el.textContent.trim() === href) {
870
892
  if ((match[1] || match[2]) && match[3]) {
871
- const videoHref = `https://play.3speak.tv/embed?v=${match[3]}&mode=iframe`;
893
+ const videoHref = `https://3speak.tv/embed?v=${match[3]}`;
872
894
  el.setAttribute("class", "markdown-video-link markdown-video-link-speak");
873
895
  el.removeAttribute("href");
874
896
  el.setAttribute("data-embed-src", videoHref);
@@ -1001,10 +1023,7 @@ function iframe(el, parentDomain = "ecency.com") {
1001
1023
  return;
1002
1024
  }
1003
1025
  if (src.match(SPEAK_EMBED_REGEX)) {
1004
- let normalizedSrc = src.replace(/3speak\.[a-z]+/i, "play.3speak.tv");
1005
- if (!/[?&]mode=iframe/.test(normalizedSrc)) {
1006
- normalizedSrc = `${normalizedSrc}${normalizedSrc.includes("?") ? "&" : "?"}mode=iframe`;
1007
- }
1026
+ let normalizedSrc = src.replace(/3speak\.[a-z]+/i, "3speak.tv");
1008
1027
  const hasAutoplay = /[?&]autoplay=/.test(normalizedSrc);
1009
1028
  const s = hasAutoplay ? normalizedSrc : `${normalizedSrc}&autoplay=true`;
1010
1029
  el.setAttribute("src", s);
@@ -1278,6 +1297,7 @@ function traverse(node, forApp, depth = 0, webp = false, state = { firstImageFou
1278
1297
  function cleanReply(s) {
1279
1298
  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">![](https://i.imgur.com/XsrNmcl.png)</a></div>', "").replace('<div><a href="https://engage.hivechain.app">![](https://i.imgur.com/XsrNmcl.png)</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>`, "");
1280
1299
  }
1300
+ var domSerializer = domSerializerModule__namespace.default || domSerializerModule__namespace;
1281
1301
  var lolight = null;
1282
1302
  function getLolightInstance() {
1283
1303
  if (!lolight) {
@@ -1289,6 +1309,20 @@ function getLolightInstance() {
1289
1309
  }
1290
1310
  return lolight;
1291
1311
  }
1312
+ function fixBlockLevelTagsInParagraphs(html) {
1313
+ const blockTags = "center|div|table|figure|section|article|aside|header|footer|nav|main";
1314
+ const openingPattern = new RegExp(`<p>(<(?:${blockTags})(?:\\s[^>]*)?>)<\\/p>`, "gi");
1315
+ html = html.replace(openingPattern, "$1");
1316
+ const closingPattern = new RegExp(`<p>(<\\/(?:${blockTags})>)<\\/p>`, "gi");
1317
+ html = html.replace(closingPattern, "$1");
1318
+ const startPattern = new RegExp(`<p>(<(?:${blockTags})(?:\\s[^>]*)?>)(?:<br>)?\\s*`, "gi");
1319
+ html = html.replace(startPattern, "$1<p>");
1320
+ const endPattern = new RegExp(`\\s*(?:<br>)?\\s*(<\\/(?:${blockTags})>)<\\/p>`, "gi");
1321
+ html = html.replace(endPattern, "</p>$1");
1322
+ html = html.replace(/<p>\s*<\/p>/g, "");
1323
+ html = html.replace(/<p><br>\s*<\/p>/g, "");
1324
+ return html;
1325
+ }
1292
1326
  function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
1293
1327
  input = input.replace(new RegExp("https://leofinance.io/threads/view/", "g"), "/@");
1294
1328
  input = input.replace(new RegExp("https://leofinance.io/posts/", "g"), "/@");
@@ -1347,6 +1381,7 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
1347
1381
  }
1348
1382
  try {
1349
1383
  output = md.render(input);
1384
+ output = fixBlockLevelTagsInParagraphs(output);
1350
1385
  const doc = DOMParser.parseFromString(`<body id="root">${output}</body>`, "text/html");
1351
1386
  traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain);
1352
1387
  output = serializer.serializeToString(doc);
@@ -1354,9 +1389,7 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
1354
1389
  try {
1355
1390
  output = md.render(input);
1356
1391
  const preSanitized = sanitizeHtml(output);
1357
- const htmlparser2 = __require("htmlparser2");
1358
- const domSerializer = __require("dom-serializer").default;
1359
- const dom = htmlparser2.parseDocument(preSanitized, {
1392
+ const dom = htmlparser2__namespace.parseDocument(preSanitized, {
1360
1393
  // lenient options - don't throw on malformed HTML
1361
1394
  lowerCaseTags: false,
1362
1395
  lowerCaseAttributeNames: false
@@ -1366,8 +1399,7 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
1366
1399
  traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain);
1367
1400
  output = serializer.serializeToString(doc);
1368
1401
  } catch (fallbackError) {
1369
- const he2 = __require("he");
1370
- const escapedContent = he2.encode(output || md.render(input));
1402
+ const escapedContent = he__default.default.encode(output || md.render(input));
1371
1403
  output = `<p dir="auto">${escapedContent}</p>`;
1372
1404
  }
1373
1405
  }