@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.
@@ -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;
@@ -92,8 +92,8 @@ var LBRY_REGEX = /^(https?:)?\/\/lbry.tv\/\$\/embed\/[^?#]+(?:$|[?#])/i;
92
92
  var ODYSEE_REGEX = /^(https?:)?\/\/odysee\.com\/(?:\$|%24)\/embed\/[^/?#]+(?:$|[?#])/i;
93
93
  var SKATEHIVE_IPFS_REGEX = /^https?:\/\/ipfs\.skatehive\.app\/ipfs\/([^/?#]+)/i;
94
94
  var ARCH_REGEX = /^(https?:)?\/\/archive.org\/embed\/[^/?#]+(?:$|[?#])/i;
95
- var SPEAK_REGEX = /(?:https?:\/\/(?:3speak.([a-z]+)\/watch\?v=)|(?:3speak.([a-z]+)\/embed\?v=))([A-Za-z0-9\_\-\.\/]+)(&.*)?/i;
96
- var SPEAK_EMBED_REGEX = /^(https?:)?\/\/3speak.([a-z]+)\/embed\?[^/]+$/i;
95
+ var SPEAK_REGEX = /(?:https?:\/\/(?:(?:play\.)?3speak.([a-z]+)\/watch\?v=)|(?:(?:play\.)?3speak.([a-z]+)\/embed\?v=))([A-Za-z0-9\_\-\.\/]+)(&.*)?/i;
96
+ var SPEAK_EMBED_REGEX = /^(https?:)?\/\/(?:play\.)?3speak.([a-z]+)\/embed\?[^/]+$/i;
97
97
  var TWITTER_REGEX = /(?:https?:\/\/(?:(?:twitter\.com\/(.*?)\/status\/(.*))))/gi;
98
98
  var SPOTIFY_REGEX = /^https:\/\/open\.spotify\.com\/playlist\/(.*)?$/gi;
99
99
  var RUMBLE_REGEX = /^https:\/\/rumble.com\/embed\/([a-zA-Z0-9-]+)\/\?pub=\w+/;
@@ -194,7 +194,7 @@ function createDoc(html) {
194
194
  if (html.trim() === "") {
195
195
  return null;
196
196
  }
197
- const doc = DOMParser.parseFromString(html, "text/html");
197
+ const doc = DOMParser.parseFromString(`<body>${html}</body>`, "text/html");
198
198
  return doc;
199
199
  }
200
200
  function makeEntryCacheKey(entry) {
@@ -1001,9 +1001,9 @@ function iframe(el, parentDomain = "ecency.com") {
1001
1001
  return;
1002
1002
  }
1003
1003
  if (src.match(SPEAK_EMBED_REGEX)) {
1004
- const normalizedSrc = src.replace(/3speak\.[a-z]+/i, "3speak.tv");
1004
+ let normalizedSrc = src.replace(/3speak\.[a-z]+/i, "3speak.tv");
1005
1005
  const hasAutoplay = /[?&]autoplay=/.test(normalizedSrc);
1006
- const s = hasAutoplay ? normalizedSrc : `${normalizedSrc}${normalizedSrc.includes("?") ? "&" : "?"}autoplay=true`;
1006
+ const s = hasAutoplay ? normalizedSrc : `${normalizedSrc}&autoplay=true`;
1007
1007
  el.setAttribute("src", s);
1008
1008
  return;
1009
1009
  }
@@ -1286,6 +1286,20 @@ function getLolightInstance() {
1286
1286
  }
1287
1287
  return lolight;
1288
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
+ }
1289
1303
  function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
1290
1304
  input = input.replace(new RegExp("https://leofinance.io/threads/view/", "g"), "/@");
1291
1305
  input = input.replace(new RegExp("https://leofinance.io/posts/", "g"), "/@");
@@ -1344,6 +1358,7 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
1344
1358
  }
1345
1359
  try {
1346
1360
  output = md.render(input);
1361
+ output = fixBlockLevelTagsInParagraphs(output);
1347
1362
  const doc = DOMParser.parseFromString(`<body id="root">${output}</body>`, "text/html");
1348
1363
  traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain);
1349
1364
  output = serializer.serializeToString(doc);