@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.
- package/dist/browser/index.js +36 -16
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +37 -17
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +36 -16
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.mjs
CHANGED
|
@@ -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
|
|
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';
|
|
@@ -1404,7 +1404,7 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
|
|
|
1404
1404
|
traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain);
|
|
1405
1405
|
output = serializer.serializeToString(doc);
|
|
1406
1406
|
} catch (fallbackError) {
|
|
1407
|
-
const escapedContent =
|
|
1407
|
+
const escapedContent = he2.encode(output || md.render(input));
|
|
1408
1408
|
output = `<p dir="auto">${escapedContent}</p>`;
|
|
1409
1409
|
}
|
|
1410
1410
|
}
|
|
@@ -1444,8 +1444,6 @@ function markdown2Html(obj, forApp = true, webp = false, parentDomain = "ecency.
|
|
|
1444
1444
|
cacheSet(key, res);
|
|
1445
1445
|
return res;
|
|
1446
1446
|
}
|
|
1447
|
-
|
|
1448
|
-
// src/catch-post-image.ts
|
|
1449
1447
|
var gifLinkRegex = /\.(gif)$/i;
|
|
1450
1448
|
function isGifLink(link) {
|
|
1451
1449
|
return gifLinkRegex.test(link);
|
|
@@ -1462,12 +1460,20 @@ function getImage(entry, width = 0, height = 0, format = "match") {
|
|
|
1462
1460
|
}
|
|
1463
1461
|
}
|
|
1464
1462
|
if (meta && typeof meta.image === "string" && meta.image.length > 0) {
|
|
1465
|
-
|
|
1466
|
-
|
|
1463
|
+
const decodedImage = he2.decode(meta.image);
|
|
1464
|
+
if (isGifLink(decodedImage)) {
|
|
1465
|
+
return proxifyImageSrc(decodedImage, 0, 0, format);
|
|
1467
1466
|
}
|
|
1468
|
-
return proxifyImageSrc(
|
|
1467
|
+
return proxifyImageSrc(decodedImage, width, height, format);
|
|
1469
1468
|
}
|
|
1470
1469
|
if (meta && meta.image && !!meta.image.length && meta.image[0]) {
|
|
1470
|
+
if (typeof meta.image[0] === "string") {
|
|
1471
|
+
const decodedImage = he2.decode(meta.image[0]);
|
|
1472
|
+
if (isGifLink(decodedImage)) {
|
|
1473
|
+
return proxifyImageSrc(decodedImage, 0, 0, format);
|
|
1474
|
+
}
|
|
1475
|
+
return proxifyImageSrc(decodedImage, width, height, format);
|
|
1476
|
+
}
|
|
1471
1477
|
if (isGifLink(meta.image[0])) {
|
|
1472
1478
|
return proxifyImageSrc(meta.image[0], 0, 0, format);
|
|
1473
1479
|
}
|
|
@@ -1484,20 +1490,34 @@ function getImage(entry, width = 0, height = 0, format = "match") {
|
|
|
1484
1490
|
if (!src) {
|
|
1485
1491
|
return null;
|
|
1486
1492
|
}
|
|
1487
|
-
|
|
1488
|
-
|
|
1493
|
+
const decodedSrc = he2.decode(src);
|
|
1494
|
+
if (isGifLink(decodedSrc)) {
|
|
1495
|
+
return proxifyImageSrc(decodedSrc, 0, 0, format);
|
|
1489
1496
|
}
|
|
1490
|
-
return proxifyImageSrc(
|
|
1497
|
+
return proxifyImageSrc(decodedSrc, width, height, format);
|
|
1491
1498
|
}
|
|
1492
1499
|
return null;
|
|
1493
1500
|
}
|
|
1494
1501
|
function catchPostImage(obj, width = 0, height = 0, format = "match") {
|
|
1495
1502
|
if (typeof obj === "string") {
|
|
1496
|
-
const
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1503
|
+
const html = markdown2Html(obj);
|
|
1504
|
+
const doc = createDoc(html);
|
|
1505
|
+
if (!doc) {
|
|
1506
|
+
return null;
|
|
1507
|
+
}
|
|
1508
|
+
const imgEls = doc.getElementsByTagName("img");
|
|
1509
|
+
if (imgEls.length >= 1) {
|
|
1510
|
+
const src = imgEls[0].getAttribute("src");
|
|
1511
|
+
if (!src) {
|
|
1512
|
+
return null;
|
|
1513
|
+
}
|
|
1514
|
+
const decodedSrc = he2.decode(src);
|
|
1515
|
+
if (isGifLink(decodedSrc)) {
|
|
1516
|
+
return proxifyImageSrc(decodedSrc, 0, 0, format);
|
|
1517
|
+
}
|
|
1518
|
+
return proxifyImageSrc(decodedSrc, width, height, format);
|
|
1519
|
+
}
|
|
1520
|
+
return null;
|
|
1501
1521
|
}
|
|
1502
1522
|
const key = `${makeEntryCacheKey(obj)}-${width}x${height}-${format}`;
|
|
1503
1523
|
const item = cacheGet(key);
|
|
@@ -1584,7 +1604,7 @@ function postBodySummary(entryBody, length = 200, platform = "web") {
|
|
|
1584
1604
|
text2 = joint(text2.split(" "), length);
|
|
1585
1605
|
}
|
|
1586
1606
|
if (text2) {
|
|
1587
|
-
text2 =
|
|
1607
|
+
text2 = he2.decode(text2);
|
|
1588
1608
|
}
|
|
1589
1609
|
return text2;
|
|
1590
1610
|
}
|