@aiquants/html-to-markdown 0.1.0 → 0.1.2

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.
@@ -1,3 +1,10 @@
1
+ import { Window } from "happy-dom";
2
+ const window = new Window();
3
+ Object.assign(global, {
4
+ document: window.document,
5
+ window,
6
+ self: window
7
+ });
1
8
  import { chromium } from "playwright";
2
9
  const messages = {
3
10
  "ja-JP": {
@@ -16,7 +23,8 @@ const messages = {
16
23
  playwright_close: "✅ ブラウザを閉じました。",
17
24
  playwright_error: "PlaywrightでのHTML取得中にエラーが発生しました:",
18
25
  convert_start: "🔄 HTMLからMarkdownへの変換を開始...",
19
- convert_success: "✅ Markdown変換が完了しました。"
26
+ convert_success: "✅ Markdown変換が完了しました。",
27
+ url_parse_error: "URLのパースに失敗しました:"
20
28
  },
21
29
  "en-US": {
22
30
  error_url_required: "Error: Please specify the URL to convert as an argument.",
@@ -34,7 +42,8 @@ const messages = {
34
42
  playwright_close: "✅ Browser closed.",
35
43
  playwright_error: "An error occurred while fetching HTML with Playwright:",
36
44
  convert_start: "🔄 Starting HTML to Markdown conversion...",
37
- convert_success: "✅ Markdown conversion completed."
45
+ convert_success: "✅ Markdown conversion completed.",
46
+ url_parse_error: "Failed to parse URL:"
38
47
  }
39
48
  };
40
49
  const getMessage = (locale, key2, replacements) => {
@@ -68,6 +77,55 @@ const getHtmlWithPlaywright = async (url, locale) => {
68
77
  }
69
78
  }
70
79
  };
80
+ const regex = /[\0-\x1F!-,\.\/:-@\[-\^`\{-\xA9\xAB-\xB4\xB6-\xB9\xBB-\xBF\xD7\xF7\u02C2-\u02C5\u02D2-\u02DF\u02E5-\u02EB\u02ED\u02EF-\u02FF\u0375\u0378\u0379\u037E\u0380-\u0385\u0387\u038B\u038D\u03A2\u03F6\u0482\u0530\u0557\u0558\u055A-\u055F\u0589-\u0590\u05BE\u05C0\u05C3\u05C6\u05C8-\u05CF\u05EB-\u05EE\u05F3-\u060F\u061B-\u061F\u066A-\u066D\u06D4\u06DD\u06DE\u06E9\u06FD\u06FE\u0700-\u070F\u074B\u074C\u07B2-\u07BF\u07F6-\u07F9\u07FB\u07FC\u07FE\u07FF\u082E-\u083F\u085C-\u085F\u086B-\u089F\u08B5\u08C8-\u08D2\u08E2\u0964\u0965\u0970\u0984\u098D\u098E\u0991\u0992\u09A9\u09B1\u09B3-\u09B5\u09BA\u09BB\u09C5\u09C6\u09C9\u09CA\u09CF-\u09D6\u09D8-\u09DB\u09DE\u09E4\u09E5\u09F2-\u09FB\u09FD\u09FF\u0A00\u0A04\u0A0B-\u0A0E\u0A11\u0A12\u0A29\u0A31\u0A34\u0A37\u0A3A\u0A3B\u0A3D\u0A43-\u0A46\u0A49\u0A4A\u0A4E-\u0A50\u0A52-\u0A58\u0A5D\u0A5F-\u0A65\u0A76-\u0A80\u0A84\u0A8E\u0A92\u0AA9\u0AB1\u0AB4\u0ABA\u0ABB\u0AC6\u0ACA\u0ACE\u0ACF\u0AD1-\u0ADF\u0AE4\u0AE5\u0AF0-\u0AF8\u0B00\u0B04\u0B0D\u0B0E\u0B11\u0B12\u0B29\u0B31\u0B34\u0B3A\u0B3B\u0B45\u0B46\u0B49\u0B4A\u0B4E-\u0B54\u0B58-\u0B5B\u0B5E\u0B64\u0B65\u0B70\u0B72-\u0B81\u0B84\u0B8B-\u0B8D\u0B91\u0B96-\u0B98\u0B9B\u0B9D\u0BA0-\u0BA2\u0BA5-\u0BA7\u0BAB-\u0BAD\u0BBA-\u0BBD\u0BC3-\u0BC5\u0BC9\u0BCE\u0BCF\u0BD1-\u0BD6\u0BD8-\u0BE5\u0BF0-\u0BFF\u0C0D\u0C11\u0C29\u0C3A-\u0C3C\u0C45\u0C49\u0C4E-\u0C54\u0C57\u0C5B-\u0C5F\u0C64\u0C65\u0C70-\u0C7F\u0C84\u0C8D\u0C91\u0CA9\u0CB4\u0CBA\u0CBB\u0CC5\u0CC9\u0CCE-\u0CD4\u0CD7-\u0CDD\u0CDF\u0CE4\u0CE5\u0CF0\u0CF3-\u0CFF\u0D0D\u0D11\u0D45\u0D49\u0D4F-\u0D53\u0D58-\u0D5E\u0D64\u0D65\u0D70-\u0D79\u0D80\u0D84\u0D97-\u0D99\u0DB2\u0DBC\u0DBE\u0DBF\u0DC7-\u0DC9\u0DCB-\u0DCE\u0DD5\u0DD7\u0DE0-\u0DE5\u0DF0\u0DF1\u0DF4-\u0E00\u0E3B-\u0E3F\u0E4F\u0E5A-\u0E80\u0E83\u0E85\u0E8B\u0EA4\u0EA6\u0EBE\u0EBF\u0EC5\u0EC7\u0ECE\u0ECF\u0EDA\u0EDB\u0EE0-\u0EFF\u0F01-\u0F17\u0F1A-\u0F1F\u0F2A-\u0F34\u0F36\u0F38\u0F3A-\u0F3D\u0F48\u0F6D-\u0F70\u0F85\u0F98\u0FBD-\u0FC5\u0FC7-\u0FFF\u104A-\u104F\u109E\u109F\u10C6\u10C8-\u10CC\u10CE\u10CF\u10FB\u1249\u124E\u124F\u1257\u1259\u125E\u125F\u1289\u128E\u128F\u12B1\u12B6\u12B7\u12BF\u12C1\u12C6\u12C7\u12D7\u1311\u1316\u1317\u135B\u135C\u1360-\u137F\u1390-\u139F\u13F6\u13F7\u13FE-\u1400\u166D\u166E\u1680\u169B-\u169F\u16EB-\u16ED\u16F9-\u16FF\u170D\u1715-\u171F\u1735-\u173F\u1754-\u175F\u176D\u1771\u1774-\u177F\u17D4-\u17D6\u17D8-\u17DB\u17DE\u17DF\u17EA-\u180A\u180E\u180F\u181A-\u181F\u1879-\u187F\u18AB-\u18AF\u18F6-\u18FF\u191F\u192C-\u192F\u193C-\u1945\u196E\u196F\u1975-\u197F\u19AC-\u19AF\u19CA-\u19CF\u19DA-\u19FF\u1A1C-\u1A1F\u1A5F\u1A7D\u1A7E\u1A8A-\u1A8F\u1A9A-\u1AA6\u1AA8-\u1AAF\u1AC1-\u1AFF\u1B4C-\u1B4F\u1B5A-\u1B6A\u1B74-\u1B7F\u1BF4-\u1BFF\u1C38-\u1C3F\u1C4A-\u1C4C\u1C7E\u1C7F\u1C89-\u1C8F\u1CBB\u1CBC\u1CC0-\u1CCF\u1CD3\u1CFB-\u1CFF\u1DFA\u1F16\u1F17\u1F1E\u1F1F\u1F46\u1F47\u1F4E\u1F4F\u1F58\u1F5A\u1F5C\u1F5E\u1F7E\u1F7F\u1FB5\u1FBD\u1FBF-\u1FC1\u1FC5\u1FCD-\u1FCF\u1FD4\u1FD5\u1FDC-\u1FDF\u1FED-\u1FF1\u1FF5\u1FFD-\u203E\u2041-\u2053\u2055-\u2070\u2072-\u207E\u2080-\u208F\u209D-\u20CF\u20F1-\u2101\u2103-\u2106\u2108\u2109\u2114\u2116-\u2118\u211E-\u2123\u2125\u2127\u2129\u212E\u213A\u213B\u2140-\u2144\u214A-\u214D\u214F-\u215F\u2189-\u24B5\u24EA-\u2BFF\u2C2F\u2C5F\u2CE5-\u2CEA\u2CF4-\u2CFF\u2D26\u2D28-\u2D2C\u2D2E\u2D2F\u2D68-\u2D6E\u2D70-\u2D7E\u2D97-\u2D9F\u2DA7\u2DAF\u2DB7\u2DBF\u2DC7\u2DCF\u2DD7\u2DDF\u2E00-\u2E2E\u2E30-\u3004\u3008-\u3020\u3030\u3036\u3037\u303D-\u3040\u3097\u3098\u309B\u309C\u30A0\u30FB\u3100-\u3104\u3130\u318F-\u319F\u31C0-\u31EF\u3200-\u33FF\u4DC0-\u4DFF\u9FFD-\u9FFF\uA48D-\uA4CF\uA4FE\uA4FF\uA60D-\uA60F\uA62C-\uA63F\uA673\uA67E\uA6F2-\uA716\uA720\uA721\uA789\uA78A\uA7C0\uA7C1\uA7CB-\uA7F4\uA828-\uA82B\uA82D-\uA83F\uA874-\uA87F\uA8C6-\uA8CF\uA8DA-\uA8DF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA954-\uA95F\uA97D-\uA97F\uA9C1-\uA9CE\uA9DA-\uA9DF\uA9FF\uAA37-\uAA3F\uAA4E\uAA4F\uAA5A-\uAA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0\uDCA1\uDCA3\uDCA4\uDCA7\uDCA8\uDCAD\uDCBA\uDCBC\uDCC4\uDD06\uDD0B\uDD0C\uDD15\uDD1D\uDD3A\uDD3F\uDD45\uDD47-\uDD49\uDD51\uDEA6\uDEA7\uDEC1\uDEDB\uDEFB\uDF15\uDF35\uDF4F\uDF6F\uDF89\uDFA9\uDFC3\uDFCC\uDFCD]|\uD836[\uDC00-\uDDFF\uDE37-\uDE3A\uDE6D-\uDE74\uDE76-\uDE83\uDE85-\uDE9A\uDEA0\uDEB0-\uDFFF]|\uD838[\uDC07\uDC19\uDC1A\uDC22\uDC25\uDC2B-\uDCFF\uDD2D-\uDD2F\uDD3E\uDD3F\uDD4A-\uDD4D\uDD4F-\uDEBF\uDEFA-\uDFFF]|\uD83A[\uDCC5-\uDCCF\uDCD7-\uDCFF\uDD4C-\uDD4F\uDD5A-\uDFFF]|\uD83B[\uDC00-\uDDFF\uDE04\uDE20\uDE23\uDE25\uDE26\uDE28\uDE33\uDE38\uDE3A\uDE3C-\uDE41\uDE43-\uDE46\uDE48\uDE4A\uDE4C\uDE50\uDE53\uDE55\uDE56\uDE58\uDE5A\uDE5C\uDE5E\uDE60\uDE63\uDE65\uDE66\uDE6B\uDE73\uDE78\uDE7D\uDE7F\uDE8A\uDE9C-\uDEA0\uDEA4\uDEAA\uDEBC-\uDFFF]|\uD83C[\uDC00-\uDD2F\uDD4A-\uDD4F\uDD6A-\uDD6F\uDD8A-\uDFFF]|\uD83E[\uDC00-\uDFEF\uDFFA-\uDFFF]|\uD869[\uDEDE-\uDEFF]|\uD86D[\uDF35-\uDF3F]|\uD86E[\uDC1E\uDC1F]|\uD873[\uDEA2-\uDEAF]|\uD87A[\uDFE1-\uDFFF]|\uD87E[\uDE1E-\uDFFF]|\uD884[\uDF4B-\uDFFF]|\uDB40[\uDC00-\uDCFF\uDDF0-\uDFFF]/g;
81
+ const own$a = Object.hasOwnProperty;
82
+ class BananaSlug {
83
+ /**
84
+ * Create a new slug class.
85
+ */
86
+ constructor() {
87
+ this.occurrences;
88
+ this.reset();
89
+ }
90
+ /**
91
+ * Generate a unique slug.
92
+ *
93
+ * Tracks previously generated slugs: repeated calls with the same value
94
+ * will result in different slugs.
95
+ * Use the `slug` function to get same slugs.
96
+ *
97
+ * @param {string} value
98
+ * String of text to slugify
99
+ * @param {boolean} [maintainCase=false]
100
+ * Keep the current case, otherwise make all lowercase
101
+ * @return {string}
102
+ * A unique slug string
103
+ */
104
+ slug(value, maintainCase) {
105
+ const self2 = this;
106
+ let result = slug(value, maintainCase === true);
107
+ const originalSlug = result;
108
+ while (own$a.call(self2.occurrences, result)) {
109
+ self2.occurrences[originalSlug]++;
110
+ result = originalSlug + "-" + self2.occurrences[originalSlug];
111
+ }
112
+ self2.occurrences[result] = 0;
113
+ return result;
114
+ }
115
+ /**
116
+ * Reset - Forget all previous slugs
117
+ *
118
+ * @return void
119
+ */
120
+ reset() {
121
+ this.occurrences = /* @__PURE__ */ Object.create(null);
122
+ }
123
+ }
124
+ function slug(value, maintainCase) {
125
+ if (typeof value !== "string") return "";
126
+ if (!maintainCase) value = value.toLowerCase();
127
+ return value.replace(regex, "").replace(/ /g, "-");
128
+ }
71
129
  const htmlVoidElements = [
72
130
  "area",
73
131
  "base",
@@ -207,7 +265,7 @@ function mark$1(values, key2, value) {
207
265
  values[key2] = value;
208
266
  }
209
267
  }
210
- function create$5(definition2) {
268
+ function create$4(definition2) {
211
269
  const properties = {};
212
270
  const normals = {};
213
271
  for (const [property, value] of Object.entries(definition2.properties)) {
@@ -226,7 +284,7 @@ function create$5(definition2) {
226
284
  }
227
285
  return new Schema$1(properties, normals, definition2.space);
228
286
  }
229
- const aria$1 = create$5({
287
+ const aria$1 = create$4({
230
288
  properties: {
231
289
  ariaActiveDescendant: null,
232
290
  ariaAtomic: booleanish$1,
@@ -288,7 +346,7 @@ function caseSensitiveTransform$1(attributes, attribute) {
288
346
  function caseInsensitiveTransform$1(attributes, property) {
289
347
  return caseSensitiveTransform$1(attributes, property.toLowerCase());
290
348
  }
291
- const html$6 = create$5({
349
+ const html$6 = create$4({
292
350
  attributes: {
293
351
  acceptcharset: "accept-charset",
294
352
  classname: "class",
@@ -650,7 +708,7 @@ const html$6 = create$5({
650
708
  space: "html",
651
709
  transform: caseInsensitiveTransform$1
652
710
  });
653
- const svg$3 = create$5({
711
+ const svg$3 = create$4({
654
712
  attributes: {
655
713
  accentHeight: "accent-height",
656
714
  alignmentBaseline: "alignment-baseline",
@@ -1210,7 +1268,7 @@ const svg$3 = create$5({
1210
1268
  space: "svg",
1211
1269
  transform: caseSensitiveTransform$1
1212
1270
  });
1213
- const xlink$1 = create$5({
1271
+ const xlink$1 = create$4({
1214
1272
  properties: {
1215
1273
  xLinkActuate: null,
1216
1274
  xLinkArcRole: null,
@@ -1225,13 +1283,13 @@ const xlink$1 = create$5({
1225
1283
  return "xlink:" + property.slice(5).toLowerCase();
1226
1284
  }
1227
1285
  });
1228
- const xmlns$1 = create$5({
1286
+ const xmlns$1 = create$4({
1229
1287
  attributes: { xmlnsxlink: "xmlns:xlink" },
1230
1288
  properties: { xmlnsXLink: null, xmlns: null },
1231
1289
  space: "xmlns",
1232
1290
  transform: caseInsensitiveTransform$1
1233
1291
  });
1234
- const xml$1 = create$5({
1292
+ const xml$1 = create$4({
1235
1293
  properties: { xmlBase: null, xmlLang: null, xmlSpace: null },
1236
1294
  space: "xml",
1237
1295
  transform(_, property) {
@@ -1274,15 +1332,15 @@ function camelcase$2($0) {
1274
1332
  }
1275
1333
  const html$5 = merge$1([aria$1, html$6, xlink$1, xmlns$1, xml$1], "html");
1276
1334
  const svg$2 = merge$1([aria$1, svg$3, xlink$1, xmlns$1, xml$1], "svg");
1277
- const own$a = {}.hasOwnProperty;
1335
+ const own$9 = {}.hasOwnProperty;
1278
1336
  function zwitch(key2, options) {
1279
1337
  const settings = options || {};
1280
1338
  function one2(value, ...parameters) {
1281
1339
  let fn = one2.invalid;
1282
1340
  const handlers2 = one2.handlers;
1283
- if (value && own$a.call(value, key2)) {
1341
+ if (value && own$9.call(value, key2)) {
1284
1342
  const id = String(value[key2]);
1285
- fn = own$a.call(handlers2, id) ? handlers2[id] : one2.unknown;
1343
+ fn = own$9.call(handlers2, id) ? handlers2[id] : one2.unknown;
1286
1344
  }
1287
1345
  if (fn) {
1288
1346
  return fn.call(this, value, ...parameters);
@@ -1723,18 +1781,18 @@ const dangerous = [
1723
1781
  "para",
1724
1782
  "times"
1725
1783
  ];
1726
- const own$9 = {}.hasOwnProperty;
1784
+ const own$8 = {}.hasOwnProperty;
1727
1785
  const characters = {};
1728
1786
  let key;
1729
1787
  for (key in characterEntitiesHtml4) {
1730
- if (own$9.call(characterEntitiesHtml4, key)) {
1788
+ if (own$8.call(characterEntitiesHtml4, key)) {
1731
1789
  characters[characterEntitiesHtml4[key]] = key;
1732
1790
  }
1733
1791
  }
1734
1792
  const notAlphanumericRegex = /[^\dA-Za-z]/;
1735
1793
  function toNamed(code2, next2, omit, attribute) {
1736
1794
  const character = String.fromCharCode(code2);
1737
- if (own$9.call(characters, character)) {
1795
+ if (own$8.call(characters, character)) {
1738
1796
  const name = characters[character];
1739
1797
  const value = "&" + name;
1740
1798
  if (omit && characterEntitiesLegacy.includes(name) && !dangerous.includes(name) && (!attribute || next2 && next2 !== 61 && notAlphanumericRegex.test(String.fromCharCode(next2)))) {
@@ -1860,11 +1918,11 @@ function siblings(increment2) {
1860
1918
  return next2;
1861
1919
  }
1862
1920
  }
1863
- const own$8 = {}.hasOwnProperty;
1921
+ const own$7 = {}.hasOwnProperty;
1864
1922
  function omission(handlers2) {
1865
1923
  return omit;
1866
1924
  function omit(node2, index2, parent) {
1867
- return own$8.call(handlers2, node2.tagName) && handlers2[node2.tagName](node2, index2, parent);
1925
+ return own$7.call(handlers2, node2.tagName) && handlers2[node2.tagName](node2, index2, parent);
1868
1926
  }
1869
1927
  }
1870
1928
  const closing = omission({
@@ -2149,11 +2207,11 @@ function unknown$2(node_) {
2149
2207
  );
2150
2208
  throw new Error("Cannot compile unknown node `" + node2.type + "`");
2151
2209
  }
2152
- const emptyOptions$8 = {};
2210
+ const emptyOptions$7 = {};
2153
2211
  const emptyCharacterReferences = {};
2154
2212
  const emptyChildren = [];
2155
2213
  function toHtml(tree, options) {
2156
- const options_ = options || emptyOptions$8;
2214
+ const options_ = options || emptyOptions$7;
2157
2215
  const quote = options_.quote || '"';
2158
2216
  const alternative = quote === '"' ? "'" : '"';
2159
2217
  if (quote !== '"' && quote !== "'") {
@@ -2203,665 +2261,65 @@ function all$8(parent) {
2203
2261
  }
2204
2262
  return results.join("");
2205
2263
  }
2206
- const VOID = -1;
2207
- const PRIMITIVE = 0;
2208
- const ARRAY = 1;
2209
- const OBJECT = 2;
2210
- const DATE = 3;
2211
- const REGEXP = 4;
2212
- const MAP = 5;
2213
- const SET = 6;
2214
- const ERROR = 7;
2215
- const BIGINT = 8;
2216
- const env = typeof self === "object" ? self : globalThis;
2217
- const deserializer = ($2, _) => {
2218
- const as = (out, index2) => {
2219
- $2.set(index2, out);
2220
- return out;
2221
- };
2222
- const unpair = (index2) => {
2223
- if ($2.has(index2))
2224
- return $2.get(index2);
2225
- const [type, value] = _[index2];
2226
- switch (type) {
2227
- case PRIMITIVE:
2228
- case VOID:
2229
- return as(value, index2);
2230
- case ARRAY: {
2231
- const arr = as([], index2);
2232
- for (const index3 of value)
2233
- arr.push(unpair(index3));
2234
- return arr;
2235
- }
2236
- case OBJECT: {
2237
- const object = as({}, index2);
2238
- for (const [key2, index3] of value)
2239
- object[unpair(key2)] = unpair(index3);
2240
- return object;
2241
- }
2242
- case DATE:
2243
- return as(new Date(value), index2);
2244
- case REGEXP: {
2245
- const { source, flags } = value;
2246
- return as(new RegExp(source, flags), index2);
2247
- }
2248
- case MAP: {
2249
- const map2 = as(/* @__PURE__ */ new Map(), index2);
2250
- for (const [key2, index3] of value)
2251
- map2.set(unpair(key2), unpair(index3));
2252
- return map2;
2253
- }
2254
- case SET: {
2255
- const set = as(/* @__PURE__ */ new Set(), index2);
2256
- for (const index3 of value)
2257
- set.add(unpair(index3));
2258
- return set;
2259
- }
2260
- case ERROR: {
2261
- const { name, message } = value;
2262
- return as(new env[name](message), index2);
2263
- }
2264
- case BIGINT:
2265
- return as(BigInt(value), index2);
2266
- case "BigInt":
2267
- return as(Object(BigInt(value)), index2);
2268
- case "ArrayBuffer":
2269
- return as(new Uint8Array(value).buffer, value);
2270
- case "DataView": {
2271
- const { buffer } = new Uint8Array(value);
2272
- return as(new DataView(buffer), value);
2264
+ function ok$1() {
2265
+ }
2266
+ const search = /[#.]/g;
2267
+ function parseSelector(selector, defaultTagName) {
2268
+ const value = selector || "";
2269
+ const props = {};
2270
+ let start = 0;
2271
+ let previous2;
2272
+ let tagName;
2273
+ while (start < value.length) {
2274
+ search.lastIndex = start;
2275
+ const match = search.exec(value);
2276
+ const subvalue = value.slice(start, match ? match.index : value.length);
2277
+ if (subvalue) {
2278
+ if (!previous2) {
2279
+ tagName = subvalue;
2280
+ } else if (previous2 === "#") {
2281
+ props.id = subvalue;
2282
+ } else if (Array.isArray(props.className)) {
2283
+ props.className.push(subvalue);
2284
+ } else {
2285
+ props.className = [subvalue];
2273
2286
  }
2287
+ start += subvalue.length;
2288
+ }
2289
+ if (match) {
2290
+ previous2 = match[0];
2291
+ start++;
2274
2292
  }
2275
- return as(new env[type](value), index2);
2276
- };
2277
- return unpair;
2278
- };
2279
- const deserialize = (serialized) => deserializer(/* @__PURE__ */ new Map(), serialized)(0);
2280
- const EMPTY = "";
2281
- const { toString: toString$2 } = {};
2282
- const { keys } = Object;
2283
- const typeOf = (value) => {
2284
- const type = typeof value;
2285
- if (type !== "object" || !value)
2286
- return [PRIMITIVE, type];
2287
- const asString = toString$2.call(value).slice(8, -1);
2288
- switch (asString) {
2289
- case "Array":
2290
- return [ARRAY, EMPTY];
2291
- case "Object":
2292
- return [OBJECT, EMPTY];
2293
- case "Date":
2294
- return [DATE, EMPTY];
2295
- case "RegExp":
2296
- return [REGEXP, EMPTY];
2297
- case "Map":
2298
- return [MAP, EMPTY];
2299
- case "Set":
2300
- return [SET, EMPTY];
2301
- case "DataView":
2302
- return [ARRAY, asString];
2303
2293
  }
2304
- if (asString.includes("Array"))
2305
- return [ARRAY, asString];
2306
- if (asString.includes("Error"))
2307
- return [ERROR, asString];
2308
- return [OBJECT, asString];
2309
- };
2310
- const shouldSkip = ([TYPE, type]) => TYPE === PRIMITIVE && (type === "function" || type === "symbol");
2311
- const serializer = (strict, json, $2, _) => {
2312
- const as = (out, value) => {
2313
- const index2 = _.push(out) - 1;
2314
- $2.set(value, index2);
2315
- return index2;
2294
+ return {
2295
+ type: "element",
2296
+ // @ts-expect-error: tag name is parsed.
2297
+ tagName: tagName || defaultTagName || "div",
2298
+ properties: props,
2299
+ children: []
2316
2300
  };
2317
- const pair = (value) => {
2318
- if ($2.has(value))
2319
- return $2.get(value);
2320
- let [TYPE, type] = typeOf(value);
2321
- switch (TYPE) {
2322
- case PRIMITIVE: {
2323
- let entry = value;
2324
- switch (type) {
2325
- case "bigint":
2326
- TYPE = BIGINT;
2327
- entry = value.toString();
2328
- break;
2329
- case "function":
2330
- case "symbol":
2331
- if (strict)
2332
- throw new TypeError("unable to serialize " + type);
2333
- entry = null;
2334
- break;
2335
- case "undefined":
2336
- return as([VOID], value);
2337
- }
2338
- return as([TYPE, entry], value);
2339
- }
2340
- case ARRAY: {
2341
- if (type) {
2342
- let spread = value;
2343
- if (type === "DataView") {
2344
- spread = new Uint8Array(value.buffer);
2345
- } else if (type === "ArrayBuffer") {
2346
- spread = new Uint8Array(value);
2347
- }
2348
- return as([type, [...spread]], value);
2349
- }
2350
- const arr = [];
2351
- const index2 = as([TYPE, arr], value);
2352
- for (const entry of value)
2353
- arr.push(pair(entry));
2354
- return index2;
2355
- }
2356
- case OBJECT: {
2357
- if (type) {
2358
- switch (type) {
2359
- case "BigInt":
2360
- return as([type, value.toString()], value);
2361
- case "Boolean":
2362
- case "Number":
2363
- case "String":
2364
- return as([type, value.valueOf()], value);
2365
- }
2366
- }
2367
- if (json && "toJSON" in value)
2368
- return pair(value.toJSON());
2369
- const entries = [];
2370
- const index2 = as([TYPE, entries], value);
2371
- for (const key2 of keys(value)) {
2372
- if (strict || !shouldSkip(typeOf(value[key2])))
2373
- entries.push([pair(key2), pair(value[key2])]);
2374
- }
2375
- return index2;
2376
- }
2377
- case DATE:
2378
- return as([TYPE, value.toISOString()], value);
2379
- case REGEXP: {
2380
- const { source, flags } = value;
2381
- return as([TYPE, { source, flags }], value);
2382
- }
2383
- case MAP: {
2384
- const entries = [];
2385
- const index2 = as([TYPE, entries], value);
2386
- for (const [key2, entry] of value) {
2387
- if (strict || !(shouldSkip(typeOf(key2)) || shouldSkip(typeOf(entry))))
2388
- entries.push([pair(key2), pair(entry)]);
2389
- }
2390
- return index2;
2391
- }
2392
- case SET: {
2393
- const entries = [];
2394
- const index2 = as([TYPE, entries], value);
2395
- for (const entry of value) {
2396
- if (strict || !shouldSkip(typeOf(entry)))
2397
- entries.push(pair(entry));
2398
- }
2399
- return index2;
2400
- }
2401
- }
2402
- const { message } = value;
2403
- return as([TYPE, { name: type, message }], value);
2404
- };
2405
- return pair;
2406
- };
2407
- const serialize$1 = (value, { json, lossy } = {}) => {
2408
- const _ = [];
2409
- return serializer(!(json || lossy), !!json, /* @__PURE__ */ new Map(), _)(value), _;
2410
- };
2411
- const structuredClone$1 = typeof structuredClone === "function" ? (
2412
- /* c8 ignore start */
2413
- (any, options) => options && ("json" in options || "lossy" in options) ? deserialize(serialize$1(any, options)) : structuredClone(any)
2414
- ) : (any, options) => deserialize(serialize$1(any, options));
2415
- function headingRank(node2) {
2416
- const name = node2.type === "element" ? node2.tagName.toLowerCase() : "";
2417
- const code2 = name.length === 2 && name.charCodeAt(0) === 104 ? name.charCodeAt(1) : 0;
2418
- return code2 > 48 && code2 < 55 ? code2 - 48 : void 0;
2419
- }
2420
- const isElement = (
2421
- // Note: overloads in JSDoc can’t yet use different `@template`s.
2422
- /**
2423
- * @type {(
2424
- * (<Condition extends TestFunction>(element: unknown, test: Condition, index?: number | null | undefined, parent?: Parents | null | undefined, context?: unknown) => element is Element & Predicate<Condition, Element>) &
2425
- * (<Condition extends string>(element: unknown, test: Condition, index?: number | null | undefined, parent?: Parents | null | undefined, context?: unknown) => element is Element & {tagName: Condition}) &
2426
- * ((element?: null | undefined) => false) &
2427
- * ((element: unknown, test?: null | undefined, index?: number | null | undefined, parent?: Parents | null | undefined, context?: unknown) => element is Element) &
2428
- * ((element: unknown, test?: Test, index?: number | null | undefined, parent?: Parents | null | undefined, context?: unknown) => boolean)
2429
- * )}
2430
- */
2431
- /**
2432
- * @param {unknown} [element]
2433
- * @param {Test | undefined} [test]
2434
- * @param {number | null | undefined} [index]
2435
- * @param {Parents | null | undefined} [parent]
2436
- * @param {unknown} [context]
2437
- * @returns {boolean}
2438
- */
2439
- // eslint-disable-next-line max-params
2440
- function(element2, test, index2, parent, context) {
2441
- const check = convertElement(test);
2442
- return looksLikeAnElement(element2) ? check.call(context, element2, index2, parent) : false;
2443
- }
2444
- );
2445
- const convertElement = (
2446
- // Note: overloads in JSDoc can’t yet use different `@template`s.
2447
- /**
2448
- * @type {(
2449
- * (<Condition extends TestFunction>(test: Condition) => (element: unknown, index?: number | null | undefined, parent?: Parents | null | undefined, context?: unknown) => element is Element & Predicate<Condition, Element>) &
2450
- * (<Condition extends string>(test: Condition) => (element: unknown, index?: number | null | undefined, parent?: Parents | null | undefined, context?: unknown) => element is Element & {tagName: Condition}) &
2451
- * ((test?: null | undefined) => (element?: unknown, index?: number | null | undefined, parent?: Parents | null | undefined, context?: unknown) => element is Element) &
2452
- * ((test?: Test) => Check)
2453
- * )}
2454
- */
2455
- /**
2456
- * @param {Test | null | undefined} [test]
2457
- * @returns {Check}
2458
- */
2459
- function(test) {
2460
- if (test === null || test === void 0) {
2461
- return element$4;
2462
- }
2463
- if (typeof test === "string") {
2464
- return tagNameFactory(test);
2465
- }
2466
- if (typeof test === "object") {
2467
- return anyFactory$1(test);
2468
- }
2469
- if (typeof test === "function") {
2470
- return castFactory$1(test);
2471
- }
2472
- throw new Error("Expected function, string, or array as `test`");
2473
- }
2474
- );
2475
- function anyFactory$1(tests) {
2476
- const checks2 = [];
2477
- let index2 = -1;
2478
- while (++index2 < tests.length) {
2479
- checks2[index2] = convertElement(tests[index2]);
2480
- }
2481
- return castFactory$1(any);
2482
- function any(...parameters) {
2483
- let index3 = -1;
2484
- while (++index3 < checks2.length) {
2485
- if (checks2[index3].apply(this, parameters)) return true;
2486
- }
2487
- return false;
2488
- }
2489
- }
2490
- function tagNameFactory(check) {
2491
- return castFactory$1(tagName);
2492
- function tagName(element2) {
2493
- return element2.tagName === check;
2494
- }
2495
- }
2496
- function castFactory$1(testFunction) {
2497
- return check;
2498
- function check(value, index2, parent) {
2499
- return Boolean(
2500
- looksLikeAnElement(value) && testFunction.call(
2501
- this,
2502
- value,
2503
- typeof index2 === "number" ? index2 : void 0,
2504
- parent || void 0
2505
- )
2506
- );
2507
- }
2508
- }
2509
- function element$4(element2) {
2510
- return Boolean(
2511
- element2 && typeof element2 === "object" && "type" in element2 && element2.type === "element" && "tagName" in element2 && typeof element2.tagName === "string"
2512
- );
2513
- }
2514
- function looksLikeAnElement(value) {
2515
- return value !== null && typeof value === "object" && "type" in value && "tagName" in value;
2516
- }
2517
- const convert = (
2518
- // Note: overloads in JSDoc can’t yet use different `@template`s.
2519
- /**
2520
- * @type {(
2521
- * (<Condition extends string>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition}) &
2522
- * (<Condition extends Props>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Condition) &
2523
- * (<Condition extends TestFunction>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Predicate<Condition, Node>) &
2524
- * ((test?: null | undefined) => (node?: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node) &
2525
- * ((test?: Test) => Check)
2526
- * )}
2527
- */
2528
- /**
2529
- * @param {Test} [test]
2530
- * @returns {Check}
2531
- */
2532
- function(test) {
2533
- if (test === null || test === void 0) {
2534
- return ok$1;
2535
- }
2536
- if (typeof test === "function") {
2537
- return castFactory(test);
2538
- }
2539
- if (typeof test === "object") {
2540
- return Array.isArray(test) ? anyFactory(test) : propsFactory(test);
2541
- }
2542
- if (typeof test === "string") {
2543
- return typeFactory(test);
2544
- }
2545
- throw new Error("Expected function, string, or object as test");
2546
- }
2547
- );
2548
- function anyFactory(tests) {
2549
- const checks2 = [];
2550
- let index2 = -1;
2551
- while (++index2 < tests.length) {
2552
- checks2[index2] = convert(tests[index2]);
2553
- }
2554
- return castFactory(any);
2555
- function any(...parameters) {
2556
- let index3 = -1;
2557
- while (++index3 < checks2.length) {
2558
- if (checks2[index3].apply(this, parameters)) return true;
2559
- }
2560
- return false;
2561
- }
2562
- }
2563
- function propsFactory(check) {
2564
- const checkAsRecord = (
2565
- /** @type {Record<string, unknown>} */
2566
- check
2567
- );
2568
- return castFactory(all2);
2569
- function all2(node2) {
2570
- const nodeAsRecord = (
2571
- /** @type {Record<string, unknown>} */
2572
- /** @type {unknown} */
2573
- node2
2574
- );
2575
- let key2;
2576
- for (key2 in check) {
2577
- if (nodeAsRecord[key2] !== checkAsRecord[key2]) return false;
2578
- }
2579
- return true;
2580
- }
2581
- }
2582
- function typeFactory(check) {
2583
- return castFactory(type);
2584
- function type(node2) {
2585
- return node2 && node2.type === check;
2586
- }
2587
- }
2588
- function castFactory(testFunction) {
2589
- return check;
2590
- function check(value, index2, parent) {
2591
- return Boolean(
2592
- looksLikeANode(value) && testFunction.call(
2593
- this,
2594
- value,
2595
- typeof index2 === "number" ? index2 : void 0,
2596
- parent || void 0
2597
- )
2598
- );
2599
- }
2600
- }
2601
- function ok$1() {
2602
- return true;
2603
- }
2604
- function looksLikeANode(value) {
2605
- return value !== null && typeof value === "object" && "type" in value;
2606
- }
2607
- function color(d) {
2608
- return d;
2609
- }
2610
- const empty = [];
2611
- const CONTINUE = true;
2612
- const EXIT = false;
2613
- const SKIP = "skip";
2614
- function visitParents(tree, test, visitor, reverse) {
2615
- let check;
2616
- if (typeof test === "function" && typeof visitor !== "function") {
2617
- reverse = visitor;
2618
- visitor = test;
2619
- } else {
2620
- check = test;
2621
- }
2622
- const is = convert(check);
2623
- const step = reverse ? -1 : 1;
2624
- factory(tree, void 0, [])();
2625
- function factory(node2, index2, parents) {
2626
- const value = (
2627
- /** @type {Record<string, unknown>} */
2628
- node2 && typeof node2 === "object" ? node2 : {}
2629
- );
2630
- if (typeof value.type === "string") {
2631
- const name = (
2632
- // `hast`
2633
- typeof value.tagName === "string" ? value.tagName : (
2634
- // `xast`
2635
- typeof value.name === "string" ? value.name : void 0
2636
- )
2637
- );
2638
- Object.defineProperty(visit2, "name", {
2639
- value: "node (" + color(node2.type + (name ? "<" + name + ">" : "")) + ")"
2640
- });
2641
- }
2642
- return visit2;
2643
- function visit2() {
2644
- let result = empty;
2645
- let subresult;
2646
- let offset;
2647
- let grandparents;
2648
- if (!test || is(node2, index2, parents[parents.length - 1] || void 0)) {
2649
- result = toResult(visitor(node2, parents));
2650
- if (result[0] === EXIT) {
2651
- return result;
2652
- }
2653
- }
2654
- if ("children" in node2 && node2.children) {
2655
- const nodeAsParent = (
2656
- /** @type {UnistParent} */
2657
- node2
2658
- );
2659
- if (nodeAsParent.children && result[0] !== SKIP) {
2660
- offset = (reverse ? nodeAsParent.children.length : -1) + step;
2661
- grandparents = parents.concat(nodeAsParent);
2662
- while (offset > -1 && offset < nodeAsParent.children.length) {
2663
- const child = nodeAsParent.children[offset];
2664
- subresult = factory(child, offset, grandparents)();
2665
- if (subresult[0] === EXIT) {
2666
- return subresult;
2667
- }
2668
- offset = typeof subresult[1] === "number" ? subresult[1] : offset + step;
2669
- }
2670
- }
2671
- }
2672
- return result;
2673
- }
2674
- }
2675
- }
2676
- function toResult(value) {
2677
- if (Array.isArray(value)) {
2678
- return value;
2679
- }
2680
- if (typeof value === "number") {
2681
- return [CONTINUE, value];
2682
- }
2683
- return value === null || value === void 0 ? empty : [value];
2684
- }
2685
- function visit(tree, testOrVisitor, visitorOrReverse, maybeReverse) {
2686
- let reverse;
2687
- let test;
2688
- let visitor;
2689
- if (typeof testOrVisitor === "function" && typeof visitorOrReverse !== "function") {
2690
- test = void 0;
2691
- visitor = testOrVisitor;
2692
- reverse = visitorOrReverse;
2693
- } else {
2694
- test = testOrVisitor;
2695
- visitor = visitorOrReverse;
2696
- reverse = maybeReverse;
2697
- }
2698
- visitParents(tree, test, overload, reverse);
2699
- function overload(node2, parents) {
2700
- const parent = parents[parents.length - 1];
2701
- const index2 = parent ? parent.children.indexOf(node2) : void 0;
2702
- return visitor(node2, index2, parent);
2703
- }
2704
- }
2705
- const contentDefaults = {
2706
- type: "element",
2707
- tagName: "span",
2708
- properties: { className: ["icon", "icon-link"] },
2709
- children: []
2710
- };
2711
- const emptyOptions$7 = {};
2712
- function rehypeAutolinkHeadings(options) {
2713
- const settings = options || emptyOptions$7;
2714
- let properties = settings.properties;
2715
- const headingOroperties = settings.headingProperties;
2716
- const behavior = settings.behavior || "prepend";
2717
- const content2 = settings.content;
2718
- const group = settings.group;
2719
- const is = convertElement(settings.test);
2720
- let method;
2721
- if (behavior === "after" || behavior === "before") {
2722
- method = around;
2723
- } else if (behavior === "wrap") {
2724
- method = wrap2;
2725
- } else {
2726
- method = inject;
2727
- if (!properties) {
2728
- properties = { ariaHidden: "true", tabIndex: -1 };
2729
- }
2730
- }
2731
- return function(tree) {
2732
- visit(tree, "element", function(node2, index2, parent) {
2733
- if (headingRank(node2) && node2.properties.id && is(node2, index2, parent)) {
2734
- Object.assign(node2.properties, toProperties(headingOroperties, node2));
2735
- return method(node2, index2, parent);
2736
- }
2737
- });
2738
- };
2739
- function inject(node2) {
2740
- const children = toChildren(content2 || contentDefaults, node2);
2741
- node2.children[behavior === "prepend" ? "unshift" : "push"](
2742
- create$4(node2, toProperties(properties, node2), children)
2743
- );
2744
- return [SKIP];
2745
- }
2746
- function around(node2, index2, parent) {
2747
- if (typeof index2 !== "number" || !parent) return;
2748
- const children = toChildren(content2 || contentDefaults, node2);
2749
- const link2 = create$4(node2, toProperties(properties, node2), children);
2750
- let nodes = behavior === "before" ? [link2, node2] : [node2, link2];
2751
- if (group) {
2752
- const grouping = toNode(group, node2);
2753
- if (grouping && !Array.isArray(grouping) && grouping.type === "element") {
2754
- grouping.children = nodes;
2755
- nodes = [grouping];
2756
- }
2757
- }
2758
- parent.children.splice(index2, 1, ...nodes);
2759
- return [SKIP, index2 + nodes.length];
2760
- }
2761
- function wrap2(node2) {
2762
- let before = node2.children;
2763
- let after = [];
2764
- if (typeof content2 === "function") {
2765
- before = [];
2766
- after = content2(node2);
2767
- } else if (content2) {
2768
- after = clone(content2);
2769
- }
2770
- node2.children = [
2771
- create$4(
2772
- node2,
2773
- toProperties(properties, node2),
2774
- Array.isArray(after) ? [...before, ...after] : [...before, after]
2775
- )
2776
- ];
2777
- return [SKIP];
2778
- }
2779
- }
2780
- function clone(thing) {
2781
- return (
2782
- /** @type {Cloneable<T>} */
2783
- structuredClone$1(thing)
2784
- );
2785
- }
2786
- function create$4(node2, properties, children) {
2787
- return {
2788
- type: "element",
2789
- tagName: "a",
2790
- properties: { ...properties, href: "#" + node2.properties.id },
2791
- children
2792
- };
2793
- }
2794
- function toChildren(value, node2) {
2795
- const result = toNode(value, node2);
2796
- return Array.isArray(result) ? result : [result];
2797
- }
2798
- function toNode(value, node2) {
2799
- if (typeof value === "function") return value(node2);
2800
- return clone(value);
2801
- }
2802
- function toProperties(value, node2) {
2803
- if (typeof value === "function") return value(node2);
2804
- return value ? clone(value) : {};
2805
- }
2806
- function ok() {
2807
- }
2808
- const search = /[#.]/g;
2809
- function parseSelector(selector, defaultTagName) {
2810
- const value = selector || "";
2811
- const props = {};
2812
- let start = 0;
2813
- let previous2;
2814
- let tagName;
2815
- while (start < value.length) {
2816
- search.lastIndex = start;
2817
- const match = search.exec(value);
2818
- const subvalue = value.slice(start, match ? match.index : value.length);
2819
- if (subvalue) {
2820
- if (!previous2) {
2821
- tagName = subvalue;
2822
- } else if (previous2 === "#") {
2823
- props.id = subvalue;
2824
- } else if (Array.isArray(props.className)) {
2825
- props.className.push(subvalue);
2826
- } else {
2827
- props.className = [subvalue];
2828
- }
2829
- start += subvalue.length;
2830
- }
2831
- if (match) {
2832
- previous2 = match[0];
2833
- start++;
2834
- }
2835
- }
2836
- return {
2837
- type: "element",
2838
- // @ts-expect-error: tag name is parsed.
2839
- tagName: tagName || defaultTagName || "div",
2840
- properties: props,
2841
- children: []
2842
- };
2843
- }
2844
- function createH(schema, defaultTagName, caseSensitive) {
2845
- const adjust = caseSensitive ? createAdjustMap(caseSensitive) : void 0;
2846
- function h2(selector, properties, ...children) {
2847
- let node2;
2848
- if (selector === null || selector === void 0) {
2849
- node2 = { type: "root", children: [] };
2850
- const child = (
2851
- /** @type {Child} */
2852
- properties
2853
- );
2854
- children.unshift(child);
2855
- } else {
2856
- node2 = parseSelector(selector, defaultTagName);
2857
- const lower = node2.tagName.toLowerCase();
2858
- const adjusted = adjust ? adjust.get(lower) : void 0;
2859
- node2.tagName = adjusted || lower;
2860
- if (isChild(properties)) {
2861
- children.unshift(properties);
2862
- } else {
2863
- for (const [key2, value] of Object.entries(properties)) {
2864
- addProperty(schema, node2.properties, key2, value);
2301
+ }
2302
+ function createH(schema, defaultTagName, caseSensitive) {
2303
+ const adjust = caseSensitive ? createAdjustMap(caseSensitive) : void 0;
2304
+ function h2(selector, properties, ...children) {
2305
+ let node2;
2306
+ if (selector === null || selector === void 0) {
2307
+ node2 = { type: "root", children: [] };
2308
+ const child = (
2309
+ /** @type {Child} */
2310
+ properties
2311
+ );
2312
+ children.unshift(child);
2313
+ } else {
2314
+ node2 = parseSelector(selector, defaultTagName);
2315
+ const lower = node2.tagName.toLowerCase();
2316
+ const adjusted = adjust ? adjust.get(lower) : void 0;
2317
+ node2.tagName = adjusted || lower;
2318
+ if (isChild(properties)) {
2319
+ children.unshift(properties);
2320
+ } else {
2321
+ for (const [key2, value] of Object.entries(properties)) {
2322
+ addProperty(schema, node2.properties, key2, value);
2865
2323
  }
2866
2324
  }
2867
2325
  }
@@ -3088,7 +2546,7 @@ const webNamespaces = {
3088
2546
  xml: "http://www.w3.org/XML/1998/namespace",
3089
2547
  xmlns: "http://www.w3.org/2000/xmlns/"
3090
2548
  };
3091
- const own$7 = {}.hasOwnProperty;
2549
+ const own$6 = {}.hasOwnProperty;
3092
2550
  const proto = Object.prototype;
3093
2551
  function fromParse5(tree, options) {
3094
2552
  const settings = options || {};
@@ -3159,7 +2617,7 @@ function one$4(state, node2) {
3159
2617
  /** @type {DefaultTreeAdapterMap['element']} */
3160
2618
  node2
3161
2619
  );
3162
- result = element$3(state, reference);
2620
+ result = element$4(state, reference);
3163
2621
  return result;
3164
2622
  }
3165
2623
  }
@@ -3176,7 +2634,7 @@ function all$7(state, nodes) {
3176
2634
  }
3177
2635
  return results;
3178
2636
  }
3179
- function element$3(state, node2) {
2637
+ function element$4(state, node2) {
3180
2638
  const schema = state.schema;
3181
2639
  state.schema = node2.namespaceURI === webNamespaces.svg ? svg$2 : html$5;
3182
2640
  let index2 = -1;
@@ -3184,7 +2642,7 @@ function element$3(state, node2) {
3184
2642
  while (++index2 < node2.attrs.length) {
3185
2643
  const attribute = node2.attrs[index2];
3186
2644
  const name = (attribute.prefix ? attribute.prefix + ":" : "") + attribute.name;
3187
- if (!own$7.call(proto, name)) {
2645
+ if (!own$6.call(proto, name)) {
3188
2646
  properties[name] = attribute.value;
3189
2647
  }
3190
2648
  }
@@ -3232,14 +2690,14 @@ function createLocation(state, node2, location2) {
3232
2690
  let key2;
3233
2691
  if (location2.attrs) {
3234
2692
  for (key2 in location2.attrs) {
3235
- if (own$7.call(location2.attrs, key2)) {
2693
+ if (own$6.call(location2.attrs, key2)) {
3236
2694
  properties[find$1(state.schema, key2).property] = position$2(
3237
2695
  location2.attrs[key2]
3238
2696
  );
3239
2697
  }
3240
2698
  }
3241
2699
  }
3242
- ok(location2.startTag);
2700
+ ok$1(location2.startTag);
3243
2701
  const opening2 = position$2(location2.startTag);
3244
2702
  const closing2 = location2.endTag ? position$2(location2.endTag) : void 0;
3245
2703
  const data = { opening: opening2 };
@@ -12342,11 +11800,220 @@ function rehypeParse(options) {
12342
11800
  message.name = file.path + ":" + message.name;
12343
11801
  message.file = file.path;
12344
11802
  }
12345
- file.messages.push(message);
12346
- } : void 0
12347
- });
12348
- }
12349
- }
11803
+ file.messages.push(message);
11804
+ } : void 0
11805
+ });
11806
+ }
11807
+ }
11808
+ const VOID = -1;
11809
+ const PRIMITIVE = 0;
11810
+ const ARRAY = 1;
11811
+ const OBJECT = 2;
11812
+ const DATE = 3;
11813
+ const REGEXP = 4;
11814
+ const MAP = 5;
11815
+ const SET = 6;
11816
+ const ERROR = 7;
11817
+ const BIGINT = 8;
11818
+ const env = typeof self === "object" ? self : globalThis;
11819
+ const deserializer = ($2, _) => {
11820
+ const as = (out, index2) => {
11821
+ $2.set(index2, out);
11822
+ return out;
11823
+ };
11824
+ const unpair = (index2) => {
11825
+ if ($2.has(index2))
11826
+ return $2.get(index2);
11827
+ const [type, value] = _[index2];
11828
+ switch (type) {
11829
+ case PRIMITIVE:
11830
+ case VOID:
11831
+ return as(value, index2);
11832
+ case ARRAY: {
11833
+ const arr = as([], index2);
11834
+ for (const index3 of value)
11835
+ arr.push(unpair(index3));
11836
+ return arr;
11837
+ }
11838
+ case OBJECT: {
11839
+ const object = as({}, index2);
11840
+ for (const [key2, index3] of value)
11841
+ object[unpair(key2)] = unpair(index3);
11842
+ return object;
11843
+ }
11844
+ case DATE:
11845
+ return as(new Date(value), index2);
11846
+ case REGEXP: {
11847
+ const { source, flags } = value;
11848
+ return as(new RegExp(source, flags), index2);
11849
+ }
11850
+ case MAP: {
11851
+ const map2 = as(/* @__PURE__ */ new Map(), index2);
11852
+ for (const [key2, index3] of value)
11853
+ map2.set(unpair(key2), unpair(index3));
11854
+ return map2;
11855
+ }
11856
+ case SET: {
11857
+ const set = as(/* @__PURE__ */ new Set(), index2);
11858
+ for (const index3 of value)
11859
+ set.add(unpair(index3));
11860
+ return set;
11861
+ }
11862
+ case ERROR: {
11863
+ const { name, message } = value;
11864
+ return as(new env[name](message), index2);
11865
+ }
11866
+ case BIGINT:
11867
+ return as(BigInt(value), index2);
11868
+ case "BigInt":
11869
+ return as(Object(BigInt(value)), index2);
11870
+ case "ArrayBuffer":
11871
+ return as(new Uint8Array(value).buffer, value);
11872
+ case "DataView": {
11873
+ const { buffer } = new Uint8Array(value);
11874
+ return as(new DataView(buffer), value);
11875
+ }
11876
+ }
11877
+ return as(new env[type](value), index2);
11878
+ };
11879
+ return unpair;
11880
+ };
11881
+ const deserialize = (serialized) => deserializer(/* @__PURE__ */ new Map(), serialized)(0);
11882
+ const EMPTY = "";
11883
+ const { toString: toString$2 } = {};
11884
+ const { keys } = Object;
11885
+ const typeOf = (value) => {
11886
+ const type = typeof value;
11887
+ if (type !== "object" || !value)
11888
+ return [PRIMITIVE, type];
11889
+ const asString = toString$2.call(value).slice(8, -1);
11890
+ switch (asString) {
11891
+ case "Array":
11892
+ return [ARRAY, EMPTY];
11893
+ case "Object":
11894
+ return [OBJECT, EMPTY];
11895
+ case "Date":
11896
+ return [DATE, EMPTY];
11897
+ case "RegExp":
11898
+ return [REGEXP, EMPTY];
11899
+ case "Map":
11900
+ return [MAP, EMPTY];
11901
+ case "Set":
11902
+ return [SET, EMPTY];
11903
+ case "DataView":
11904
+ return [ARRAY, asString];
11905
+ }
11906
+ if (asString.includes("Array"))
11907
+ return [ARRAY, asString];
11908
+ if (asString.includes("Error"))
11909
+ return [ERROR, asString];
11910
+ return [OBJECT, asString];
11911
+ };
11912
+ const shouldSkip = ([TYPE, type]) => TYPE === PRIMITIVE && (type === "function" || type === "symbol");
11913
+ const serializer = (strict, json, $2, _) => {
11914
+ const as = (out, value) => {
11915
+ const index2 = _.push(out) - 1;
11916
+ $2.set(value, index2);
11917
+ return index2;
11918
+ };
11919
+ const pair = (value) => {
11920
+ if ($2.has(value))
11921
+ return $2.get(value);
11922
+ let [TYPE, type] = typeOf(value);
11923
+ switch (TYPE) {
11924
+ case PRIMITIVE: {
11925
+ let entry = value;
11926
+ switch (type) {
11927
+ case "bigint":
11928
+ TYPE = BIGINT;
11929
+ entry = value.toString();
11930
+ break;
11931
+ case "function":
11932
+ case "symbol":
11933
+ if (strict)
11934
+ throw new TypeError("unable to serialize " + type);
11935
+ entry = null;
11936
+ break;
11937
+ case "undefined":
11938
+ return as([VOID], value);
11939
+ }
11940
+ return as([TYPE, entry], value);
11941
+ }
11942
+ case ARRAY: {
11943
+ if (type) {
11944
+ let spread = value;
11945
+ if (type === "DataView") {
11946
+ spread = new Uint8Array(value.buffer);
11947
+ } else if (type === "ArrayBuffer") {
11948
+ spread = new Uint8Array(value);
11949
+ }
11950
+ return as([type, [...spread]], value);
11951
+ }
11952
+ const arr = [];
11953
+ const index2 = as([TYPE, arr], value);
11954
+ for (const entry of value)
11955
+ arr.push(pair(entry));
11956
+ return index2;
11957
+ }
11958
+ case OBJECT: {
11959
+ if (type) {
11960
+ switch (type) {
11961
+ case "BigInt":
11962
+ return as([type, value.toString()], value);
11963
+ case "Boolean":
11964
+ case "Number":
11965
+ case "String":
11966
+ return as([type, value.valueOf()], value);
11967
+ }
11968
+ }
11969
+ if (json && "toJSON" in value)
11970
+ return pair(value.toJSON());
11971
+ const entries = [];
11972
+ const index2 = as([TYPE, entries], value);
11973
+ for (const key2 of keys(value)) {
11974
+ if (strict || !shouldSkip(typeOf(value[key2])))
11975
+ entries.push([pair(key2), pair(value[key2])]);
11976
+ }
11977
+ return index2;
11978
+ }
11979
+ case DATE:
11980
+ return as([TYPE, value.toISOString()], value);
11981
+ case REGEXP: {
11982
+ const { source, flags } = value;
11983
+ return as([TYPE, { source, flags }], value);
11984
+ }
11985
+ case MAP: {
11986
+ const entries = [];
11987
+ const index2 = as([TYPE, entries], value);
11988
+ for (const [key2, entry] of value) {
11989
+ if (strict || !(shouldSkip(typeOf(key2)) || shouldSkip(typeOf(entry))))
11990
+ entries.push([pair(key2), pair(entry)]);
11991
+ }
11992
+ return index2;
11993
+ }
11994
+ case SET: {
11995
+ const entries = [];
11996
+ const index2 = as([TYPE, entries], value);
11997
+ for (const entry of value) {
11998
+ if (strict || !shouldSkip(typeOf(entry)))
11999
+ entries.push(pair(entry));
12000
+ }
12001
+ return index2;
12002
+ }
12003
+ }
12004
+ const { message } = value;
12005
+ return as([TYPE, { name: type, message }], value);
12006
+ };
12007
+ return pair;
12008
+ };
12009
+ const serialize$1 = (value, { json, lossy } = {}) => {
12010
+ const _ = [];
12011
+ return serializer(!(json || lossy), !!json, /* @__PURE__ */ new Map(), _)(value), _;
12012
+ };
12013
+ const structuredClone$1 = typeof structuredClone === "function" ? (
12014
+ /* c8 ignore start */
12015
+ (any, options) => options && ("json" in options || "lossy" in options) ? deserialize(serialize$1(any, options)) : structuredClone(any)
12016
+ ) : (any, options) => deserialize(serialize$1(any, options));
12350
12017
  class Schema2 {
12351
12018
  /**
12352
12019
  * @constructor
@@ -12447,13 +12114,13 @@ function mark(values, key2, value) {
12447
12114
  values[key2] = value;
12448
12115
  }
12449
12116
  }
12450
- const own$6 = {}.hasOwnProperty;
12117
+ const own$5 = {}.hasOwnProperty;
12451
12118
  function create$3(definition2) {
12452
12119
  const property = {};
12453
12120
  const normal = {};
12454
12121
  let prop;
12455
12122
  for (prop in definition2.properties) {
12456
- if (own$6.call(definition2.properties, prop)) {
12123
+ if (own$5.call(definition2.properties, prop)) {
12457
12124
  const value = definition2.properties[prop];
12458
12125
  const info = new DefinedInfo2(
12459
12126
  prop,
@@ -13520,8 +13187,8 @@ function camelcase($0) {
13520
13187
  const html$1 = merge([xml, xlink, xmlns, aria, html$2], "html");
13521
13188
  const svg = merge([xml, xlink, xmlns, aria, svg$1], "svg");
13522
13189
  const emptyOptions$5 = {};
13523
- const own$5 = {}.hasOwnProperty;
13524
- const one$3 = zwitch("type", { handlers: { root: root$3, element: element$2, text: text$4, comment: comment$2, doctype: doctype$1 } });
13190
+ const own$4 = {}.hasOwnProperty;
13191
+ const one$3 = zwitch("type", { handlers: { root: root$3, element: element$3, text: text$4, comment: comment$2, doctype: doctype$1 } });
13525
13192
  function toParse5(tree, options) {
13526
13193
  const settings = options || emptyOptions$5;
13527
13194
  const space = settings.space;
@@ -13573,7 +13240,7 @@ function comment$2(node2) {
13573
13240
  patch$1(node2, result);
13574
13241
  return result;
13575
13242
  }
13576
- function element$2(node2, schema) {
13243
+ function element$3(node2, schema) {
13577
13244
  const parentSchema = schema;
13578
13245
  let currentSchema = parentSchema;
13579
13246
  if (node2.type === "element" && node2.tagName.toLowerCase() === "svg" && parentSchema.space === "html") {
@@ -13583,106 +13250,294 @@ function element$2(node2, schema) {
13583
13250
  let prop;
13584
13251
  if (node2.properties) {
13585
13252
  for (prop in node2.properties) {
13586
- if (prop !== "children" && own$5.call(node2.properties, prop)) {
13253
+ if (prop !== "children" && own$4.call(node2.properties, prop)) {
13587
13254
  const result2 = createProperty(
13588
13255
  currentSchema,
13589
13256
  prop,
13590
13257
  node2.properties[prop]
13591
13258
  );
13592
- if (result2) {
13593
- attrs.push(result2);
13259
+ if (result2) {
13260
+ attrs.push(result2);
13261
+ }
13262
+ }
13263
+ }
13264
+ }
13265
+ const space = currentSchema.space;
13266
+ const result = {
13267
+ nodeName: node2.tagName,
13268
+ tagName: node2.tagName,
13269
+ attrs,
13270
+ // @ts-expect-error: `parse5` types are wrong.
13271
+ namespaceURI: webNamespaces[space],
13272
+ childNodes: [],
13273
+ parentNode: null
13274
+ };
13275
+ result.childNodes = all$6(node2.children, result, currentSchema);
13276
+ patch$1(node2, result);
13277
+ if (node2.tagName === "template" && node2.content) {
13278
+ result.content = fragment(node2.content, currentSchema);
13279
+ }
13280
+ return result;
13281
+ }
13282
+ function createProperty(schema, prop, value) {
13283
+ const info = find(schema, prop);
13284
+ if (value === false || value === null || value === void 0 || typeof value === "number" && Number.isNaN(value) || !value && info.boolean) {
13285
+ return;
13286
+ }
13287
+ if (Array.isArray(value)) {
13288
+ value = info.commaSeparated ? stringify$1(value) : stringify(value);
13289
+ }
13290
+ const attribute = {
13291
+ name: info.attribute,
13292
+ value: value === true ? "" : String(value)
13293
+ };
13294
+ if (info.space && info.space !== "html" && info.space !== "svg") {
13295
+ const index2 = attribute.name.indexOf(":");
13296
+ if (index2 < 0) {
13297
+ attribute.prefix = "";
13298
+ } else {
13299
+ attribute.name = attribute.name.slice(index2 + 1);
13300
+ attribute.prefix = info.attribute.slice(0, index2);
13301
+ }
13302
+ attribute.namespace = webNamespaces[info.space];
13303
+ }
13304
+ return attribute;
13305
+ }
13306
+ function all$6(children, parentNode, schema) {
13307
+ let index2 = -1;
13308
+ const results = [];
13309
+ if (children) {
13310
+ while (++index2 < children.length) {
13311
+ const child = one$3(children[index2], schema);
13312
+ child.parentNode = parentNode;
13313
+ results.push(child);
13314
+ }
13315
+ }
13316
+ return results;
13317
+ }
13318
+ function patch$1(from, to) {
13319
+ const position2 = from.position;
13320
+ if (position2 && position2.start && position2.end) {
13321
+ ok$1(typeof position2.start.offset === "number");
13322
+ ok$1(typeof position2.end.offset === "number");
13323
+ to.sourceCodeLocation = {
13324
+ startLine: position2.start.line,
13325
+ startCol: position2.start.column,
13326
+ startOffset: position2.start.offset,
13327
+ endLine: position2.end.line,
13328
+ endCol: position2.end.column,
13329
+ endOffset: position2.end.offset
13330
+ };
13331
+ }
13332
+ }
13333
+ const pointEnd = point("end");
13334
+ const pointStart = point("start");
13335
+ function point(type) {
13336
+ return point2;
13337
+ function point2(node2) {
13338
+ const point3 = node2 && node2.position && node2.position[type] || {};
13339
+ if (typeof point3.line === "number" && point3.line > 0 && typeof point3.column === "number" && point3.column > 0) {
13340
+ return {
13341
+ line: point3.line,
13342
+ column: point3.column,
13343
+ offset: typeof point3.offset === "number" && point3.offset > -1 ? point3.offset : void 0
13344
+ };
13345
+ }
13346
+ }
13347
+ }
13348
+ function position(node2) {
13349
+ const start = pointStart(node2);
13350
+ const end = pointEnd(node2);
13351
+ if (start && end) {
13352
+ return { start, end };
13353
+ }
13354
+ }
13355
+ const convert = (
13356
+ // Note: overloads in JSDoc can’t yet use different `@template`s.
13357
+ /**
13358
+ * @type {(
13359
+ * (<Condition extends string>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition}) &
13360
+ * (<Condition extends Props>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Condition) &
13361
+ * (<Condition extends TestFunction>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Predicate<Condition, Node>) &
13362
+ * ((test?: null | undefined) => (node?: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node) &
13363
+ * ((test?: Test) => Check)
13364
+ * )}
13365
+ */
13366
+ /**
13367
+ * @param {Test} [test]
13368
+ * @returns {Check}
13369
+ */
13370
+ function(test) {
13371
+ if (test === null || test === void 0) {
13372
+ return ok;
13373
+ }
13374
+ if (typeof test === "function") {
13375
+ return castFactory$1(test);
13376
+ }
13377
+ if (typeof test === "object") {
13378
+ return Array.isArray(test) ? anyFactory$1(test) : propsFactory(test);
13379
+ }
13380
+ if (typeof test === "string") {
13381
+ return typeFactory(test);
13382
+ }
13383
+ throw new Error("Expected function, string, or object as test");
13384
+ }
13385
+ );
13386
+ function anyFactory$1(tests) {
13387
+ const checks2 = [];
13388
+ let index2 = -1;
13389
+ while (++index2 < tests.length) {
13390
+ checks2[index2] = convert(tests[index2]);
13391
+ }
13392
+ return castFactory$1(any);
13393
+ function any(...parameters) {
13394
+ let index3 = -1;
13395
+ while (++index3 < checks2.length) {
13396
+ if (checks2[index3].apply(this, parameters)) return true;
13397
+ }
13398
+ return false;
13399
+ }
13400
+ }
13401
+ function propsFactory(check) {
13402
+ const checkAsRecord = (
13403
+ /** @type {Record<string, unknown>} */
13404
+ check
13405
+ );
13406
+ return castFactory$1(all2);
13407
+ function all2(node2) {
13408
+ const nodeAsRecord = (
13409
+ /** @type {Record<string, unknown>} */
13410
+ /** @type {unknown} */
13411
+ node2
13412
+ );
13413
+ let key2;
13414
+ for (key2 in check) {
13415
+ if (nodeAsRecord[key2] !== checkAsRecord[key2]) return false;
13416
+ }
13417
+ return true;
13418
+ }
13419
+ }
13420
+ function typeFactory(check) {
13421
+ return castFactory$1(type);
13422
+ function type(node2) {
13423
+ return node2 && node2.type === check;
13424
+ }
13425
+ }
13426
+ function castFactory$1(testFunction) {
13427
+ return check;
13428
+ function check(value, index2, parent) {
13429
+ return Boolean(
13430
+ looksLikeANode(value) && testFunction.call(
13431
+ this,
13432
+ value,
13433
+ typeof index2 === "number" ? index2 : void 0,
13434
+ parent || void 0
13435
+ )
13436
+ );
13437
+ }
13438
+ }
13439
+ function ok() {
13440
+ return true;
13441
+ }
13442
+ function looksLikeANode(value) {
13443
+ return value !== null && typeof value === "object" && "type" in value;
13444
+ }
13445
+ function color(d) {
13446
+ return d;
13447
+ }
13448
+ const empty = [];
13449
+ const CONTINUE = true;
13450
+ const EXIT = false;
13451
+ const SKIP = "skip";
13452
+ function visitParents(tree, test, visitor, reverse) {
13453
+ let check;
13454
+ if (typeof test === "function" && typeof visitor !== "function") {
13455
+ reverse = visitor;
13456
+ visitor = test;
13457
+ } else {
13458
+ check = test;
13459
+ }
13460
+ const is = convert(check);
13461
+ const step = reverse ? -1 : 1;
13462
+ factory(tree, void 0, [])();
13463
+ function factory(node2, index2, parents) {
13464
+ const value = (
13465
+ /** @type {Record<string, unknown>} */
13466
+ node2 && typeof node2 === "object" ? node2 : {}
13467
+ );
13468
+ if (typeof value.type === "string") {
13469
+ const name = (
13470
+ // `hast`
13471
+ typeof value.tagName === "string" ? value.tagName : (
13472
+ // `xast`
13473
+ typeof value.name === "string" ? value.name : void 0
13474
+ )
13475
+ );
13476
+ Object.defineProperty(visit2, "name", {
13477
+ value: "node (" + color(node2.type + (name ? "<" + name + ">" : "")) + ")"
13478
+ });
13479
+ }
13480
+ return visit2;
13481
+ function visit2() {
13482
+ let result = empty;
13483
+ let subresult;
13484
+ let offset;
13485
+ let grandparents;
13486
+ if (!test || is(node2, index2, parents[parents.length - 1] || void 0)) {
13487
+ result = toResult(visitor(node2, parents));
13488
+ if (result[0] === EXIT) {
13489
+ return result;
13490
+ }
13491
+ }
13492
+ if ("children" in node2 && node2.children) {
13493
+ const nodeAsParent = (
13494
+ /** @type {UnistParent} */
13495
+ node2
13496
+ );
13497
+ if (nodeAsParent.children && result[0] !== SKIP) {
13498
+ offset = (reverse ? nodeAsParent.children.length : -1) + step;
13499
+ grandparents = parents.concat(nodeAsParent);
13500
+ while (offset > -1 && offset < nodeAsParent.children.length) {
13501
+ const child = nodeAsParent.children[offset];
13502
+ subresult = factory(child, offset, grandparents)();
13503
+ if (subresult[0] === EXIT) {
13504
+ return subresult;
13505
+ }
13506
+ offset = typeof subresult[1] === "number" ? subresult[1] : offset + step;
13507
+ }
13594
13508
  }
13595
13509
  }
13510
+ return result;
13596
13511
  }
13597
13512
  }
13598
- const space = currentSchema.space;
13599
- const result = {
13600
- nodeName: node2.tagName,
13601
- tagName: node2.tagName,
13602
- attrs,
13603
- // @ts-expect-error: `parse5` types are wrong.
13604
- namespaceURI: webNamespaces[space],
13605
- childNodes: [],
13606
- parentNode: null
13607
- };
13608
- result.childNodes = all$6(node2.children, result, currentSchema);
13609
- patch$1(node2, result);
13610
- if (node2.tagName === "template" && node2.content) {
13611
- result.content = fragment(node2.content, currentSchema);
13612
- }
13613
- return result;
13614
13513
  }
13615
- function createProperty(schema, prop, value) {
13616
- const info = find(schema, prop);
13617
- if (value === false || value === null || value === void 0 || typeof value === "number" && Number.isNaN(value) || !value && info.boolean) {
13618
- return;
13619
- }
13514
+ function toResult(value) {
13620
13515
  if (Array.isArray(value)) {
13621
- value = info.commaSeparated ? stringify$1(value) : stringify(value);
13622
- }
13623
- const attribute = {
13624
- name: info.attribute,
13625
- value: value === true ? "" : String(value)
13626
- };
13627
- if (info.space && info.space !== "html" && info.space !== "svg") {
13628
- const index2 = attribute.name.indexOf(":");
13629
- if (index2 < 0) {
13630
- attribute.prefix = "";
13631
- } else {
13632
- attribute.name = attribute.name.slice(index2 + 1);
13633
- attribute.prefix = info.attribute.slice(0, index2);
13634
- }
13635
- attribute.namespace = webNamespaces[info.space];
13636
- }
13637
- return attribute;
13638
- }
13639
- function all$6(children, parentNode, schema) {
13640
- let index2 = -1;
13641
- const results = [];
13642
- if (children) {
13643
- while (++index2 < children.length) {
13644
- const child = one$3(children[index2], schema);
13645
- child.parentNode = parentNode;
13646
- results.push(child);
13647
- }
13516
+ return value;
13648
13517
  }
13649
- return results;
13650
- }
13651
- function patch$1(from, to) {
13652
- const position2 = from.position;
13653
- if (position2 && position2.start && position2.end) {
13654
- ok(typeof position2.start.offset === "number");
13655
- ok(typeof position2.end.offset === "number");
13656
- to.sourceCodeLocation = {
13657
- startLine: position2.start.line,
13658
- startCol: position2.start.column,
13659
- startOffset: position2.start.offset,
13660
- endLine: position2.end.line,
13661
- endCol: position2.end.column,
13662
- endOffset: position2.end.offset
13663
- };
13518
+ if (typeof value === "number") {
13519
+ return [CONTINUE, value];
13664
13520
  }
13521
+ return value === null || value === void 0 ? empty : [value];
13665
13522
  }
13666
- const pointEnd = point("end");
13667
- const pointStart = point("start");
13668
- function point(type) {
13669
- return point2;
13670
- function point2(node2) {
13671
- const point3 = node2 && node2.position && node2.position[type] || {};
13672
- if (typeof point3.line === "number" && point3.line > 0 && typeof point3.column === "number" && point3.column > 0) {
13673
- return {
13674
- line: point3.line,
13675
- column: point3.column,
13676
- offset: typeof point3.offset === "number" && point3.offset > -1 ? point3.offset : void 0
13677
- };
13678
- }
13523
+ function visit(tree, testOrVisitor, visitorOrReverse, maybeReverse) {
13524
+ let reverse;
13525
+ let test;
13526
+ let visitor;
13527
+ if (typeof testOrVisitor === "function" && typeof visitorOrReverse !== "function") {
13528
+ test = void 0;
13529
+ visitor = testOrVisitor;
13530
+ reverse = visitorOrReverse;
13531
+ } else {
13532
+ test = testOrVisitor;
13533
+ visitor = visitorOrReverse;
13534
+ reverse = maybeReverse;
13679
13535
  }
13680
- }
13681
- function position(node2) {
13682
- const start = pointStart(node2);
13683
- const end = pointEnd(node2);
13684
- if (start && end) {
13685
- return { start, end };
13536
+ visitParents(tree, test, overload, reverse);
13537
+ function overload(node2, parents) {
13538
+ const parent = parents[parents.length - 1];
13539
+ const index2 = parent ? parent.children.indexOf(node2) : void 0;
13540
+ return visitor(node2, index2, parent);
13686
13541
  }
13687
13542
  }
13688
13543
  const gfmTagfilterExpression = /<(\/?)(iframe|noembed|noframes|plaintext|script|style|textarea|title|xmp)(?=[\t\n\f\r />])/gi;
@@ -13697,7 +13552,7 @@ const parseOptions = { sourceCodeLocationInfo: true, scriptingEnabled: false };
13697
13552
  function raw(tree, options) {
13698
13553
  const document2 = documentMode(tree);
13699
13554
  const one2 = zwitch("type", {
13700
- handlers: { root: root$2, element: element$1, text: text$3, comment: comment$1, doctype, raw: handleRaw },
13555
+ handlers: { root: root$2, element: element$2, text: text$3, comment: comment$1, doctype, raw: handleRaw },
13701
13556
  unknown: unknown$1
13702
13557
  });
13703
13558
  const state = {
@@ -13745,7 +13600,7 @@ function all$5(nodes, state) {
13745
13600
  function root$2(node2, state) {
13746
13601
  all$5(node2.children, state);
13747
13602
  }
13748
- function element$1(node2, state) {
13603
+ function element$2(node2, state) {
13749
13604
  startTag(node2, state);
13750
13605
  all$5(node2.children, state);
13751
13606
  endTag(node2, state);
@@ -13778,15 +13633,15 @@ function doctype(node2, state) {
13778
13633
  }
13779
13634
  function stitch(node2, state) {
13780
13635
  state.stitches = true;
13781
- const clone2 = cloneWithoutChildren$1(node2);
13782
- if ("children" in node2 && "children" in clone2) {
13636
+ const clone = cloneWithoutChildren$1(node2);
13637
+ if ("children" in node2 && "children" in clone) {
13783
13638
  const fakeRoot = (
13784
13639
  /** @type {Root} */
13785
13640
  raw({ type: "root", children: node2.children }, state.options)
13786
13641
  );
13787
- clone2.children = fakeRoot.children;
13642
+ clone.children = fakeRoot.children;
13788
13643
  }
13789
- comment$1({ type: "comment", value: { stitch: clone2 } }, state);
13644
+ comment$1({ type: "comment", value: { stitch: clone } }, state);
13790
13645
  }
13791
13646
  function comment$1(node2, state) {
13792
13647
  const data = node2.value;
@@ -13903,72 +13758,169 @@ function startTag(node2, state) {
13903
13758
  state.parser._processToken(state.parser.currentToken);
13904
13759
  state.parser.tokenizer.lastStartTagName = tagName;
13905
13760
  }
13906
- function endTag(node2, state) {
13907
- const tagName = node2.tagName.toLowerCase();
13908
- if (!state.parser.tokenizer.inForeignNode && htmlVoidElements.includes(tagName)) {
13909
- return;
13761
+ function endTag(node2, state) {
13762
+ const tagName = node2.tagName.toLowerCase();
13763
+ if (!state.parser.tokenizer.inForeignNode && htmlVoidElements.includes(tagName)) {
13764
+ return;
13765
+ }
13766
+ if (state.parser.tokenizer.state === TokenizerMode.PLAINTEXT) return;
13767
+ resetTokenizer(state, pointEnd(node2));
13768
+ const tag = {
13769
+ type: TokenType.END_TAG,
13770
+ tagName,
13771
+ tagID: getTagID(tagName),
13772
+ selfClosing: false,
13773
+ ackSelfClosing: false,
13774
+ attrs: [],
13775
+ location: createParse5Location(node2)
13776
+ };
13777
+ state.parser.currentToken = tag;
13778
+ state.parser._processToken(state.parser.currentToken);
13779
+ if (
13780
+ // Current element is closed.
13781
+ tagName === state.parser.tokenizer.lastStartTagName && // `<textarea>` and `<title>`
13782
+ (state.parser.tokenizer.state === TokenizerMode.RCDATA || // `<iframe>`, `<noembed>`, `<noframes>`, `<style>`, `<xmp>`
13783
+ state.parser.tokenizer.state === TokenizerMode.RAWTEXT || // `<script>`
13784
+ state.parser.tokenizer.state === TokenizerMode.SCRIPT_DATA)
13785
+ ) {
13786
+ state.parser.tokenizer.state = TokenizerMode.DATA;
13787
+ }
13788
+ }
13789
+ function documentMode(node2) {
13790
+ const head2 = node2.type === "root" ? node2.children[0] : node2;
13791
+ return Boolean(
13792
+ head2 && (head2.type === "doctype" || head2.type === "element" && head2.tagName.toLowerCase() === "html")
13793
+ );
13794
+ }
13795
+ function createParse5Location(node2) {
13796
+ const start = pointStart(node2) || {
13797
+ line: void 0,
13798
+ column: void 0,
13799
+ offset: void 0
13800
+ };
13801
+ const end = pointEnd(node2) || {
13802
+ line: void 0,
13803
+ column: void 0,
13804
+ offset: void 0
13805
+ };
13806
+ const location2 = {
13807
+ startLine: start.line,
13808
+ startCol: start.column,
13809
+ startOffset: start.offset,
13810
+ endLine: end.line,
13811
+ endCol: end.column,
13812
+ endOffset: end.offset
13813
+ };
13814
+ return location2;
13815
+ }
13816
+ function cloneWithoutChildren$1(node2) {
13817
+ return "children" in node2 ? structuredClone$1({ ...node2, children: [] }) : structuredClone$1(node2);
13818
+ }
13819
+ function rehypeRaw(options) {
13820
+ return function(tree, file) {
13821
+ const result = (
13822
+ /** @type {Root} */
13823
+ raw(tree, { ...options, file })
13824
+ );
13825
+ return result;
13826
+ };
13827
+ }
13828
+ const isElement = (
13829
+ // Note: overloads in JSDoc can’t yet use different `@template`s.
13830
+ /**
13831
+ * @type {(
13832
+ * (<Condition extends TestFunction>(element: unknown, test: Condition, index?: number | null | undefined, parent?: Parents | null | undefined, context?: unknown) => element is Element & Predicate<Condition, Element>) &
13833
+ * (<Condition extends string>(element: unknown, test: Condition, index?: number | null | undefined, parent?: Parents | null | undefined, context?: unknown) => element is Element & {tagName: Condition}) &
13834
+ * ((element?: null | undefined) => false) &
13835
+ * ((element: unknown, test?: null | undefined, index?: number | null | undefined, parent?: Parents | null | undefined, context?: unknown) => element is Element) &
13836
+ * ((element: unknown, test?: Test, index?: number | null | undefined, parent?: Parents | null | undefined, context?: unknown) => boolean)
13837
+ * )}
13838
+ */
13839
+ /**
13840
+ * @param {unknown} [element]
13841
+ * @param {Test | undefined} [test]
13842
+ * @param {number | null | undefined} [index]
13843
+ * @param {Parents | null | undefined} [parent]
13844
+ * @param {unknown} [context]
13845
+ * @returns {boolean}
13846
+ */
13847
+ // eslint-disable-next-line max-params
13848
+ function(element2, test, index2, parent, context) {
13849
+ const check = convertElement(test);
13850
+ return looksLikeAnElement(element2) ? check.call(context, element2, index2, parent) : false;
13851
+ }
13852
+ );
13853
+ const convertElement = (
13854
+ // Note: overloads in JSDoc can’t yet use different `@template`s.
13855
+ /**
13856
+ * @type {(
13857
+ * (<Condition extends TestFunction>(test: Condition) => (element: unknown, index?: number | null | undefined, parent?: Parents | null | undefined, context?: unknown) => element is Element & Predicate<Condition, Element>) &
13858
+ * (<Condition extends string>(test: Condition) => (element: unknown, index?: number | null | undefined, parent?: Parents | null | undefined, context?: unknown) => element is Element & {tagName: Condition}) &
13859
+ * ((test?: null | undefined) => (element?: unknown, index?: number | null | undefined, parent?: Parents | null | undefined, context?: unknown) => element is Element) &
13860
+ * ((test?: Test) => Check)
13861
+ * )}
13862
+ */
13863
+ /**
13864
+ * @param {Test | null | undefined} [test]
13865
+ * @returns {Check}
13866
+ */
13867
+ function(test) {
13868
+ if (test === null || test === void 0) {
13869
+ return element$1;
13870
+ }
13871
+ if (typeof test === "string") {
13872
+ return tagNameFactory(test);
13873
+ }
13874
+ if (typeof test === "object") {
13875
+ return anyFactory(test);
13876
+ }
13877
+ if (typeof test === "function") {
13878
+ return castFactory(test);
13879
+ }
13880
+ throw new Error("Expected function, string, or array as `test`");
13881
+ }
13882
+ );
13883
+ function anyFactory(tests) {
13884
+ const checks2 = [];
13885
+ let index2 = -1;
13886
+ while (++index2 < tests.length) {
13887
+ checks2[index2] = convertElement(tests[index2]);
13888
+ }
13889
+ return castFactory(any);
13890
+ function any(...parameters) {
13891
+ let index3 = -1;
13892
+ while (++index3 < checks2.length) {
13893
+ if (checks2[index3].apply(this, parameters)) return true;
13894
+ }
13895
+ return false;
13896
+ }
13897
+ }
13898
+ function tagNameFactory(check) {
13899
+ return castFactory(tagName);
13900
+ function tagName(element2) {
13901
+ return element2.tagName === check;
13910
13902
  }
13911
- if (state.parser.tokenizer.state === TokenizerMode.PLAINTEXT) return;
13912
- resetTokenizer(state, pointEnd(node2));
13913
- const tag = {
13914
- type: TokenType.END_TAG,
13915
- tagName,
13916
- tagID: getTagID(tagName),
13917
- selfClosing: false,
13918
- ackSelfClosing: false,
13919
- attrs: [],
13920
- location: createParse5Location(node2)
13921
- };
13922
- state.parser.currentToken = tag;
13923
- state.parser._processToken(state.parser.currentToken);
13924
- if (
13925
- // Current element is closed.
13926
- tagName === state.parser.tokenizer.lastStartTagName && // `<textarea>` and `<title>`
13927
- (state.parser.tokenizer.state === TokenizerMode.RCDATA || // `<iframe>`, `<noembed>`, `<noframes>`, `<style>`, `<xmp>`
13928
- state.parser.tokenizer.state === TokenizerMode.RAWTEXT || // `<script>`
13929
- state.parser.tokenizer.state === TokenizerMode.SCRIPT_DATA)
13930
- ) {
13931
- state.parser.tokenizer.state = TokenizerMode.DATA;
13903
+ }
13904
+ function castFactory(testFunction) {
13905
+ return check;
13906
+ function check(value, index2, parent) {
13907
+ return Boolean(
13908
+ looksLikeAnElement(value) && testFunction.call(
13909
+ this,
13910
+ value,
13911
+ typeof index2 === "number" ? index2 : void 0,
13912
+ parent || void 0
13913
+ )
13914
+ );
13932
13915
  }
13933
13916
  }
13934
- function documentMode(node2) {
13935
- const head2 = node2.type === "root" ? node2.children[0] : node2;
13917
+ function element$1(element2) {
13936
13918
  return Boolean(
13937
- head2 && (head2.type === "doctype" || head2.type === "element" && head2.tagName.toLowerCase() === "html")
13919
+ element2 && typeof element2 === "object" && "type" in element2 && element2.type === "element" && "tagName" in element2 && typeof element2.tagName === "string"
13938
13920
  );
13939
13921
  }
13940
- function createParse5Location(node2) {
13941
- const start = pointStart(node2) || {
13942
- line: void 0,
13943
- column: void 0,
13944
- offset: void 0
13945
- };
13946
- const end = pointEnd(node2) || {
13947
- line: void 0,
13948
- column: void 0,
13949
- offset: void 0
13950
- };
13951
- const location2 = {
13952
- startLine: start.line,
13953
- startCol: start.column,
13954
- startOffset: start.offset,
13955
- endLine: end.line,
13956
- endCol: end.column,
13957
- endOffset: end.offset
13958
- };
13959
- return location2;
13960
- }
13961
- function cloneWithoutChildren$1(node2) {
13962
- return "children" in node2 ? structuredClone$1({ ...node2, children: [] }) : structuredClone$1(node2);
13963
- }
13964
- function rehypeRaw(options) {
13965
- return function(tree, file) {
13966
- const result = (
13967
- /** @type {Root} */
13968
- raw(tree, { ...options, file })
13969
- );
13970
- return result;
13971
- };
13922
+ function looksLikeAnElement(value) {
13923
+ return value !== null && typeof value === "object" && "type" in value && "tagName" in value;
13972
13924
  }
13973
13925
  const embedded = convertElement(
13974
13926
  /**
@@ -14994,9 +14946,9 @@ function input(state, node2) {
14994
14946
  state.patch(node2, result);
14995
14947
  return result;
14996
14948
  }
14997
- const own$4 = {}.hasOwnProperty;
14949
+ const own$3 = {}.hasOwnProperty;
14998
14950
  function hasProperty(node2, name) {
14999
- const value = node2.type === "element" && own$4.call(node2.properties, name) && node2.properties[name];
14951
+ const value = node2.type === "element" && own$3.call(node2.properties, name) && node2.properties[name];
15000
14952
  return value !== null && value !== void 0 && value !== false;
15001
14953
  }
15002
14954
  const list$3 = /* @__PURE__ */ new Set(["pingback", "prefetch", "stylesheet"]);
@@ -15711,7 +15663,7 @@ function flow(state, node2) {
15711
15663
  }
15712
15664
  function ignore() {
15713
15665
  }
15714
- const own$3 = {}.hasOwnProperty;
15666
+ const own$2 = {}.hasOwnProperty;
15715
15667
  function createState(options) {
15716
15668
  return {
15717
15669
  all: all$1,
@@ -15753,10 +15705,10 @@ function one$1(node2, parent) {
15753
15705
  if (node2.properties && node2.properties.dataMdast === "ignore") {
15754
15706
  return;
15755
15707
  }
15756
- if (own$3.call(this.handlers, node2.tagName)) {
15708
+ if (own$2.call(this.handlers, node2.tagName)) {
15757
15709
  return this.handlers[node2.tagName](this, node2, parent) || void 0;
15758
15710
  }
15759
- } else if (own$3.call(this.nodeHandlers, node2.type)) {
15711
+ } else if (own$2.call(this.nodeHandlers, node2.type)) {
15760
15712
  return this.nodeHandlers[node2.type](this, node2, parent) || void 0;
15761
15713
  }
15762
15714
  if ("value" in node2 && typeof node2.value === "string") {
@@ -15892,54 +15844,10 @@ function rehypeRemark(destination, options) {
15892
15844
  );
15893
15845
  };
15894
15846
  }
15895
- const regex = /[\0-\x1F!-,\.\/:-@\[-\^`\{-\xA9\xAB-\xB4\xB6-\xB9\xBB-\xBF\xD7\xF7\u02C2-\u02C5\u02D2-\u02DF\u02E5-\u02EB\u02ED\u02EF-\u02FF\u0375\u0378\u0379\u037E\u0380-\u0385\u0387\u038B\u038D\u03A2\u03F6\u0482\u0530\u0557\u0558\u055A-\u055F\u0589-\u0590\u05BE\u05C0\u05C3\u05C6\u05C8-\u05CF\u05EB-\u05EE\u05F3-\u060F\u061B-\u061F\u066A-\u066D\u06D4\u06DD\u06DE\u06E9\u06FD\u06FE\u0700-\u070F\u074B\u074C\u07B2-\u07BF\u07F6-\u07F9\u07FB\u07FC\u07FE\u07FF\u082E-\u083F\u085C-\u085F\u086B-\u089F\u08B5\u08C8-\u08D2\u08E2\u0964\u0965\u0970\u0984\u098D\u098E\u0991\u0992\u09A9\u09B1\u09B3-\u09B5\u09BA\u09BB\u09C5\u09C6\u09C9\u09CA\u09CF-\u09D6\u09D8-\u09DB\u09DE\u09E4\u09E5\u09F2-\u09FB\u09FD\u09FF\u0A00\u0A04\u0A0B-\u0A0E\u0A11\u0A12\u0A29\u0A31\u0A34\u0A37\u0A3A\u0A3B\u0A3D\u0A43-\u0A46\u0A49\u0A4A\u0A4E-\u0A50\u0A52-\u0A58\u0A5D\u0A5F-\u0A65\u0A76-\u0A80\u0A84\u0A8E\u0A92\u0AA9\u0AB1\u0AB4\u0ABA\u0ABB\u0AC6\u0ACA\u0ACE\u0ACF\u0AD1-\u0ADF\u0AE4\u0AE5\u0AF0-\u0AF8\u0B00\u0B04\u0B0D\u0B0E\u0B11\u0B12\u0B29\u0B31\u0B34\u0B3A\u0B3B\u0B45\u0B46\u0B49\u0B4A\u0B4E-\u0B54\u0B58-\u0B5B\u0B5E\u0B64\u0B65\u0B70\u0B72-\u0B81\u0B84\u0B8B-\u0B8D\u0B91\u0B96-\u0B98\u0B9B\u0B9D\u0BA0-\u0BA2\u0BA5-\u0BA7\u0BAB-\u0BAD\u0BBA-\u0BBD\u0BC3-\u0BC5\u0BC9\u0BCE\u0BCF\u0BD1-\u0BD6\u0BD8-\u0BE5\u0BF0-\u0BFF\u0C0D\u0C11\u0C29\u0C3A-\u0C3C\u0C45\u0C49\u0C4E-\u0C54\u0C57\u0C5B-\u0C5F\u0C64\u0C65\u0C70-\u0C7F\u0C84\u0C8D\u0C91\u0CA9\u0CB4\u0CBA\u0CBB\u0CC5\u0CC9\u0CCE-\u0CD4\u0CD7-\u0CDD\u0CDF\u0CE4\u0CE5\u0CF0\u0CF3-\u0CFF\u0D0D\u0D11\u0D45\u0D49\u0D4F-\u0D53\u0D58-\u0D5E\u0D64\u0D65\u0D70-\u0D79\u0D80\u0D84\u0D97-\u0D99\u0DB2\u0DBC\u0DBE\u0DBF\u0DC7-\u0DC9\u0DCB-\u0DCE\u0DD5\u0DD7\u0DE0-\u0DE5\u0DF0\u0DF1\u0DF4-\u0E00\u0E3B-\u0E3F\u0E4F\u0E5A-\u0E80\u0E83\u0E85\u0E8B\u0EA4\u0EA6\u0EBE\u0EBF\u0EC5\u0EC7\u0ECE\u0ECF\u0EDA\u0EDB\u0EE0-\u0EFF\u0F01-\u0F17\u0F1A-\u0F1F\u0F2A-\u0F34\u0F36\u0F38\u0F3A-\u0F3D\u0F48\u0F6D-\u0F70\u0F85\u0F98\u0FBD-\u0FC5\u0FC7-\u0FFF\u104A-\u104F\u109E\u109F\u10C6\u10C8-\u10CC\u10CE\u10CF\u10FB\u1249\u124E\u124F\u1257\u1259\u125E\u125F\u1289\u128E\u128F\u12B1\u12B6\u12B7\u12BF\u12C1\u12C6\u12C7\u12D7\u1311\u1316\u1317\u135B\u135C\u1360-\u137F\u1390-\u139F\u13F6\u13F7\u13FE-\u1400\u166D\u166E\u1680\u169B-\u169F\u16EB-\u16ED\u16F9-\u16FF\u170D\u1715-\u171F\u1735-\u173F\u1754-\u175F\u176D\u1771\u1774-\u177F\u17D4-\u17D6\u17D8-\u17DB\u17DE\u17DF\u17EA-\u180A\u180E\u180F\u181A-\u181F\u1879-\u187F\u18AB-\u18AF\u18F6-\u18FF\u191F\u192C-\u192F\u193C-\u1945\u196E\u196F\u1975-\u197F\u19AC-\u19AF\u19CA-\u19CF\u19DA-\u19FF\u1A1C-\u1A1F\u1A5F\u1A7D\u1A7E\u1A8A-\u1A8F\u1A9A-\u1AA6\u1AA8-\u1AAF\u1AC1-\u1AFF\u1B4C-\u1B4F\u1B5A-\u1B6A\u1B74-\u1B7F\u1BF4-\u1BFF\u1C38-\u1C3F\u1C4A-\u1C4C\u1C7E\u1C7F\u1C89-\u1C8F\u1CBB\u1CBC\u1CC0-\u1CCF\u1CD3\u1CFB-\u1CFF\u1DFA\u1F16\u1F17\u1F1E\u1F1F\u1F46\u1F47\u1F4E\u1F4F\u1F58\u1F5A\u1F5C\u1F5E\u1F7E\u1F7F\u1FB5\u1FBD\u1FBF-\u1FC1\u1FC5\u1FCD-\u1FCF\u1FD4\u1FD5\u1FDC-\u1FDF\u1FED-\u1FF1\u1FF5\u1FFD-\u203E\u2041-\u2053\u2055-\u2070\u2072-\u207E\u2080-\u208F\u209D-\u20CF\u20F1-\u2101\u2103-\u2106\u2108\u2109\u2114\u2116-\u2118\u211E-\u2123\u2125\u2127\u2129\u212E\u213A\u213B\u2140-\u2144\u214A-\u214D\u214F-\u215F\u2189-\u24B5\u24EA-\u2BFF\u2C2F\u2C5F\u2CE5-\u2CEA\u2CF4-\u2CFF\u2D26\u2D28-\u2D2C\u2D2E\u2D2F\u2D68-\u2D6E\u2D70-\u2D7E\u2D97-\u2D9F\u2DA7\u2DAF\u2DB7\u2DBF\u2DC7\u2DCF\u2DD7\u2DDF\u2E00-\u2E2E\u2E30-\u3004\u3008-\u3020\u3030\u3036\u3037\u303D-\u3040\u3097\u3098\u309B\u309C\u30A0\u30FB\u3100-\u3104\u3130\u318F-\u319F\u31C0-\u31EF\u3200-\u33FF\u4DC0-\u4DFF\u9FFD-\u9FFF\uA48D-\uA4CF\uA4FE\uA4FF\uA60D-\uA60F\uA62C-\uA63F\uA673\uA67E\uA6F2-\uA716\uA720\uA721\uA789\uA78A\uA7C0\uA7C1\uA7CB-\uA7F4\uA828-\uA82B\uA82D-\uA83F\uA874-\uA87F\uA8C6-\uA8CF\uA8DA-\uA8DF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA954-\uA95F\uA97D-\uA97F\uA9C1-\uA9CE\uA9DA-\uA9DF\uA9FF\uAA37-\uAA3F\uAA4E\uAA4F\uAA5A-\uAA5F\uAA77-\uAA79\uAAC3-\uAADA\uAADE\uAADF\uAAF0\uAAF1\uAAF7-\uAB00\uAB07\uAB08\uAB0F\uAB10\uAB17-\uAB1F\uAB27\uAB2F\uAB5B\uAB6A-\uAB6F\uABEB\uABEE\uABEF\uABFA-\uABFF\uD7A4-\uD7AF\uD7C7-\uD7CA\uD7FC-\uD7FF\uE000-\uF8FF\uFA6E\uFA6F\uFADA-\uFAFF\uFB07-\uFB12\uFB18-\uFB1C\uFB29\uFB37\uFB3D\uFB3F\uFB42\uFB45\uFBB2-\uFBD2\uFD3E-\uFD4F\uFD90\uFD91\uFDC8-\uFDEF\uFDFC-\uFDFF\uFE10-\uFE1F\uFE30-\uFE32\uFE35-\uFE4C\uFE50-\uFE6F\uFE75\uFEFD-\uFF0F\uFF1A-\uFF20\uFF3B-\uFF3E\uFF40\uFF5B-\uFF65\uFFBF-\uFFC1\uFFC8\uFFC9\uFFD0\uFFD1\uFFD8\uFFD9\uFFDD-\uFFFF]|\uD800[\uDC0C\uDC27\uDC3B\uDC3E\uDC4E\uDC4F\uDC5E-\uDC7F\uDCFB-\uDD3F\uDD75-\uDDFC\uDDFE-\uDE7F\uDE9D-\uD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\uDE65\uDE66\uDE6B\uDE73\uDE78\uDE7D\uDE7F\uDE8A\uDE9C-\uDEA0\uDEA4\uDEAA\uDEBC-\uDFFF]|\uD83C[\uDC00-\uDD2F\uDD4A-\uDD4F\uDD6A-\uDD6F\uDD8A-\uDFFF]|\uD83E[\uDC00-\uDFEF\uDFFA-\uDFFF]|\uD869[\uDEDE-\uDEFF]|\uD86D[\uDF35-\uDF3F]|\uD86E[\uDC1E\uDC1F]|\uD873[\uDEA2-\uDEAF]|\uD87A[\uDFE1-\uDFFF]|\uD87E[\uDE1E-\uDFFF]|\uD884[\uDF4B-\uDFFF]|\uDB40[\uDC00-\uDCFF\uDDF0-\uDFFF]/g;
15896
- const own$2 = Object.hasOwnProperty;
15897
- class BananaSlug {
15898
- /**
15899
- * Create a new slug class.
15900
- */
15901
- constructor() {
15902
- this.occurrences;
15903
- this.reset();
15904
- }
15905
- /**
15906
- * Generate a unique slug.
15907
- *
15908
- * Tracks previously generated slugs: repeated calls with the same value
15909
- * will result in different slugs.
15910
- * Use the `slug` function to get same slugs.
15911
- *
15912
- * @param {string} value
15913
- * String of text to slugify
15914
- * @param {boolean} [maintainCase=false]
15915
- * Keep the current case, otherwise make all lowercase
15916
- * @return {string}
15917
- * A unique slug string
15918
- */
15919
- slug(value, maintainCase) {
15920
- const self2 = this;
15921
- let result = slug(value, maintainCase === true);
15922
- const originalSlug = result;
15923
- while (own$2.call(self2.occurrences, result)) {
15924
- self2.occurrences[originalSlug]++;
15925
- result = originalSlug + "-" + self2.occurrences[originalSlug];
15926
- }
15927
- self2.occurrences[result] = 0;
15928
- return result;
15929
- }
15930
- /**
15931
- * Reset - Forget all previous slugs
15932
- *
15933
- * @return void
15934
- */
15935
- reset() {
15936
- this.occurrences = /* @__PURE__ */ Object.create(null);
15937
- }
15938
- }
15939
- function slug(value, maintainCase) {
15940
- if (typeof value !== "string") return "";
15941
- if (!maintainCase) value = value.toLowerCase();
15942
- return value.replace(regex, "").replace(/ /g, "-");
15847
+ function headingRank(node2) {
15848
+ const name = node2.type === "element" ? node2.tagName.toLowerCase() : "";
15849
+ const code2 = name.length === 2 && name.charCodeAt(0) === 104 ? name.charCodeAt(1) : 0;
15850
+ return code2 > 48 && code2 < 55 ? code2 - 48 : void 0;
15943
15851
  }
15944
15852
  function toString(node2) {
15945
15853
  if ("children" in node2) {
@@ -16168,7 +16076,7 @@ function exitLiteralAutolinkHttp(token) {
16168
16076
  function exitLiteralAutolinkWww(token) {
16169
16077
  this.config.exit.data.call(this, token);
16170
16078
  const node2 = this.stack[this.stack.length - 1];
16171
- ok(node2.type === "link");
16079
+ ok$1(node2.type === "link");
16172
16080
  node2.url = "http://" + this.sliceSerialize(token);
16173
16081
  }
16174
16082
  function exitLiteralAutolinkEmail(token) {
@@ -16280,7 +16188,7 @@ function enterFootnoteDefinition(token) {
16280
16188
  function exitFootnoteCallString(token) {
16281
16189
  const label = this.resume();
16282
16190
  const node2 = this.stack[this.stack.length - 1];
16283
- ok(node2.type === "footnoteReference");
16191
+ ok$1(node2.type === "footnoteReference");
16284
16192
  node2.identifier = normalizeIdentifier(
16285
16193
  this.sliceSerialize(token)
16286
16194
  ).toLowerCase();
@@ -16292,7 +16200,7 @@ function exitFootnoteCall(token) {
16292
16200
  function exitFootnoteDefinitionLabelString(token) {
16293
16201
  const label = this.resume();
16294
16202
  const node2 = this.stack[this.stack.length - 1];
16295
- ok(node2.type === "footnoteDefinition");
16203
+ ok$1(node2.type === "footnoteDefinition");
16296
16204
  node2.identifier = normalizeIdentifier(
16297
16205
  this.sliceSerialize(token)
16298
16206
  ).toLowerCase();
@@ -17981,7 +17889,7 @@ function exitCodeText(token) {
17981
17889
  value = value.replace(/\\([\\|])/g, replace);
17982
17890
  }
17983
17891
  const node2 = this.stack[this.stack.length - 1];
17984
- ok(node2.type === "inlineCode");
17892
+ ok$1(node2.type === "inlineCode");
17985
17893
  node2.value = value;
17986
17894
  this.exit(token);
17987
17895
  }
@@ -18016,7 +17924,7 @@ function gfmTableToMarkdown(options) {
18016
17924
  handlers: {
18017
17925
  inlineCode: inlineCodeWithTable,
18018
17926
  table: handleTable,
18019
- tableCell: handleTableCell,
17927
+ tableCell: handleTableCell2,
18020
17928
  tableRow: handleTableRow
18021
17929
  }
18022
17930
  };
@@ -18028,7 +17936,7 @@ function gfmTableToMarkdown(options) {
18028
17936
  const value = serializeData([row2]);
18029
17937
  return value.slice(0, value.indexOf("\n"));
18030
17938
  }
18031
- function handleTableCell(node2, _, state, info) {
17939
+ function handleTableCell2(node2, _, state, info) {
18032
17940
  const exit2 = state.enter("tableCell");
18033
17941
  const subexit = state.enter("phrasing");
18034
17942
  const value = state.containerPhrasing(node2, {
@@ -18068,7 +17976,7 @@ function gfmTableToMarkdown(options) {
18068
17976
  const result = [];
18069
17977
  const subexit = state.enter("tableRow");
18070
17978
  while (++index2 < children.length) {
18071
- result[index2] = handleTableCell(children[index2], node2, state, info);
17979
+ result[index2] = handleTableCell2(children[index2], node2, state, info);
18072
17980
  }
18073
17981
  subexit();
18074
17982
  return result;
@@ -18098,14 +18006,14 @@ function gfmTaskListItemToMarkdown() {
18098
18006
  }
18099
18007
  function exitCheck(token) {
18100
18008
  const node2 = this.stack[this.stack.length - 2];
18101
- ok(node2.type === "listItem");
18009
+ ok$1(node2.type === "listItem");
18102
18010
  node2.checked = token.type === "taskListCheckValueChecked";
18103
18011
  }
18104
18012
  function exitParagraphWithTaskListItem(token) {
18105
18013
  const parent = this.stack[this.stack.length - 2];
18106
18014
  if (parent && parent.type === "listItem" && typeof parent.checked === "boolean") {
18107
18015
  const node2 = this.stack[this.stack.length - 1];
18108
- ok(node2.type === "paragraph");
18016
+ ok$1(node2.type === "paragraph");
18109
18017
  const head2 = node2.children[0];
18110
18018
  if (head2 && head2.type === "text") {
18111
18019
  const siblings2 = parent.children;
@@ -19639,7 +19547,7 @@ function requireExtend() {
19639
19547
  return obj[name];
19640
19548
  };
19641
19549
  extend$1 = function extend2() {
19642
- var options, name, src, copy, copyIsArray, clone2;
19550
+ var options, name, src, copy, copyIsArray, clone;
19643
19551
  var target = arguments[0];
19644
19552
  var i = 1;
19645
19553
  var length = arguments.length;
@@ -19662,11 +19570,11 @@ function requireExtend() {
19662
19570
  if (deep && copy && (isPlainObject2(copy) || (copyIsArray = isArray(copy)))) {
19663
19571
  if (copyIsArray) {
19664
19572
  copyIsArray = false;
19665
- clone2 = src && isArray(src) ? src : [];
19573
+ clone = src && isArray(src) ? src : [];
19666
19574
  } else {
19667
- clone2 = src && isPlainObject2(src) ? src : {};
19575
+ clone = src && isPlainObject2(src) ? src : {};
19668
19576
  }
19669
- setProperty(target, { name, newValue: extend2(deep, clone2, copy) });
19577
+ setProperty(target, { name, newValue: extend2(deep, clone, copy) });
19670
19578
  } else if (typeof copy !== "undefined") {
19671
19579
  setProperty(target, { name, newValue: copy });
19672
19580
  }
@@ -20422,42 +20330,6 @@ function isUint8Array(value) {
20422
20330
  value && typeof value === "object" && "byteLength" in value && "byteOffset" in value
20423
20331
  );
20424
20332
  }
20425
- const rehypeSanitizeHtml = () => {
20426
- return (tree) => {
20427
- visit(tree, (node2, index2, parent) => {
20428
- if (!parent || typeof index2 !== "number") {
20429
- return;
20430
- }
20431
- if (node2.type === "comment" && node2.value.trim() === "") {
20432
- parent.children.splice(index2, 1);
20433
- return index2;
20434
- }
20435
- if (node2.type === "element" && node2.children) {
20436
- const newChildren = [];
20437
- let textBuffer = "";
20438
- const flushTextBuffer = () => {
20439
- if (textBuffer) {
20440
- const cleanedText = textBuffer.replace(/\s+/g, " ");
20441
- newChildren.push({ type: "text", value: cleanedText });
20442
- textBuffer = "";
20443
- }
20444
- };
20445
- for (const child of node2.children) {
20446
- if (child.type === "text") {
20447
- textBuffer += child.value;
20448
- } else if (child.type === "comment" && child.value.trim() === "") {
20449
- continue;
20450
- } else {
20451
- flushTextBuffer();
20452
- newChildren.push(child);
20453
- }
20454
- }
20455
- flushTextBuffer();
20456
- node2.children = newChildren;
20457
- }
20458
- });
20459
- };
20460
- };
20461
20333
  const rehypeAbsoluteLinks = (options) => {
20462
20334
  const { baseUrl } = options;
20463
20335
  const tagAttributeMap = {
@@ -20494,13 +20366,11 @@ const rehypeAbsoluteLinks = (options) => {
20494
20366
  const trimmedPart = part.trim();
20495
20367
  if (!trimmedPart) return "";
20496
20368
  const parts = trimmedPart.split(/\s+/);
20369
+ if (parts.length === 0) return "";
20497
20370
  const url = parts[0];
20498
- const descriptor = parts.slice(1).join(" ");
20499
- if (url) {
20500
- const absoluteUrl = resolveUrl(url);
20501
- return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
20502
- }
20503
- return trimmedPart;
20371
+ const absoluteUrl = resolveUrl(url);
20372
+ parts[0] = absoluteUrl;
20373
+ return parts.join(" ");
20504
20374
  }).filter(Boolean).join(", ");
20505
20375
  node2.properties[attr] = newSrcset;
20506
20376
  } else {
@@ -20512,6 +20382,41 @@ const rehypeAbsoluteLinks = (options) => {
20512
20382
  });
20513
20383
  };
20514
20384
  };
20385
+ const rehypeSanitizeHtml = () => {
20386
+ return (tree) => {
20387
+ visit(tree, (node2, index2, parent) => {
20388
+ if (!parent || typeof index2 !== "number") {
20389
+ return;
20390
+ }
20391
+ if (node2.type === "comment" && node2.value.trim() === "") {
20392
+ parent.children.splice(index2, 1);
20393
+ return index2;
20394
+ }
20395
+ if (node2.type === "element" && node2.children) {
20396
+ const newChildren = [];
20397
+ let textBuffer = "";
20398
+ const flushTextBuffer = () => {
20399
+ if (textBuffer) {
20400
+ const cleanedText = textBuffer.replace(/\s+/g, " ");
20401
+ newChildren.push({ type: "text", value: cleanedText });
20402
+ textBuffer = "";
20403
+ }
20404
+ };
20405
+ for (const child of node2.children) {
20406
+ if (child.type === "text") {
20407
+ textBuffer += child.value;
20408
+ } else if (child.type === "comment" && child.value.trim() === "") ;
20409
+ else {
20410
+ flushTextBuffer();
20411
+ newChildren.push(child);
20412
+ }
20413
+ }
20414
+ flushTextBuffer();
20415
+ node2.children = newChildren;
20416
+ }
20417
+ });
20418
+ };
20419
+ };
20515
20420
  const rehypeWikipediaFootnotes = () => {
20516
20421
  return (tree) => {
20517
20422
  const footnotes = [];
@@ -20569,22 +20474,82 @@ const rehypeWikipediaFootnotes = () => {
20569
20474
  }
20570
20475
  };
20571
20476
  };
20477
+ const handleTableCell = (_state, node2, _parent) => {
20478
+ const allowedTags = ["br", "hr", "h1", "h2", "h3", "h4", "h5", "h6", "strong", "em", "b", "i", "u", "s", "strike", "del", "ins", "code", "ul", "ol", "li", "a", "img", "blockquote", "pre", "table", "thead", "tbody", "tfoot", "tr", "th", "td"];
20479
+ const allowedAttributes = ["style", "class", "id", "colspan", "rowspan", "width", "height", "align", "href", "src", "title", "alt"];
20480
+ visit(node2, "element", (elementNode, index2, parent) => {
20481
+ if (!parent || typeof index2 !== "number") {
20482
+ return;
20483
+ }
20484
+ if (elementNode.tagName === "div") {
20485
+ const style2 = elementNode.properties?.style;
20486
+ const isHorizontalLayout = /display:\s*(inline-block|flex|inline-flex)|float:\s*(left|right)/.test(style2 ?? "");
20487
+ if (isHorizontalLayout) {
20488
+ for (const child of elementNode.children) {
20489
+ if (child.type === "element" && child.tagName === "div") {
20490
+ child.tagName = "span";
20491
+ }
20492
+ }
20493
+ const newChildren = [];
20494
+ const separator = { type: "text", value: " " };
20495
+ elementNode.children.forEach((child, i) => {
20496
+ newChildren.push(child);
20497
+ if (i < elementNode.children.length - 1) {
20498
+ newChildren.push(separator);
20499
+ }
20500
+ });
20501
+ parent.children.splice(index2, 1, ...newChildren);
20502
+ return index2;
20503
+ }
20504
+ const brNode = { type: "element", tagName: "br", properties: {}, children: [] };
20505
+ const nodesToInsert = [...elementNode.children];
20506
+ const prevNode = parent.children[index2 - 1];
20507
+ const nextNode = parent.children[index2 + 1];
20508
+ const prevIsBr = prevNode && prevNode.type === "element" && prevNode.tagName === "br";
20509
+ const nextIsBr = nextNode && nextNode.type === "element" && nextNode.tagName === "br";
20510
+ if (prevIsBr !== void 0 && !prevIsBr) {
20511
+ nodesToInsert.unshift(brNode);
20512
+ }
20513
+ if (nextIsBr !== void 0 && !nextIsBr) {
20514
+ nodesToInsert.push(brNode);
20515
+ }
20516
+ parent.children.splice(index2, 1, ...nodesToInsert);
20517
+ return index2;
20518
+ }
20519
+ if (!allowedTags.includes(elementNode.tagName)) {
20520
+ parent.children.splice(index2, 1, ...elementNode.children);
20521
+ return index2;
20522
+ }
20523
+ if (elementNode.properties) {
20524
+ Object.keys(elementNode.properties).forEach((key2) => {
20525
+ if (!allowedAttributes.includes(key2)) {
20526
+ delete elementNode.properties[key2];
20527
+ }
20528
+ });
20529
+ }
20530
+ });
20531
+ const value = toHtml(node2.children, { allowDangerousHtml: true });
20532
+ return { type: "tableCell", children: [{ type: "html", value }] };
20533
+ };
20572
20534
  const convertHtmlToMarkdown = async (html2, baseUrl, locale) => {
20573
20535
  console.log(getMessage(locale, "convert_start"));
20574
- const file = await unified().use(rehypeParse, { fragment: true }).use(rehypeRaw).use(rehypeSanitizeHtml).use(rehypeSlug).use(rehypeAutolinkHeadings, { behavior: "wrap" }).use(rehypeAbsoluteLinks, { baseUrl }).use(rehypeWikipediaFootnotes).use(rehypeRemark, {
20536
+ const slugger = new BananaSlug();
20537
+ const file = await unified().use(rehypeParse, { fragment: true }).use(rehypeRaw).use(rehypeSanitizeHtml).use(rehypeSlug).use(rehypeAbsoluteLinks, { baseUrl }).use(rehypeWikipediaFootnotes).use(rehypeRemark, {
20575
20538
  handlers: {
20576
20539
  a(state, node2) {
20577
20540
  const hasComplexChildren = node2.children.some((child) => child.type === "element" && ["dl", "ul", "ol", "table", "div"].includes(child.tagName));
20578
20541
  if (hasComplexChildren && node2.properties?.href) {
20579
20542
  const linkText2 = String(node2.properties.ariaLabel || "");
20580
- const url = String(node2.properties.href);
20581
- const linkNode = {
20582
- type: "link",
20583
- url,
20584
- children: [{ type: "text", value: linkText2 }]
20585
- };
20586
- const otherContent = state.all(node2);
20587
- return [linkNode, { type: "text", value: "\n" }, ...otherContent];
20543
+ if (linkText2) {
20544
+ const url2 = String(node2.properties.href);
20545
+ const linkNode = {
20546
+ type: "link",
20547
+ url: url2,
20548
+ children: [{ type: "text", value: linkText2 }]
20549
+ };
20550
+ const otherContent = state.all(node2);
20551
+ return [linkNode, { type: "text", value: "\n" }, ...otherContent];
20552
+ }
20588
20553
  }
20589
20554
  const extractTextFromHast = (n) => {
20590
20555
  if (n.type === "text") {
@@ -20596,8 +20561,12 @@ const convertHtmlToMarkdown = async (html2, baseUrl, locale) => {
20596
20561
  return "";
20597
20562
  };
20598
20563
  let linkText = extractTextFromHast(node2).replace(/\s+/g, " ").trim();
20599
- if (!linkText && node2.properties?.ariaLabel) {
20600
- linkText = String(node2.properties.ariaLabel);
20564
+ if (!linkText) {
20565
+ const props = node2.properties || {};
20566
+ linkText = String(props.ariaLabel || props.title || props.href || "");
20567
+ }
20568
+ if (!linkText) {
20569
+ return state.all(node2);
20601
20570
  }
20602
20571
  const containsImage = (hastNode) => {
20603
20572
  if (!hastNode.children) return false;
@@ -20621,96 +20590,22 @@ const convertHtmlToMarkdown = async (html2, baseUrl, locale) => {
20621
20590
  children: state.all(node2)
20622
20591
  };
20623
20592
  }
20593
+ let url = String(node2.properties?.href || "");
20594
+ if (url.startsWith("#")) {
20595
+ url = `#${slugger.slug(url.substring(1))}`;
20596
+ }
20624
20597
  return {
20625
20598
  type: "link",
20626
- url: String(node2.properties?.href || ""),
20599
+ url,
20627
20600
  title: node2.properties?.title ? String(node2.properties.title) : null,
20628
20601
  children: [{ type: "text", value: linkText }]
20629
20602
  };
20630
20603
  },
20631
- td(state, node2) {
20632
- const allowedTags = ["p", "br", "hr", "h1", "h2", "h3", "h4", "h5", "h6", "strong", "em", "b", "i", "u", "s", "strike", "del", "ins", "code", "ul", "ol", "li", "a", "img", "blockquote", "pre", "table", "thead", "tbody", "tfoot", "tr", "th", "td"];
20633
- const allowedAttributes = ["style", "class", "id", "colspan", "rowspan", "width", "height", "align", "href", "src", "title", "alt"];
20634
- visit(node2, "element", (elementNode, index2, parent) => {
20635
- if (!parent || typeof index2 !== "number") {
20636
- return;
20637
- }
20638
- if (elementNode.tagName === "div") {
20639
- const brNode = { type: "element", tagName: "br", properties: {}, children: [] };
20640
- let nodesToInsert = [...elementNode.children];
20641
- const style2 = elementNode.properties?.style;
20642
- const isHorizontalLayout = style2 ? /display:\s*(inline-block|flex|inline-flex)|float:\s*(left|right)/.test(style2) : false;
20643
- if (!isHorizontalLayout) {
20644
- const prevNode = parent.children[index2 - 1];
20645
- const nextNode = parent.children[index2 + 1];
20646
- const prevIsBr = prevNode && prevNode.type === "element" && prevNode.tagName === "br";
20647
- const nextIsBr = nextNode && nextNode.type === "element" && nextNode.tagName === "br";
20648
- if (index2 > 0 && !prevIsBr) {
20649
- nodesToInsert.unshift(brNode);
20650
- }
20651
- if (index2 < parent.children.length - 1 && !nextIsBr) {
20652
- nodesToInsert.push(brNode);
20653
- }
20654
- }
20655
- parent.children.splice(index2, 1, ...nodesToInsert);
20656
- return index2;
20657
- }
20658
- if (!allowedTags.includes(elementNode.tagName)) {
20659
- parent.children.splice(index2, 1, ...elementNode.children);
20660
- return index2;
20661
- }
20662
- if (elementNode.properties) {
20663
- Object.keys(elementNode.properties).forEach((key2) => {
20664
- if (!allowedAttributes.includes(key2)) {
20665
- delete elementNode.properties[key2];
20666
- }
20667
- });
20668
- }
20669
- });
20670
- const value = toHtml(node2.children, { allowDangerousHtml: true });
20671
- return { type: "tableCell", children: [{ type: "html", value }] };
20604
+ td(state, node2, parent) {
20605
+ return handleTableCell(state, node2);
20672
20606
  },
20673
- th(state, node2) {
20674
- const allowedTags = ["p", "br", "hr", "h1", "h2", "h3", "h4", "h5", "h6", "strong", "em", "b", "i", "u", "s", "strike", "del", "ins", "code", "ul", "ol", "li", "a", "img", "blockquote", "pre", "table", "thead", "tbody", "tfoot", "tr", "th", "td"];
20675
- const allowedAttributes = ["style", "class", "id", "colspan", "rowspan", "width", "height", "align", "href", "src", "title", "alt"];
20676
- visit(node2, "element", (elementNode, index2, parent) => {
20677
- if (!parent || typeof index2 !== "number") {
20678
- return;
20679
- }
20680
- if (elementNode.tagName === "div") {
20681
- const brNode = { type: "element", tagName: "br", properties: {}, children: [] };
20682
- let nodesToInsert = [...elementNode.children];
20683
- const style2 = elementNode.properties?.style;
20684
- const isHorizontalLayout = style2 ? /display:\s*(inline-block|flex|inline-flex)|float:\s*(left|right)/.test(style2) : false;
20685
- if (!isHorizontalLayout) {
20686
- const prevNode = parent.children[index2 - 1];
20687
- const nextNode = parent.children[index2 + 1];
20688
- const prevIsBr = prevNode && prevNode.type === "element" && prevNode.tagName === "br";
20689
- const nextIsBr = nextNode && nextNode.type === "element" && nextNode.tagName === "br";
20690
- if (index2 > 0 && !prevIsBr) {
20691
- nodesToInsert.unshift(brNode);
20692
- }
20693
- if (index2 < parent.children.length - 1 && !nextIsBr) {
20694
- nodesToInsert.push(brNode);
20695
- }
20696
- }
20697
- parent.children.splice(index2, 1, ...nodesToInsert);
20698
- return index2;
20699
- }
20700
- if (!allowedTags.includes(elementNode.tagName)) {
20701
- parent.children.splice(index2, 1, ...elementNode.children);
20702
- return index2;
20703
- }
20704
- if (elementNode.properties) {
20705
- Object.keys(elementNode.properties).forEach((key2) => {
20706
- if (!allowedAttributes.includes(key2)) {
20707
- delete elementNode.properties[key2];
20708
- }
20709
- });
20710
- }
20711
- });
20712
- const value = toHtml(node2.children, { allowDangerousHtml: true });
20713
- return { type: "tableCell", children: [{ type: "html", value }] };
20607
+ th(state, node2, parent) {
20608
+ return handleTableCell(state, node2);
20714
20609
  }
20715
20610
  }
20716
20611
  }).use(remarkGfm).use(remarkStringify, {
@@ -20729,15 +20624,20 @@ const convertHtmlToMarkdown = async (html2, baseUrl, locale) => {
20729
20624
  return correctedMarkdown;
20730
20625
  };
20731
20626
  const htmlToMarkdown = async (url, options = {}) => {
20627
+ const { locale = "en-US" } = options;
20732
20628
  try {
20733
20629
  new URL(url);
20734
- } catch {
20735
- throw new Error(`Invalid URL format: ${url}`);
20630
+ const htmlContent = await getHtmlWithPlaywright(url, locale);
20631
+ if (!htmlContent) {
20632
+ console.error(`No HTML content found for URL: ${url}`);
20633
+ return "";
20634
+ }
20635
+ const markdown = await convertHtmlToMarkdown(htmlContent, url, locale);
20636
+ return markdown;
20637
+ } catch (error) {
20638
+ console.error(`An error occurred during the conversion process for URL: ${url}`, error);
20639
+ return "";
20736
20640
  }
20737
- const { locale = "en-US" } = options;
20738
- const htmlContent = await getHtmlWithPlaywright(url, locale);
20739
- const markdown = await convertHtmlToMarkdown(htmlContent, url, locale);
20740
- return markdown;
20741
20641
  };
20742
20642
  export {
20743
20643
  getMessage as g,