@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.
@@ -1,3 +1,6 @@
1
+ /**
2
+ * Entry interface for Hive post data
3
+ */
1
4
  interface Entry {
2
5
  author?: string;
3
6
  permlink?: string;
@@ -29,4 +32,4 @@ declare const SECTION_LIST: string[];
29
32
 
30
33
  declare function isValidPermlink(permlink: string): boolean;
31
34
 
32
- export { SECTION_LIST, catchPostImage, isValidPermlink, getPostBodySummary as postBodySummary, proxifyImageSrc, markdown2Html as renderPostBody, setCacheSize, setProxyBase };
35
+ export { type Entry, SECTION_LIST, catchPostImage, isValidPermlink, getPostBodySummary as postBodySummary, proxifyImageSrc, markdown2Html as renderPostBody, setCacheSize, setProxyBase };
@@ -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+/;
@@ -182,7 +182,7 @@ function createDoc(html) {
182
182
  if (html.trim() === "") {
183
183
  return null;
184
184
  }
185
- const doc = DOMParser.parseFromString(html, "text/html");
185
+ const doc = DOMParser.parseFromString(`<body>${html}</body>`, "text/html");
186
186
  return doc;
187
187
  }
188
188
  function makeEntryCacheKey(entry) {
@@ -989,9 +989,9 @@ function iframe(el, parentDomain = "ecency.com") {
989
989
  return;
990
990
  }
991
991
  if (src.match(SPEAK_EMBED_REGEX)) {
992
- const normalizedSrc = src.replace(/3speak\.[a-z]+/i, "3speak.tv");
992
+ let normalizedSrc = src.replace(/3speak\.[a-z]+/i, "3speak.tv");
993
993
  const hasAutoplay = /[?&]autoplay=/.test(normalizedSrc);
994
- const s = hasAutoplay ? normalizedSrc : `${normalizedSrc}${normalizedSrc.includes("?") ? "&" : "?"}autoplay=true`;
994
+ const s = hasAutoplay ? normalizedSrc : `${normalizedSrc}&autoplay=true`;
995
995
  el.setAttribute("src", s);
996
996
  return;
997
997
  }
@@ -1274,6 +1274,20 @@ function getLolightInstance() {
1274
1274
  }
1275
1275
  return lolight;
1276
1276
  }
1277
+ function fixBlockLevelTagsInParagraphs(html) {
1278
+ const blockTags = "center|div|table|figure|section|article|aside|header|footer|nav|main";
1279
+ const openingPattern = new RegExp(`<p>(<(?:${blockTags})(?:\\s[^>]*)?>)<\\/p>`, "gi");
1280
+ html = html.replace(openingPattern, "$1");
1281
+ const closingPattern = new RegExp(`<p>(<\\/(?:${blockTags})>)<\\/p>`, "gi");
1282
+ html = html.replace(closingPattern, "$1");
1283
+ const startPattern = new RegExp(`<p>(<(?:${blockTags})(?:\\s[^>]*)?>)(?:<br>)?\\s*`, "gi");
1284
+ html = html.replace(startPattern, "$1<p>");
1285
+ const endPattern = new RegExp(`\\s*(?:<br>)?\\s*(<\\/(?:${blockTags})>)<\\/p>`, "gi");
1286
+ html = html.replace(endPattern, "</p>$1");
1287
+ html = html.replace(/<p>\s*<\/p>/g, "");
1288
+ html = html.replace(/<p><br>\s*<\/p>/g, "");
1289
+ return html;
1290
+ }
1277
1291
  function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
1278
1292
  input = input.replace(new RegExp("https://leofinance.io/threads/view/", "g"), "/@");
1279
1293
  input = input.replace(new RegExp("https://leofinance.io/posts/", "g"), "/@");
@@ -1332,6 +1346,7 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
1332
1346
  }
1333
1347
  try {
1334
1348
  output = md.render(input);
1349
+ output = fixBlockLevelTagsInParagraphs(output);
1335
1350
  const doc = DOMParser.parseFromString(`<body id="root">${output}</body>`, "text/html");
1336
1351
  traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain);
1337
1352
  output = serializer.serializeToString(doc);