@ecency/render-helper 2.4.13 → 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 +24 -4
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +25 -5
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +25 -5
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.cjs
CHANGED
|
@@ -193,10 +193,11 @@ var ALLOWED_ATTRIBUTES = {
|
|
|
193
193
|
"del": [],
|
|
194
194
|
"ins": []
|
|
195
195
|
};
|
|
196
|
-
var lenientErrorHandler = (level, msg) => {
|
|
197
|
-
if (process.env.NODE_ENV === "development"
|
|
196
|
+
var lenientErrorHandler = (level, msg, context) => {
|
|
197
|
+
if (process.env.NODE_ENV === "development") {
|
|
198
198
|
console.warn("[DOMParser]", level, msg);
|
|
199
199
|
}
|
|
200
|
+
return void 0;
|
|
200
201
|
};
|
|
201
202
|
var DOMParser = new xmldom.DOMParser({
|
|
202
203
|
// Use onError instead of deprecated errorHandler
|
|
@@ -205,11 +206,30 @@ var DOMParser = new xmldom.DOMParser({
|
|
|
205
206
|
});
|
|
206
207
|
|
|
207
208
|
// src/helper.ts
|
|
209
|
+
function removeDuplicateAttributes(html) {
|
|
210
|
+
const tagRegex = /<([a-zA-Z][a-zA-Z0-9]*)\s+((?:[^>"']+|"[^"]*"|'[^']*')*?)\s*(\/?)>/g;
|
|
211
|
+
return html.replace(tagRegex, (match, tagName, attrsString, selfClose) => {
|
|
212
|
+
const seenAttrs = /* @__PURE__ */ new Set();
|
|
213
|
+
const cleanedAttrs = [];
|
|
214
|
+
const attrRegex = /([a-zA-Z_:][-a-zA-Z0-9_:.]*)\s*(?:=\s*(?:"[^"]*"|'[^']*'|[^\s/>]+))?/g;
|
|
215
|
+
let attrMatch;
|
|
216
|
+
while ((attrMatch = attrRegex.exec(attrsString)) !== null) {
|
|
217
|
+
const attrName = attrMatch[1].toLowerCase();
|
|
218
|
+
if (!seenAttrs.has(attrName)) {
|
|
219
|
+
seenAttrs.add(attrName);
|
|
220
|
+
cleanedAttrs.push(attrMatch[0]);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
const attrsJoined = cleanedAttrs.length > 0 ? ` ${cleanedAttrs.join(" ")}` : "";
|
|
224
|
+
return `<${tagName}${attrsJoined}${selfClose ? " /" : ""}>`;
|
|
225
|
+
});
|
|
226
|
+
}
|
|
208
227
|
function createDoc(html) {
|
|
209
228
|
if (html.trim() === "") {
|
|
210
229
|
return null;
|
|
211
230
|
}
|
|
212
|
-
const
|
|
231
|
+
const cleanedHtml = removeDuplicateAttributes(html);
|
|
232
|
+
const doc = DOMParser.parseFromString(`<body>${cleanedHtml}</body>`, "text/html");
|
|
213
233
|
return doc;
|
|
214
234
|
}
|
|
215
235
|
function makeEntryCacheKey(entry) {
|
|
@@ -1416,7 +1436,7 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
|
|
|
1416
1436
|
try {
|
|
1417
1437
|
output = md.render(input);
|
|
1418
1438
|
output = fixBlockLevelTagsInParagraphs(output);
|
|
1419
|
-
const doc = DOMParser.parseFromString(`<body id="root">${output}</body>`, "text/html");
|
|
1439
|
+
const doc = DOMParser.parseFromString(`<body id="root">${removeDuplicateAttributes(output)}</body>`, "text/html");
|
|
1420
1440
|
traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain);
|
|
1421
1441
|
output = serializer.serializeToString(doc);
|
|
1422
1442
|
} catch (error) {
|
|
@@ -1429,7 +1449,7 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
|
|
|
1429
1449
|
lowerCaseAttributeNames: false
|
|
1430
1450
|
});
|
|
1431
1451
|
const repairedHtml = domSerializer(dom.children);
|
|
1432
|
-
const doc = DOMParser.parseFromString(`<body id="root">${repairedHtml}</body>`, "text/html");
|
|
1452
|
+
const doc = DOMParser.parseFromString(`<body id="root">${removeDuplicateAttributes(repairedHtml)}</body>`, "text/html");
|
|
1433
1453
|
traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain);
|
|
1434
1454
|
output = serializer.serializeToString(doc);
|
|
1435
1455
|
} catch (fallbackError) {
|