@ecency/render-helper 2.4.3 → 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.
@@ -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;
@@ -83,8 +83,8 @@ var LBRY_REGEX = /^(https?:)?\/\/lbry.tv\/\$\/embed\/[^?#]+(?:$|[?#])/i;
83
83
  var ODYSEE_REGEX = /^(https?:)?\/\/odysee\.com\/(?:\$|%24)\/embed\/[^/?#]+(?:$|[?#])/i;
84
84
  var SKATEHIVE_IPFS_REGEX = /^https?:\/\/ipfs\.skatehive\.app\/ipfs\/([^/?#]+)/i;
85
85
  var ARCH_REGEX = /^(https?:)?\/\/archive.org\/embed\/[^/?#]+(?:$|[?#])/i;
86
- var SPEAK_REGEX = /(?:https?:\/\/(?:3speak.([a-z]+)\/watch\?v=)|(?:3speak.([a-z]+)\/embed\?v=))([A-Za-z0-9\_\-\.\/]+)(&.*)?/i;
87
- var SPEAK_EMBED_REGEX = /^(https?:)?\/\/3speak.([a-z]+)\/embed\?[^/]+$/i;
86
+ var SPEAK_REGEX = /(?:https?:\/\/(?:(?:play\.)?3speak.([a-z]+)\/watch\?v=)|(?:(?:play\.)?3speak.([a-z]+)\/embed\?v=))([A-Za-z0-9\_\-\.\/]+)(&.*)?/i;
87
+ var SPEAK_EMBED_REGEX = /^(https?:)?\/\/(?:play\.)?3speak.([a-z]+)\/embed\?[^/]+$/i;
88
88
  var TWITTER_REGEX = /(?:https?:\/\/(?:(?:twitter\.com\/(.*?)\/status\/(.*))))/gi;
89
89
  var SPOTIFY_REGEX = /^https:\/\/open\.spotify\.com\/playlist\/(.*)?$/gi;
90
90
  var RUMBLE_REGEX = /^https:\/\/rumble.com\/embed\/([a-zA-Z0-9-]+)\/\?pub=\w+/;
@@ -185,7 +185,7 @@ function createDoc(html) {
185
185
  if (html.trim() === "") {
186
186
  return null;
187
187
  }
188
- const doc = DOMParser.parseFromString(html, "text/html");
188
+ const doc = DOMParser.parseFromString(`<body>${html}</body>`, "text/html");
189
189
  return doc;
190
190
  }
191
191
  function makeEntryCacheKey(entry) {
@@ -992,9 +992,9 @@ function iframe(el, parentDomain = "ecency.com") {
992
992
  return;
993
993
  }
994
994
  if (src.match(SPEAK_EMBED_REGEX)) {
995
- const normalizedSrc = src.replace(/3speak\.[a-z]+/i, "3speak.tv");
995
+ let normalizedSrc = src.replace(/3speak\.[a-z]+/i, "3speak.tv");
996
996
  const hasAutoplay = /[?&]autoplay=/.test(normalizedSrc);
997
- const s = hasAutoplay ? normalizedSrc : `${normalizedSrc}${normalizedSrc.includes("?") ? "&" : "?"}autoplay=true`;
997
+ const s = hasAutoplay ? normalizedSrc : `${normalizedSrc}&autoplay=true`;
998
998
  el.setAttribute("src", s);
999
999
  return;
1000
1000
  }
@@ -1277,6 +1277,20 @@ function getLolightInstance() {
1277
1277
  }
1278
1278
  return lolight;
1279
1279
  }
1280
+ function fixBlockLevelTagsInParagraphs(html) {
1281
+ const blockTags = "center|div|table|figure|section|article|aside|header|footer|nav|main";
1282
+ const openingPattern = new RegExp(`<p>(<(?:${blockTags})(?:\\s[^>]*)?>)<\\/p>`, "gi");
1283
+ html = html.replace(openingPattern, "$1");
1284
+ const closingPattern = new RegExp(`<p>(<\\/(?:${blockTags})>)<\\/p>`, "gi");
1285
+ html = html.replace(closingPattern, "$1");
1286
+ const startPattern = new RegExp(`<p>(<(?:${blockTags})(?:\\s[^>]*)?>)(?:<br>)?\\s*`, "gi");
1287
+ html = html.replace(startPattern, "$1<p>");
1288
+ const endPattern = new RegExp(`\\s*(?:<br>)?\\s*(<\\/(?:${blockTags})>)<\\/p>`, "gi");
1289
+ html = html.replace(endPattern, "</p>$1");
1290
+ html = html.replace(/<p>\s*<\/p>/g, "");
1291
+ html = html.replace(/<p><br>\s*<\/p>/g, "");
1292
+ return html;
1293
+ }
1280
1294
  function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
1281
1295
  input = input.replace(new RegExp("https://leofinance.io/threads/view/", "g"), "/@");
1282
1296
  input = input.replace(new RegExp("https://leofinance.io/posts/", "g"), "/@");
@@ -1335,6 +1349,7 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
1335
1349
  }
1336
1350
  try {
1337
1351
  output = md.render(input);
1352
+ output = fixBlockLevelTagsInParagraphs(output);
1338
1353
  const doc = DOMParser.parseFromString(`<body id="root">${output}</body>`, "text/html");
1339
1354
  traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain);
1340
1355
  output = serializer.serializeToString(doc);