@ecency/render-helper 2.4.34 → 2.4.35
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 +103 -15
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +103 -15
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +103 -15
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.js
CHANGED
|
@@ -177,23 +177,112 @@ function createParser() {
|
|
|
177
177
|
var DOMParser = createParser();
|
|
178
178
|
|
|
179
179
|
// src/helper.ts
|
|
180
|
+
function isSpaceChar(c) {
|
|
181
|
+
return c === 32 || c === 9 || c === 10 || c === 13 || c === 12;
|
|
182
|
+
}
|
|
183
|
+
function isAsciiLetter(c) {
|
|
184
|
+
return c >= 65 && c <= 90 || c >= 97 && c <= 122;
|
|
185
|
+
}
|
|
186
|
+
function isTagNameChar(c) {
|
|
187
|
+
return isAsciiLetter(c) || c >= 48 && c <= 57;
|
|
188
|
+
}
|
|
189
|
+
function isAttrNameChar(c) {
|
|
190
|
+
return isAsciiLetter(c) || c >= 48 && c <= 57 || c === 45 || c === 95 || c === 58 || c === 46;
|
|
191
|
+
}
|
|
180
192
|
function removeDuplicateAttributes(html) {
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
193
|
+
const n = html.length;
|
|
194
|
+
let out = "";
|
|
195
|
+
let i = 0;
|
|
196
|
+
while (i < n) {
|
|
197
|
+
const lt = html.indexOf("<", i);
|
|
198
|
+
if (lt < 0) {
|
|
199
|
+
out += html.slice(i);
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
out += html.slice(i, lt);
|
|
203
|
+
if (lt + 1 >= n || !isAsciiLetter(html.charCodeAt(lt + 1))) {
|
|
204
|
+
out += "<";
|
|
205
|
+
i = lt + 1;
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
let p2 = lt + 1;
|
|
209
|
+
while (p2 < n && isTagNameChar(html.charCodeAt(p2))) p2++;
|
|
210
|
+
const tagName = html.slice(lt + 1, p2);
|
|
211
|
+
if (p2 >= n || !isSpaceChar(html.charCodeAt(p2))) {
|
|
212
|
+
out += "<";
|
|
213
|
+
i = lt + 1;
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
const attrs = [];
|
|
217
|
+
const seen = /* @__PURE__ */ new Set();
|
|
218
|
+
let q = p2;
|
|
219
|
+
while (q < n) {
|
|
220
|
+
while (q < n && isSpaceChar(html.charCodeAt(q))) q++;
|
|
221
|
+
if (q >= n) break;
|
|
222
|
+
const ch = html.charCodeAt(q);
|
|
223
|
+
if (ch === 62) break;
|
|
224
|
+
if (ch === 47 && q + 1 < n && html.charCodeAt(q + 1) === 62) break;
|
|
225
|
+
const nameStart = q;
|
|
226
|
+
while (q < n && isAttrNameChar(html.charCodeAt(q))) q++;
|
|
227
|
+
if (q === nameStart) {
|
|
228
|
+
q++;
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
const attrName = html.slice(nameStart, q);
|
|
232
|
+
let r = q;
|
|
233
|
+
while (r < n && isSpaceChar(html.charCodeAt(r))) r++;
|
|
234
|
+
let valueEnd = q;
|
|
235
|
+
if (r < n && html.charCodeAt(r) === 61) {
|
|
236
|
+
r++;
|
|
237
|
+
while (r < n && isSpaceChar(html.charCodeAt(r))) r++;
|
|
238
|
+
if (r < n) {
|
|
239
|
+
const v = html.charCodeAt(r);
|
|
240
|
+
if (v === 34 || v === 39) {
|
|
241
|
+
const quote = html[r];
|
|
242
|
+
const end = html.indexOf(quote, r + 1);
|
|
243
|
+
if (end < 0) {
|
|
244
|
+
const gt = html.indexOf(">", r + 1);
|
|
245
|
+
valueEnd = gt < 0 ? n : gt;
|
|
246
|
+
} else {
|
|
247
|
+
valueEnd = end + 1;
|
|
248
|
+
}
|
|
249
|
+
} else {
|
|
250
|
+
let s = r;
|
|
251
|
+
while (s < n) {
|
|
252
|
+
const k = html.charCodeAt(s);
|
|
253
|
+
if (isSpaceChar(k) || k === 62) break;
|
|
254
|
+
s++;
|
|
255
|
+
}
|
|
256
|
+
valueEnd = s;
|
|
257
|
+
}
|
|
258
|
+
} else {
|
|
259
|
+
valueEnd = r;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const fullAttr = html.slice(nameStart, valueEnd);
|
|
263
|
+
q = valueEnd;
|
|
264
|
+
const key = attrName.toLowerCase();
|
|
265
|
+
if (!seen.has(key)) {
|
|
266
|
+
seen.add(key);
|
|
267
|
+
attrs.push(fullAttr);
|
|
192
268
|
}
|
|
193
269
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
270
|
+
let selfClose = false;
|
|
271
|
+
if (q < n && html.charCodeAt(q) === 47) {
|
|
272
|
+
selfClose = true;
|
|
273
|
+
q++;
|
|
274
|
+
}
|
|
275
|
+
if (q >= n || html.charCodeAt(q) !== 62) {
|
|
276
|
+
out += "<";
|
|
277
|
+
i = lt + 1;
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
q++;
|
|
281
|
+
const attrsJoined = attrs.length > 0 ? " " + attrs.join(" ") : "";
|
|
282
|
+
out += "<" + tagName + attrsJoined + (selfClose ? " /" : "") + ">";
|
|
283
|
+
i = q;
|
|
284
|
+
}
|
|
285
|
+
return out;
|
|
197
286
|
}
|
|
198
287
|
function createDoc(html) {
|
|
199
288
|
if (html.trim() === "") {
|
|
@@ -1586,7 +1675,6 @@ function markdownToHTML(input, forApp, parentDomain = "ecency.com", seoContext,
|
|
|
1586
1675
|
output = serializer.serializeToString(doc);
|
|
1587
1676
|
} catch (error) {
|
|
1588
1677
|
try {
|
|
1589
|
-
output = md.render(input);
|
|
1590
1678
|
const preSanitized = sanitizeHtml(output);
|
|
1591
1679
|
const dom = htmlparser2.parseDocument(preSanitized, {
|
|
1592
1680
|
// lenient options - don't throw on malformed HTML
|