@ecency/render-helper 2.4.12 → 2.4.14
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 +46 -18
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +48 -20
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +47 -19
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.js
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';
|
|
@@ -164,7 +164,8 @@ var ALLOWED_ATTRIBUTES = {
|
|
|
164
164
|
"del": [],
|
|
165
165
|
"ins": []
|
|
166
166
|
};
|
|
167
|
-
var lenientErrorHandler = (level, msg) => {
|
|
167
|
+
var lenientErrorHandler = (level, msg, context) => {
|
|
168
|
+
return void 0;
|
|
168
169
|
};
|
|
169
170
|
var DOMParser = new DOMParser$1({
|
|
170
171
|
// Use onError instead of deprecated errorHandler
|
|
@@ -173,11 +174,30 @@ var DOMParser = new DOMParser$1({
|
|
|
173
174
|
});
|
|
174
175
|
|
|
175
176
|
// src/helper.ts
|
|
177
|
+
function removeDuplicateAttributes(html) {
|
|
178
|
+
const tagRegex = /<([a-zA-Z][a-zA-Z0-9]*)\s+((?:[^>"']+|"[^"]*"|'[^']*')*?)\s*(\/?)>/g;
|
|
179
|
+
return html.replace(tagRegex, (match, tagName, attrsString, selfClose) => {
|
|
180
|
+
const seenAttrs = /* @__PURE__ */ new Set();
|
|
181
|
+
const cleanedAttrs = [];
|
|
182
|
+
const attrRegex = /([a-zA-Z_:][-a-zA-Z0-9_:.]*)\s*(?:=\s*(?:"[^"]*"|'[^']*'|[^\s/>]+))?/g;
|
|
183
|
+
let attrMatch;
|
|
184
|
+
while ((attrMatch = attrRegex.exec(attrsString)) !== null) {
|
|
185
|
+
const attrName = attrMatch[1].toLowerCase();
|
|
186
|
+
if (!seenAttrs.has(attrName)) {
|
|
187
|
+
seenAttrs.add(attrName);
|
|
188
|
+
cleanedAttrs.push(attrMatch[0]);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const attrsJoined = cleanedAttrs.length > 0 ? ` ${cleanedAttrs.join(" ")}` : "";
|
|
192
|
+
return `<${tagName}${attrsJoined}${selfClose ? " /" : ""}>`;
|
|
193
|
+
});
|
|
194
|
+
}
|
|
176
195
|
function createDoc(html) {
|
|
177
196
|
if (html.trim() === "") {
|
|
178
197
|
return null;
|
|
179
198
|
}
|
|
180
|
-
const
|
|
199
|
+
const cleanedHtml = removeDuplicateAttributes(html);
|
|
200
|
+
const doc = DOMParser.parseFromString(`<body>${cleanedHtml}</body>`, "text/html");
|
|
181
201
|
return doc;
|
|
182
202
|
}
|
|
183
203
|
function makeEntryCacheKey(entry) {
|
|
@@ -1384,7 +1404,7 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
|
|
|
1384
1404
|
try {
|
|
1385
1405
|
output = md.render(input);
|
|
1386
1406
|
output = fixBlockLevelTagsInParagraphs(output);
|
|
1387
|
-
const doc = DOMParser.parseFromString(`<body id="root">${output}</body>`, "text/html");
|
|
1407
|
+
const doc = DOMParser.parseFromString(`<body id="root">${removeDuplicateAttributes(output)}</body>`, "text/html");
|
|
1388
1408
|
traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain);
|
|
1389
1409
|
output = serializer.serializeToString(doc);
|
|
1390
1410
|
} catch (error) {
|
|
@@ -1397,11 +1417,11 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
|
|
|
1397
1417
|
lowerCaseAttributeNames: false
|
|
1398
1418
|
});
|
|
1399
1419
|
const repairedHtml = domSerializer(dom.children);
|
|
1400
|
-
const doc = DOMParser.parseFromString(`<body id="root">${repairedHtml}</body>`, "text/html");
|
|
1420
|
+
const doc = DOMParser.parseFromString(`<body id="root">${removeDuplicateAttributes(repairedHtml)}</body>`, "text/html");
|
|
1401
1421
|
traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain);
|
|
1402
1422
|
output = serializer.serializeToString(doc);
|
|
1403
1423
|
} catch (fallbackError) {
|
|
1404
|
-
const escapedContent =
|
|
1424
|
+
const escapedContent = he2.encode(output || md.render(input));
|
|
1405
1425
|
output = `<p dir="auto">${escapedContent}</p>`;
|
|
1406
1426
|
}
|
|
1407
1427
|
}
|
|
@@ -1441,8 +1461,6 @@ function markdown2Html(obj, forApp = true, webp = false, parentDomain = "ecency.
|
|
|
1441
1461
|
cacheSet(key, res);
|
|
1442
1462
|
return res;
|
|
1443
1463
|
}
|
|
1444
|
-
|
|
1445
|
-
// src/catch-post-image.ts
|
|
1446
1464
|
var gifLinkRegex = /\.(gif)$/i;
|
|
1447
1465
|
function isGifLink(link) {
|
|
1448
1466
|
return gifLinkRegex.test(link);
|
|
@@ -1459,12 +1477,20 @@ function getImage(entry, width = 0, height = 0, format = "match") {
|
|
|
1459
1477
|
}
|
|
1460
1478
|
}
|
|
1461
1479
|
if (meta && typeof meta.image === "string" && meta.image.length > 0) {
|
|
1462
|
-
|
|
1463
|
-
|
|
1480
|
+
const decodedImage = he2.decode(meta.image);
|
|
1481
|
+
if (isGifLink(decodedImage)) {
|
|
1482
|
+
return proxifyImageSrc(decodedImage, 0, 0, format);
|
|
1464
1483
|
}
|
|
1465
|
-
return proxifyImageSrc(
|
|
1484
|
+
return proxifyImageSrc(decodedImage, width, height, format);
|
|
1466
1485
|
}
|
|
1467
1486
|
if (meta && meta.image && !!meta.image.length && meta.image[0]) {
|
|
1487
|
+
if (typeof meta.image[0] === "string") {
|
|
1488
|
+
const decodedImage = he2.decode(meta.image[0]);
|
|
1489
|
+
if (isGifLink(decodedImage)) {
|
|
1490
|
+
return proxifyImageSrc(decodedImage, 0, 0, format);
|
|
1491
|
+
}
|
|
1492
|
+
return proxifyImageSrc(decodedImage, width, height, format);
|
|
1493
|
+
}
|
|
1468
1494
|
if (isGifLink(meta.image[0])) {
|
|
1469
1495
|
return proxifyImageSrc(meta.image[0], 0, 0, format);
|
|
1470
1496
|
}
|
|
@@ -1481,10 +1507,11 @@ function getImage(entry, width = 0, height = 0, format = "match") {
|
|
|
1481
1507
|
if (!src) {
|
|
1482
1508
|
return null;
|
|
1483
1509
|
}
|
|
1484
|
-
|
|
1485
|
-
|
|
1510
|
+
const decodedSrc = he2.decode(src);
|
|
1511
|
+
if (isGifLink(decodedSrc)) {
|
|
1512
|
+
return proxifyImageSrc(decodedSrc, 0, 0, format);
|
|
1486
1513
|
}
|
|
1487
|
-
return proxifyImageSrc(
|
|
1514
|
+
return proxifyImageSrc(decodedSrc, width, height, format);
|
|
1488
1515
|
}
|
|
1489
1516
|
return null;
|
|
1490
1517
|
}
|
|
@@ -1501,10 +1528,11 @@ function catchPostImage(obj, width = 0, height = 0, format = "match") {
|
|
|
1501
1528
|
if (!src) {
|
|
1502
1529
|
return null;
|
|
1503
1530
|
}
|
|
1504
|
-
|
|
1505
|
-
|
|
1531
|
+
const decodedSrc = he2.decode(src);
|
|
1532
|
+
if (isGifLink(decodedSrc)) {
|
|
1533
|
+
return proxifyImageSrc(decodedSrc, 0, 0, format);
|
|
1506
1534
|
}
|
|
1507
|
-
return proxifyImageSrc(
|
|
1535
|
+
return proxifyImageSrc(decodedSrc, width, height, format);
|
|
1508
1536
|
}
|
|
1509
1537
|
return null;
|
|
1510
1538
|
}
|
|
@@ -1593,7 +1621,7 @@ function postBodySummary(entryBody, length = 200, platform = "web") {
|
|
|
1593
1621
|
text2 = joint(text2.split(" "), length);
|
|
1594
1622
|
}
|
|
1595
1623
|
if (text2) {
|
|
1596
|
-
text2 =
|
|
1624
|
+
text2 = he2.decode(text2);
|
|
1597
1625
|
}
|
|
1598
1626
|
return text2;
|
|
1599
1627
|
}
|