@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.
@@ -164,10 +164,11 @@ var ALLOWED_ATTRIBUTES = {
164
164
  "del": [],
165
165
  "ins": []
166
166
  };
167
- var lenientErrorHandler = (level, msg) => {
168
- if (process.env.NODE_ENV === "development" && level === "fatalError") {
167
+ var lenientErrorHandler = (level, msg, context) => {
168
+ if (process.env.NODE_ENV === "development") {
169
169
  console.warn("[DOMParser]", level, msg);
170
170
  }
171
+ return void 0;
171
172
  };
172
173
  var DOMParser = new DOMParser$1({
173
174
  // Use onError instead of deprecated errorHandler
@@ -176,11 +177,30 @@ var DOMParser = new DOMParser$1({
176
177
  });
177
178
 
178
179
  // src/helper.ts
180
+ function removeDuplicateAttributes(html) {
181
+ const tagRegex = /<([a-zA-Z][a-zA-Z0-9]*)\s+((?:[^>"']+|"[^"]*"|'[^']*')*?)\s*(\/?)>/g;
182
+ return html.replace(tagRegex, (match, tagName, attrsString, selfClose) => {
183
+ const seenAttrs = /* @__PURE__ */ new Set();
184
+ const cleanedAttrs = [];
185
+ const attrRegex = /([a-zA-Z_:][-a-zA-Z0-9_:.]*)\s*(?:=\s*(?:"[^"]*"|'[^']*'|[^\s/>]+))?/g;
186
+ let attrMatch;
187
+ while ((attrMatch = attrRegex.exec(attrsString)) !== null) {
188
+ const attrName = attrMatch[1].toLowerCase();
189
+ if (!seenAttrs.has(attrName)) {
190
+ seenAttrs.add(attrName);
191
+ cleanedAttrs.push(attrMatch[0]);
192
+ }
193
+ }
194
+ const attrsJoined = cleanedAttrs.length > 0 ? ` ${cleanedAttrs.join(" ")}` : "";
195
+ return `<${tagName}${attrsJoined}${selfClose ? " /" : ""}>`;
196
+ });
197
+ }
179
198
  function createDoc(html) {
180
199
  if (html.trim() === "") {
181
200
  return null;
182
201
  }
183
- const doc = DOMParser.parseFromString(`<body>${html}</body>`, "text/html");
202
+ const cleanedHtml = removeDuplicateAttributes(html);
203
+ const doc = DOMParser.parseFromString(`<body>${cleanedHtml}</body>`, "text/html");
184
204
  return doc;
185
205
  }
186
206
  function makeEntryCacheKey(entry) {
@@ -1387,7 +1407,7 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
1387
1407
  try {
1388
1408
  output = md.render(input);
1389
1409
  output = fixBlockLevelTagsInParagraphs(output);
1390
- const doc = DOMParser.parseFromString(`<body id="root">${output}</body>`, "text/html");
1410
+ const doc = DOMParser.parseFromString(`<body id="root">${removeDuplicateAttributes(output)}</body>`, "text/html");
1391
1411
  traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain);
1392
1412
  output = serializer.serializeToString(doc);
1393
1413
  } catch (error) {
@@ -1400,7 +1420,7 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
1400
1420
  lowerCaseAttributeNames: false
1401
1421
  });
1402
1422
  const repairedHtml = domSerializer(dom.children);
1403
- const doc = DOMParser.parseFromString(`<body id="root">${repairedHtml}</body>`, "text/html");
1423
+ const doc = DOMParser.parseFromString(`<body id="root">${removeDuplicateAttributes(repairedHtml)}</body>`, "text/html");
1404
1424
  traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain);
1405
1425
  output = serializer.serializeToString(doc);
1406
1426
  } catch (fallbackError) {