@ecency/render-helper 2.5.20 → 2.5.22

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,7 +1,6 @@
1
1
  import { DOMParser as DOMParser$1, XMLSerializer } from '@xmldom/xmldom';
2
2
  import he2 from 'he';
3
3
  import xss from 'xss';
4
- import multihash from 'multihashes';
5
4
  import querystring from 'querystring';
6
5
  import { LRUCache } from 'lru-cache';
7
6
  import { Remarkable } from 'remarkable';
@@ -72,15 +71,15 @@ var VIMEO_EMBED_REGEX = /https:\/\/player\.vimeo\.com\/video\/([0-9]+)(?:$|[?#])
72
71
  var BITCHUTE_REGEX = /^(?:https?:\/\/)?(?:www\.)?bitchute\.com\/(?:video|embed)\/([a-z0-9]+)/i;
73
72
  var D_TUBE_REGEX = /(https?:\/\/d\.tube\/#!\/v\/)(\w+)\/(\w+)/g;
74
73
  var D_TUBE_REGEX2 = /(https?:\/\/d\.tube\/v\/)(\w+)\/(\w+)/g;
75
- var D_TUBE_EMBED_REGEX = /^https:\/\/emb.d.tube\/#!\/[^/?#]+\/[^/?#]+(?:$|[?#])/i;
74
+ var D_TUBE_EMBED_REGEX = /^https:\/\/emb\.d\.tube\/#!\/[^/?#]+\/[^/?#]+(?:$|[?#])/i;
76
75
  var TWITCH_REGEX = /https?:\/\/(?:www\.)?twitch\.tv\/(?:(videos)\/)?([a-zA-Z0-9][\w]{3,24})/i;
77
- var DAPPLR_REGEX = /^(https?:)?\/\/[a-z]*\.dapplr.in\/file\/dapplr-videos\/.*/i;
78
- var TRUVVL_REGEX = /^https?:\/\/embed.truvvl.com\/(@[\w.\d-]+)\/(.*)/i;
79
- var LBRY_REGEX = /^(https?:)?\/\/lbry.tv\/\$\/embed\/[^?#]+(?:$|[?#])/i;
76
+ var DAPPLR_REGEX = /^(https?:)?\/\/[a-z]*\.dapplr\.in\/file\/dapplr-videos\/.*/i;
77
+ var TRUVVL_REGEX = /^https?:\/\/embed\.truvvl\.com\/(@[\w.\d-]+)\/(.*)/i;
78
+ var LBRY_REGEX = /^(https?:)?\/\/lbry\.tv\/\$\/embed\/[^?#]+(?:$|[?#])/i;
80
79
  var ODYSEE_REGEX = /^(https?:)?\/\/odysee\.com\/(?:\$|%24)\/embed\/[^?#]+(?:$|[?#])/i;
81
80
  var SKATEHIVE_IPFS_REGEX = /^https?:\/\/ipfs\.skatehive\.app\/ipfs\/([^/?#]+)/i;
82
81
  var SKATEHYPE_EMBED_REGEX = /^(https?:)?\/\/(www\.)?skatehype\.com\/ifplay\.php\?v=\d+(?:$|[&#])/i;
83
- var ARCH_REGEX = /^(https?:)?\/\/archive.org\/embed\/[^/?#]+(?:$|[?#])/i;
82
+ var ARCH_REGEX = /^(https?:)?\/\/archive\.org\/embed\/[^/?#]+(?:$|[?#])/i;
84
83
  var SPEAK_REGEX = /(?:https?:\/\/(?:(?:play\.)?3speak\.([a-z]+)\/watch\?v=)|(?:(?:play\.)?3speak\.([a-z]+)\/embed\?v=))([A-Za-z0-9_\-\.\/]+)(&.*)?/i;
85
84
  var SPEAK_EMBED_REGEX = /^(https?:)?\/\/(?:play\.)?3speak\.([a-z]+)\/(?:embed|watch)\?.+$/i;
86
85
  var SPEAK_AUDIO_REGEX = /https?:\/\/audio\.3speak\.tv\/play\?[^\s]+/i;
@@ -99,7 +98,6 @@ var LOOM_REGEX = /^(https?:)?\/\/www\.loom\.com\/share\/([^/?#]+)(?:$|[?#])/i;
99
98
  var LOOM_EMBED_REGEX = /^(https?:)?\/\/www\.loom\.com\/embed\/([^/?#]+)(?:$|[?#])/i;
100
99
  var AUREAL_EMBED_REGEX = /^(https?:)?\/\/(www\.)?(?:aureal-embed)\.web\.app\/([0-9]+)(?:$|[?#])/i;
101
100
  var ENTITY_REGEX = /&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});/ig;
102
- var SECTION_REGEX = /\B(\#[\da-zA-Z-_]+\b)(?!;)/i;
103
101
  var ID_WHITELIST = /^[A-Za-z][-A-Za-z0-9_]*$/;
104
102
 
105
103
  // src/consts/allowed-attributes.const.ts
@@ -542,10 +540,35 @@ function removeChildNodes(node) {
542
540
  }
543
541
  var proxyBase = "https://i.ecency.com";
544
542
  var urlHashCache = new LRUCache({ max: 500 });
543
+ var BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
544
+ function base58Encode(bytes) {
545
+ if (bytes.length === 0) return "";
546
+ const digits = [0];
547
+ for (let i = 0; i < bytes.length; i++) {
548
+ let carry = bytes[i];
549
+ for (let j = 0; j < digits.length; j++) {
550
+ carry += digits[j] << 8;
551
+ digits[j] = carry % 58;
552
+ carry = carry / 58 | 0;
553
+ }
554
+ while (carry > 0) {
555
+ digits.push(carry % 58);
556
+ carry = carry / 58 | 0;
557
+ }
558
+ }
559
+ let out = "";
560
+ for (let k = 0; k < bytes.length && bytes[k] === 0; k++) out += BASE58_ALPHABET[0];
561
+ for (let q = digits.length - 1; q >= 0; q--) out += BASE58_ALPHABET[digits[q]];
562
+ return out;
563
+ }
564
+ function utf8Bytes(url) {
565
+ if (typeof TextEncoder !== "undefined") return new TextEncoder().encode(url);
566
+ return Uint8Array.from(Buffer.from(url, "utf8"));
567
+ }
545
568
  function getUrlHash(url) {
546
569
  const cached = urlHashCache.get(url);
547
570
  if (cached) return cached;
548
- const hash = multihash.toB58String(Buffer.from(url));
571
+ const hash = base58Encode(utf8Bytes(url));
549
572
  urlHashCache.set(url, hash);
550
573
  return hash;
551
574
  }
@@ -873,10 +896,6 @@ function a(el, forApp, parentDomain = "ecency.com", seoContext, renderOptions) {
873
896
  if (!href) {
874
897
  return;
875
898
  }
876
- const className = el.getAttribute("class");
877
- if (className && (["markdown-author-link", "markdown-tag-link"].includes(className) || className.includes("er-author") || className.includes("er-tag"))) {
878
- return;
879
- }
880
899
  const trimmed = href.trim().replace(/[\t\n\r\f\v\0]/g, "").toLowerCase();
881
900
  const isSafeScheme = /^(https?|mailto|hive|tel|web\+[a-z0-9.+-]+):/i.test(trimmed);
882
901
  const isRelative = /^(\/\/|\/[^/]?|#|\?|[a-z0-9._\-]+(\/|$))/i.test(trimmed);
@@ -884,6 +903,13 @@ function a(el, forApp, parentDomain = "ecency.com", seoContext, renderOptions) {
884
903
  el.removeAttribute("href");
885
904
  return;
886
905
  }
906
+ const className = el.getAttribute("class");
907
+ if (className && (["markdown-author-link", "markdown-tag-link"].includes(className) || className.includes("er-author") || className.includes("er-tag"))) {
908
+ if (el.getAttribute("target")) {
909
+ el.setAttribute("rel", getExternalLinkRel(seoContext));
910
+ }
911
+ return;
912
+ }
887
913
  if (href.match(IMG_REGEX) && href.trim().replace(/&amp;/g, "&") === getSerializedInnerHTML(el).trim().replace(/&amp;/g, "&")) {
888
914
  const isLCP = false;
889
915
  const imgHTML = createImageHTML(href, isLCP, forApp);
@@ -1481,7 +1507,7 @@ function a(el, forApp, parentDomain = "ecency.com", seoContext, renderOptions) {
1481
1507
  }
1482
1508
  el.removeAttribute("href");
1483
1509
  } else {
1484
- const matchS = href.match(SECTION_REGEX);
1510
+ const matchS = href.trim().startsWith("#");
1485
1511
  if (matchS) {
1486
1512
  el.setAttribute("class", "markdown-internal-link");
1487
1513
  } else {