@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,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 doc = DOMParser.parseFromString(`<body>${html}</body>`, "text/html");
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,7 +1417,7 @@ 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) {