@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.
@@ -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;
@@ -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) {
@@ -859,7 +859,7 @@ function a(el, forApp, webp, parentDomain = "ecency.com") {
859
859
  const imgEls2 = el.getElementsByTagName("img");
860
860
  if (imgEls2.length === 1 || el.textContent.trim() === href) {
861
861
  if ((match[1] || match[2]) && match[3]) {
862
- const videoHref = `https://play.3speak.tv/embed?v=${match[3]}&mode=iframe`;
862
+ const videoHref = `https://3speak.tv/embed?v=${match[3]}`;
863
863
  el.setAttribute("class", "markdown-video-link markdown-video-link-speak");
864
864
  el.removeAttribute("href");
865
865
  el.setAttribute("data-embed-src", videoHref);
@@ -992,10 +992,7 @@ function iframe(el, parentDomain = "ecency.com") {
992
992
  return;
993
993
  }
994
994
  if (src.match(SPEAK_EMBED_REGEX)) {
995
- let normalizedSrc = src.replace(/3speak\.[a-z]+/i, "play.3speak.tv");
996
- if (!/[?&]mode=iframe/.test(normalizedSrc)) {
997
- normalizedSrc = `${normalizedSrc}${normalizedSrc.includes("?") ? "&" : "?"}mode=iframe`;
998
- }
995
+ let normalizedSrc = src.replace(/3speak\.[a-z]+/i, "3speak.tv");
999
996
  const hasAutoplay = /[?&]autoplay=/.test(normalizedSrc);
1000
997
  const s = hasAutoplay ? normalizedSrc : `${normalizedSrc}&autoplay=true`;
1001
998
  el.setAttribute("src", s);
@@ -1280,6 +1277,20 @@ function getLolightInstance() {
1280
1277
  }
1281
1278
  return lolight;
1282
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
+ }
1283
1294
  function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
1284
1295
  input = input.replace(new RegExp("https://leofinance.io/threads/view/", "g"), "/@");
1285
1296
  input = input.replace(new RegExp("https://leofinance.io/posts/", "g"), "/@");
@@ -1338,6 +1349,7 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
1338
1349
  }
1339
1350
  try {
1340
1351
  output = md.render(input);
1352
+ output = fixBlockLevelTagsInParagraphs(output);
1341
1353
  const doc = DOMParser.parseFromString(`<body id="root">${output}</body>`, "text/html");
1342
1354
  traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain);
1343
1355
  output = serializer.serializeToString(doc);