@ecency/render-helper 2.4.11 → 2.4.13

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.
@@ -4,7 +4,7 @@ import multihash from 'multihashes';
4
4
  import querystring from 'querystring';
5
5
  import { Remarkable } from 'remarkable';
6
6
  import { linkify as linkify$1 } from 'remarkable/linkify';
7
- import he from 'he';
7
+ import he2 from 'he';
8
8
  import * as htmlparser2 from 'htmlparser2';
9
9
  import * as domSerializerModule from 'dom-serializer';
10
10
  import { LRUCache } from 'lru-cache';
@@ -1401,7 +1401,7 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
1401
1401
  traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain);
1402
1402
  output = serializer.serializeToString(doc);
1403
1403
  } catch (fallbackError) {
1404
- const escapedContent = he.encode(output || md.render(input));
1404
+ const escapedContent = he2.encode(output || md.render(input));
1405
1405
  output = `<p dir="auto">${escapedContent}</p>`;
1406
1406
  }
1407
1407
  }
@@ -1441,8 +1441,6 @@ function markdown2Html(obj, forApp = true, webp = false, parentDomain = "ecency.
1441
1441
  cacheSet(key, res);
1442
1442
  return res;
1443
1443
  }
1444
-
1445
- // src/catch-post-image.ts
1446
1444
  var gifLinkRegex = /\.(gif)$/i;
1447
1445
  function isGifLink(link) {
1448
1446
  return gifLinkRegex.test(link);
@@ -1459,12 +1457,20 @@ function getImage(entry, width = 0, height = 0, format = "match") {
1459
1457
  }
1460
1458
  }
1461
1459
  if (meta && typeof meta.image === "string" && meta.image.length > 0) {
1462
- if (isGifLink(meta.image)) {
1463
- return proxifyImageSrc(meta.image, 0, 0, format);
1460
+ const decodedImage = he2.decode(meta.image);
1461
+ if (isGifLink(decodedImage)) {
1462
+ return proxifyImageSrc(decodedImage, 0, 0, format);
1464
1463
  }
1465
- return proxifyImageSrc(meta.image, width, height, format);
1464
+ return proxifyImageSrc(decodedImage, width, height, format);
1466
1465
  }
1467
1466
  if (meta && meta.image && !!meta.image.length && meta.image[0]) {
1467
+ if (typeof meta.image[0] === "string") {
1468
+ const decodedImage = he2.decode(meta.image[0]);
1469
+ if (isGifLink(decodedImage)) {
1470
+ return proxifyImageSrc(decodedImage, 0, 0, format);
1471
+ }
1472
+ return proxifyImageSrc(decodedImage, width, height, format);
1473
+ }
1468
1474
  if (isGifLink(meta.image[0])) {
1469
1475
  return proxifyImageSrc(meta.image[0], 0, 0, format);
1470
1476
  }
@@ -1481,20 +1487,34 @@ function getImage(entry, width = 0, height = 0, format = "match") {
1481
1487
  if (!src) {
1482
1488
  return null;
1483
1489
  }
1484
- if (isGifLink(src)) {
1485
- return proxifyImageSrc(src, 0, 0, format);
1490
+ const decodedSrc = he2.decode(src);
1491
+ if (isGifLink(decodedSrc)) {
1492
+ return proxifyImageSrc(decodedSrc, 0, 0, format);
1486
1493
  }
1487
- return proxifyImageSrc(src, width, height, format);
1494
+ return proxifyImageSrc(decodedSrc, width, height, format);
1488
1495
  }
1489
1496
  return null;
1490
1497
  }
1491
1498
  function catchPostImage(obj, width = 0, height = 0, format = "match") {
1492
1499
  if (typeof obj === "string") {
1493
- const entryWrapper = {
1494
- body: obj,
1495
- json_metadata: "{}"
1496
- };
1497
- return getImage(entryWrapper, width, height, format);
1500
+ const html = markdown2Html(obj);
1501
+ const doc = createDoc(html);
1502
+ if (!doc) {
1503
+ return null;
1504
+ }
1505
+ const imgEls = doc.getElementsByTagName("img");
1506
+ if (imgEls.length >= 1) {
1507
+ const src = imgEls[0].getAttribute("src");
1508
+ if (!src) {
1509
+ return null;
1510
+ }
1511
+ const decodedSrc = he2.decode(src);
1512
+ if (isGifLink(decodedSrc)) {
1513
+ return proxifyImageSrc(decodedSrc, 0, 0, format);
1514
+ }
1515
+ return proxifyImageSrc(decodedSrc, width, height, format);
1516
+ }
1517
+ return null;
1498
1518
  }
1499
1519
  const key = `${makeEntryCacheKey(obj)}-${width}x${height}-${format}`;
1500
1520
  const item = cacheGet(key);
@@ -1581,7 +1601,7 @@ function postBodySummary(entryBody, length = 200, platform = "web") {
1581
1601
  text2 = joint(text2.split(" "), length);
1582
1602
  }
1583
1603
  if (text2) {
1584
- text2 = he.decode(text2);
1604
+ text2 = he2.decode(text2);
1585
1605
  }
1586
1606
  return text2;
1587
1607
  }