nuxt-ai-ready 2.5.0 → 2.5.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.
Files changed (206) hide show
  1. package/dist/chunks/agent-skills.mjs +1 -1
  2. package/dist/chunks/prerender.mjs +1 -1
  3. package/dist/cli.mjs +2 -0
  4. package/dist/module.json +1 -1
  5. package/dist/module.mjs +1 -1
  6. package/dist/runtime/server/db/drizzle/queries.js +0 -1
  7. package/dist/runtime/server/db/queries.d.ts +2 -0
  8. package/dist/runtime/server/db/queries.js +11 -5
  9. package/dist/runtime/server/db/seed.d.ts +2 -2
  10. package/dist/runtime/server/routes/__ai-ready/reindex.post.js +2 -0
  11. package/dist/runtime/server/utils/batchIndex.js +4 -2
  12. package/dist/runtime/server/utils/checkStale.d.ts +1 -1
  13. package/dist/runtime/server/utils/checkStale.js +1 -1
  14. package/dist/runtime/server/utils/indexPage.d.ts +8 -1
  15. package/dist/runtime/server/utils/indexPage.js +13 -5
  16. package/dist/shared/{nuxt-ai-ready.DsokNmXc.mjs → nuxt-ai-ready.CLSWou20.mjs} +2 -0
  17. package/node_modules/@mdream/js/LICENSE.md +9 -0
  18. package/node_modules/@mdream/js/README.md +792 -0
  19. package/node_modules/@mdream/js/bin/mdream.mjs +2 -0
  20. package/node_modules/@mdream/js/dist/_chunks/const.mjs +134 -0
  21. package/node_modules/@mdream/js/dist/_chunks/index.d.mts +9 -0
  22. package/node_modules/@mdream/js/dist/_chunks/markdown-processor.mjs +1968 -0
  23. package/node_modules/@mdream/js/dist/_chunks/minimal.d.mts +6 -0
  24. package/node_modules/@mdream/js/dist/_chunks/parse.mjs +2756 -0
  25. package/node_modules/@mdream/js/dist/_chunks/plugins.mjs +725 -0
  26. package/node_modules/@mdream/js/dist/_chunks/resolve-plugins.mjs +44 -0
  27. package/node_modules/@mdream/js/dist/_chunks/stream.mjs +37 -0
  28. package/node_modules/@mdream/js/dist/_chunks/types.d.mts +473 -0
  29. package/node_modules/@mdream/js/dist/cli.d.mts +1 -0
  30. package/node_modules/@mdream/js/dist/cli.mjs +32 -0
  31. package/node_modules/@mdream/js/dist/core.d.mts +15 -0
  32. package/node_modules/@mdream/js/dist/core.mjs +28 -0
  33. package/node_modules/@mdream/js/dist/index.d.mts +4 -0
  34. package/node_modules/@mdream/js/dist/index.mjs +58 -0
  35. package/node_modules/@mdream/js/dist/llms-txt.d.mts +86 -0
  36. package/node_modules/@mdream/js/dist/llms-txt.mjs +308 -0
  37. package/node_modules/@mdream/js/dist/negotiate.d.mts +35 -0
  38. package/node_modules/@mdream/js/dist/negotiate.mjs +121 -0
  39. package/node_modules/@mdream/js/dist/parse.d.mts +90 -0
  40. package/node_modules/@mdream/js/dist/parse.mjs +2 -0
  41. package/node_modules/@mdream/js/dist/plugins.d.mts +85 -0
  42. package/node_modules/@mdream/js/dist/plugins.mjs +2 -0
  43. package/node_modules/@mdream/js/dist/preset/minimal.d.mts +2 -0
  44. package/node_modules/@mdream/js/dist/preset/minimal.mjs +33 -0
  45. package/node_modules/@mdream/js/dist/splitter.d.mts +18 -0
  46. package/node_modules/@mdream/js/dist/splitter.mjs +194 -0
  47. package/node_modules/@mdream/js/package.json +103 -0
  48. package/node_modules/cac/LICENSE +21 -0
  49. package/node_modules/cac/README.md +492 -0
  50. package/node_modules/cac/dist/index.d.ts +196 -0
  51. package/node_modules/cac/dist/index.js +638 -0
  52. package/node_modules/cac/package.json +72 -0
  53. package/node_modules/mdream/LICENSE.md +9 -0
  54. package/node_modules/mdream/README.md +1091 -0
  55. package/node_modules/mdream/bin/mdream.mjs +46 -0
  56. package/node_modules/mdream/dist/browser.d.mts +105 -0
  57. package/node_modules/mdream/dist/browser.mjs +262 -0
  58. package/node_modules/mdream/dist/edge.d.mts +100 -0
  59. package/node_modules/mdream/dist/edge.mjs +250 -0
  60. package/node_modules/mdream/dist/iife.js +605 -0
  61. package/node_modules/mdream/dist/index.d.mts +89 -0
  62. package/node_modules/mdream/dist/index.mjs +184 -0
  63. package/node_modules/mdream/dist/wasm.d.mts +100 -0
  64. package/node_modules/mdream/dist/wasm.mjs +140 -0
  65. package/node_modules/mdream/dist/worker.d.mts +101 -0
  66. package/node_modules/mdream/dist/worker.mjs +217 -0
  67. package/node_modules/mdream/napi/index.d.mts +127 -0
  68. package/node_modules/mdream/napi/index.d.ts +127 -0
  69. package/node_modules/mdream/napi/index.mjs +725 -0
  70. package/node_modules/mdream/napi/rust.android-arm-eabi.node +0 -0
  71. package/node_modules/mdream/napi/rust.android-arm64.node +0 -0
  72. package/node_modules/mdream/napi/rust.darwin-arm64.node +0 -0
  73. package/node_modules/mdream/napi/rust.darwin-x64.node +0 -0
  74. package/node_modules/mdream/napi/rust.freebsd-x64.node +0 -0
  75. package/node_modules/mdream/napi/rust.linux-arm-gnueabihf.node +0 -0
  76. package/node_modules/mdream/napi/rust.linux-arm64-gnu.node +0 -0
  77. package/node_modules/mdream/napi/rust.linux-arm64-musl.node +0 -0
  78. package/node_modules/mdream/napi/rust.linux-x64-gnu.node +0 -0
  79. package/node_modules/mdream/napi/rust.linux-x64-musl.node +0 -0
  80. package/node_modules/mdream/napi/rust.wasi.cjs +2144 -0
  81. package/node_modules/mdream/napi/rust.wasm32-wasi.wasm +0 -0
  82. package/node_modules/mdream/napi/rust.win32-arm64-msvc.node +0 -0
  83. package/node_modules/mdream/napi/rust.win32-x64-msvc.node +0 -0
  84. package/node_modules/mdream/node_modules/@emnapi/core/LICENSE +21 -0
  85. package/node_modules/mdream/node_modules/@emnapi/core/README.md +1 -0
  86. package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.d.ts +392 -0
  87. package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.full.d.ts +392 -0
  88. package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.full.js +8351 -0
  89. package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.js +7268 -0
  90. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/async-work.d.ts +5 -0
  91. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/async-work.js +843 -0
  92. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/index.d.ts +4 -0
  93. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/index.js +3 -0
  94. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/threadsafe-function.d.ts +5 -0
  95. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/threadsafe-function.js +1010 -0
  96. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/v8.d.ts +5 -0
  97. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/v8.js +1446 -0
  98. package/node_modules/mdream/node_modules/@emnapi/core/package.json +39 -0
  99. package/node_modules/mdream/node_modules/@emnapi/core/rollup.config.js +60 -0
  100. package/node_modules/mdream/node_modules/@emnapi/runtime/LICENSE +21 -0
  101. package/node_modules/mdream/node_modules/@emnapi/runtime/README.md +1 -0
  102. package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.d.ts +833 -0
  103. package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.js +2306 -0
  104. package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.js.map +1 -0
  105. package/node_modules/mdream/node_modules/@emnapi/runtime/index.cjs +63 -0
  106. package/node_modules/mdream/node_modules/@emnapi/runtime/package.json +39 -0
  107. package/node_modules/mdream/node_modules/@emnapi/runtime/rollup.config.js +25 -0
  108. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/LICENSE +21 -0
  109. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/README.md +203 -0
  110. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +236 -0
  111. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +1086 -0
  112. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/package.json +35 -0
  113. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/rollup.config.js +6 -0
  114. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.cjs +1472 -0
  115. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.js +1470 -0
  116. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/fs-proxy.cjs +237 -0
  117. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/fs.js +18260 -0
  118. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/fs-proxy.js +317 -0
  119. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/package.json +67 -0
  120. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/runtime.cjs +39 -0
  121. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/runtime.js +36 -0
  122. package/node_modules/mdream/node_modules/@tybys/wasm-util/LICENSE +21 -0
  123. package/node_modules/mdream/node_modules/@tybys/wasm-util/README.md +193 -0
  124. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/tsdoc-metadata.json +11 -0
  125. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.d.ts +423 -0
  126. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm-bundler.js +2932 -0
  127. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm.js +2932 -0
  128. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm.min.js +1 -0
  129. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.js +2954 -0
  130. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.min.js +1 -0
  131. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/asyncify.js +158 -0
  132. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/index.js +13 -0
  133. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/jspi.js +46 -0
  134. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/load.js +97 -0
  135. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/memory.js +35 -0
  136. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/error.js +103 -0
  137. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/fd.js +268 -0
  138. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/fs.js +3 -0
  139. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/index.js +192 -0
  140. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/path.js +316 -0
  141. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/preview1.js +1599 -0
  142. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/rights.js +141 -0
  143. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/types.js +220 -0
  144. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/util.js +128 -0
  145. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/webassembly.js +13 -0
  146. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/asyncify.mjs +153 -0
  147. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/index.mjs +9 -0
  148. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/jspi.mjs +39 -0
  149. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/load.mjs +89 -0
  150. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/memory.mjs +28 -0
  151. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/error.mjs +97 -0
  152. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/fd.mjs +256 -0
  153. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/fs.mjs +1 -0
  154. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/index.mjs +186 -0
  155. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/path.mjs +310 -0
  156. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/preview1.mjs +1593 -0
  157. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/rights.mjs +135 -0
  158. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/types.mjs +216 -0
  159. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/util.mjs +113 -0
  160. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/webassembly.mjs +9 -0
  161. package/node_modules/mdream/node_modules/@tybys/wasm-util/package.json +58 -0
  162. package/node_modules/mdream/node_modules/tslib/CopyrightNotice.txt +15 -0
  163. package/node_modules/mdream/node_modules/tslib/LICENSE.txt +12 -0
  164. package/node_modules/mdream/node_modules/tslib/README.md +164 -0
  165. package/node_modules/mdream/node_modules/tslib/SECURITY.md +41 -0
  166. package/node_modules/mdream/node_modules/tslib/modules/index.d.ts +38 -0
  167. package/node_modules/mdream/node_modules/tslib/modules/index.js +70 -0
  168. package/node_modules/mdream/node_modules/tslib/modules/package.json +3 -0
  169. package/node_modules/mdream/node_modules/tslib/package.json +47 -0
  170. package/node_modules/mdream/node_modules/tslib/tslib.d.ts +460 -0
  171. package/node_modules/mdream/node_modules/tslib/tslib.es6.html +1 -0
  172. package/node_modules/mdream/node_modules/tslib/tslib.es6.js +402 -0
  173. package/node_modules/mdream/node_modules/tslib/tslib.es6.mjs +401 -0
  174. package/node_modules/mdream/node_modules/tslib/tslib.html +1 -0
  175. package/node_modules/mdream/node_modules/tslib/tslib.js +484 -0
  176. package/node_modules/mdream/package.json +110 -0
  177. package/node_modules/mdream/skills/mdream/SKILL.md +124 -0
  178. package/node_modules/mdream/skills/mdream/references/runtimes.md +49 -0
  179. package/node_modules/mdream/wasm/mdream_edge.d.ts +90 -0
  180. package/node_modules/mdream/wasm/mdream_edge.js +517 -0
  181. package/node_modules/mdream/wasm/mdream_edge_bg.wasm +0 -0
  182. package/node_modules/mdream/wasm/mdream_edge_bg.wasm.d.ts +20 -0
  183. package/node_modules/mdream/wasm/package.json +17 -0
  184. package/node_modules/mdream/wasm-bundler/mdream_edge.d.ts +45 -0
  185. package/node_modules/mdream/wasm-bundler/mdream_edge.js +13 -0
  186. package/node_modules/mdream/wasm-bundler/mdream_edge_bg.js +413 -0
  187. package/node_modules/mdream/wasm-bundler/mdream_edge_bg.wasm +0 -0
  188. package/node_modules/mdream/wasm-bundler/mdream_edge_bg.wasm.d.ts +20 -0
  189. package/node_modules/mdream/wasm-bundler/package.json +19 -0
  190. package/node_modules/pathe/LICENSE +70 -0
  191. package/node_modules/pathe/README.md +73 -0
  192. package/node_modules/pathe/dist/index.cjs +39 -0
  193. package/node_modules/pathe/dist/index.d.cts +47 -0
  194. package/node_modules/pathe/dist/index.d.mts +47 -0
  195. package/node_modules/pathe/dist/index.d.ts +47 -0
  196. package/node_modules/pathe/dist/index.mjs +19 -0
  197. package/node_modules/pathe/dist/shared/pathe.BSlhyZSM.cjs +266 -0
  198. package/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs +249 -0
  199. package/node_modules/pathe/dist/utils.cjs +82 -0
  200. package/node_modules/pathe/dist/utils.d.cts +32 -0
  201. package/node_modules/pathe/dist/utils.d.mts +32 -0
  202. package/node_modules/pathe/dist/utils.d.ts +32 -0
  203. package/node_modules/pathe/dist/utils.mjs +77 -0
  204. package/node_modules/pathe/package.json +61 -0
  205. package/node_modules/pathe/utils.d.ts +1 -0
  206. package/package.json +8 -64
@@ -0,0 +1,2756 @@
1
+ import { BLOCKQUOTE_SPACING, LIST_ITEM_SPACING, NO_SPACING, TABLE_ROW_SPACING, TagIdMap, isInsideRawHtmlBlock } from "./const.mjs";
2
+ const HTML_ENTITIES = {
3
+ AElig: "Æ",
4
+ AMP: "&",
5
+ Aacute: "Á",
6
+ Acirc: "Â",
7
+ Agrave: "À",
8
+ $Alpha: "Α",
9
+ Aring: "Å",
10
+ Atilde: "Ã",
11
+ Auml: "Ä",
12
+ $Beta: "Β",
13
+ COPY: "©",
14
+ Ccedil: "Ç",
15
+ $Chi: "Χ",
16
+ $Dagger: "‡",
17
+ $Delta: "Δ",
18
+ ETH: "Ð",
19
+ Eacute: "É",
20
+ Ecirc: "Ê",
21
+ Egrave: "È",
22
+ $Epsilon: "Ε",
23
+ $Eta: "Η",
24
+ Euml: "Ë",
25
+ GT: ">",
26
+ $Gamma: "Γ",
27
+ Iacute: "Í",
28
+ Icirc: "Î",
29
+ Igrave: "Ì",
30
+ $Iota: "Ι",
31
+ Iuml: "Ï",
32
+ $Kappa: "Κ",
33
+ LT: "<",
34
+ $Lambda: "Λ",
35
+ $Mu: "Μ",
36
+ Ntilde: "Ñ",
37
+ $Nu: "Ν",
38
+ $OElig: "Œ",
39
+ Oacute: "Ó",
40
+ Ocirc: "Ô",
41
+ Ograve: "Ò",
42
+ $Omega: "Ω",
43
+ $Omicron: "Ο",
44
+ Oslash: "Ø",
45
+ Otilde: "Õ",
46
+ Ouml: "Ö",
47
+ $Phi: "Φ",
48
+ $Pi: "Π",
49
+ $Prime: "″",
50
+ $Psi: "Ψ",
51
+ QUOT: "\"",
52
+ REG: "®",
53
+ $Rho: "Ρ",
54
+ $Scaron: "Š",
55
+ $Sigma: "Σ",
56
+ THORN: "Þ",
57
+ $Tau: "Τ",
58
+ $Theta: "Θ",
59
+ Uacute: "Ú",
60
+ Ucirc: "Û",
61
+ Ugrave: "Ù",
62
+ $Upsilon: "Υ",
63
+ Uuml: "Ü",
64
+ $Xi: "Ξ",
65
+ Yacute: "Ý",
66
+ $Yuml: "Ÿ",
67
+ $Zeta: "Ζ",
68
+ aacute: "á",
69
+ acirc: "â",
70
+ acute: "´",
71
+ aelig: "æ",
72
+ agrave: "à",
73
+ $alefsym: "ℵ",
74
+ $alpha: "α",
75
+ amp: "&",
76
+ $and: "∧",
77
+ $ang: "∠",
78
+ $apos: "'",
79
+ aring: "å",
80
+ $asymp: "≈",
81
+ atilde: "ã",
82
+ auml: "ä",
83
+ $bdquo: "„",
84
+ $beta: "β",
85
+ brvbar: "¦",
86
+ $bull: "•",
87
+ $cap: "∩",
88
+ ccedil: "ç",
89
+ cedil: "¸",
90
+ cent: "¢",
91
+ $chi: "χ",
92
+ $circ: "ˆ",
93
+ $clubs: "♣",
94
+ $cong: "≅",
95
+ copy: "©",
96
+ $crarr: "↵",
97
+ $cup: "∪",
98
+ curren: "¤",
99
+ $dArr: "⇓",
100
+ $dagger: "†",
101
+ $darr: "↓",
102
+ deg: "°",
103
+ $delta: "δ",
104
+ $diams: "♦",
105
+ divide: "÷",
106
+ eacute: "é",
107
+ ecirc: "ê",
108
+ egrave: "è",
109
+ $empty: "∅",
110
+ $epsilon: "ε",
111
+ $equiv: "≡",
112
+ $eta: "η",
113
+ eth: "ð",
114
+ euml: "ë",
115
+ $euro: "€",
116
+ $exist: "∃",
117
+ $fnof: "ƒ",
118
+ $forall: "∀",
119
+ frac12: "½",
120
+ frac14: "¼",
121
+ frac34: "¾",
122
+ $frasl: "⁄",
123
+ $gamma: "γ",
124
+ $ge: "≥",
125
+ gt: ">",
126
+ $hArr: "⇔",
127
+ $harr: "↔",
128
+ $hearts: "♥",
129
+ $hellip: "…",
130
+ iacute: "í",
131
+ icirc: "î",
132
+ iexcl: "¡",
133
+ igrave: "ì",
134
+ $image: "ℑ",
135
+ $infin: "∞",
136
+ $int: "∫",
137
+ $iota: "ι",
138
+ iquest: "¿",
139
+ $isin: "∈",
140
+ iuml: "ï",
141
+ $kappa: "κ",
142
+ $lArr: "⇐",
143
+ $lambda: "λ",
144
+ $lang: "⟨",
145
+ laquo: "«",
146
+ $larr: "←",
147
+ $lceil: "⌈",
148
+ $ldquo: "“",
149
+ $le: "≤",
150
+ $lfloor: "⌊",
151
+ $lowast: "∗",
152
+ $loz: "◊",
153
+ $lsaquo: "‹",
154
+ $lsquo: "‘",
155
+ lt: "<",
156
+ macr: "¯",
157
+ $mdash: "—",
158
+ micro: "µ",
159
+ middot: "·",
160
+ $minus: "−",
161
+ $mu: "μ",
162
+ $nabla: "∇",
163
+ nbsp: "\xA0",
164
+ $ndash: "–",
165
+ $ne: "≠",
166
+ $ni: "∋",
167
+ not: "¬",
168
+ $notin: "∉",
169
+ $nsub: "⊄",
170
+ ntilde: "ñ",
171
+ $nu: "ν",
172
+ oacute: "ó",
173
+ ocirc: "ô",
174
+ $oelig: "œ",
175
+ ograve: "ò",
176
+ $oline: "‾",
177
+ $omega: "ω",
178
+ $omicron: "ο",
179
+ $oplus: "⊕",
180
+ $or: "∨",
181
+ ordf: "ª",
182
+ ordm: "º",
183
+ oslash: "ø",
184
+ otilde: "õ",
185
+ $otimes: "⊗",
186
+ ouml: "ö",
187
+ para: "¶",
188
+ $part: "∂",
189
+ $permil: "‰",
190
+ $perp: "⊥",
191
+ $phi: "φ",
192
+ $pi: "π",
193
+ $piv: "ϖ",
194
+ plusmn: "±",
195
+ pound: "£",
196
+ $prime: "′",
197
+ $prod: "∏",
198
+ $prop: "∝",
199
+ $psi: "ψ",
200
+ quot: "\"",
201
+ $rArr: "⇒",
202
+ $radic: "√",
203
+ $rang: "⟩",
204
+ raquo: "»",
205
+ $rarr: "→",
206
+ $rceil: "⌉",
207
+ $rdquo: "”",
208
+ $real: "ℜ",
209
+ reg: "®",
210
+ $rfloor: "⌋",
211
+ $rho: "ρ",
212
+ $rsaquo: "›",
213
+ $rsquo: "’",
214
+ $sbquo: "‚",
215
+ $scaron: "š",
216
+ $sdot: "⋅",
217
+ sect: "§",
218
+ shy: "­",
219
+ $sigma: "σ",
220
+ $sigmaf: "ς",
221
+ $sim: "∼",
222
+ $spades: "♠",
223
+ $sub: "⊂",
224
+ $sube: "⊆",
225
+ $sum: "∑",
226
+ $sup: "⊃",
227
+ sup1: "¹",
228
+ sup2: "²",
229
+ sup3: "³",
230
+ $supe: "⊇",
231
+ szlig: "ß",
232
+ $tau: "τ",
233
+ $there4: "∴",
234
+ $theta: "θ",
235
+ $thetasym: "ϑ",
236
+ thorn: "þ",
237
+ $tilde: "˜",
238
+ times: "×",
239
+ $trade: "™",
240
+ $uArr: "⇑",
241
+ uacute: "ú",
242
+ $uarr: "↑",
243
+ ucirc: "û",
244
+ ugrave: "ù",
245
+ uml: "¨",
246
+ $upsih: "ϒ",
247
+ $upsilon: "υ",
248
+ uuml: "ü",
249
+ $weierp: "℘",
250
+ $xi: "ξ",
251
+ yacute: "ý",
252
+ yen: "¥",
253
+ yuml: "ÿ",
254
+ $zeta: "ζ"
255
+ };
256
+ function lowerAscii(code) {
257
+ return code >= 65 && code <= 90 ? code + 32 : code;
258
+ }
259
+ function isInsideHeading(depthMap) {
260
+ for (let tagId = 7; tagId <= 12; tagId++) if (depthMap[tagId]) return true;
261
+ return false;
262
+ }
263
+ function isInsideTableCell(state) {
264
+ const depthMap = state.depthMap;
265
+ return depthMap[32] > 0 || depthMap[31] > 0;
266
+ }
267
+ function schemeMatches(href, start, end, scheme) {
268
+ let matched = 0;
269
+ for (let index = start; index < end; index++) {
270
+ const code = href.charCodeAt(index);
271
+ if (code === 9 || code === 10 || code === 13) continue;
272
+ if (lowerAscii(code) !== scheme.charCodeAt(matched)) return false;
273
+ if (++matched === scheme.length) return true;
274
+ }
275
+ return false;
276
+ }
277
+ function isDataUrl(src) {
278
+ let start = 0;
279
+ while (start < src.length && src.charCodeAt(start) <= 32) start++;
280
+ let end = src.length;
281
+ while (end > start && src.charCodeAt(end - 1) <= 32) end--;
282
+ return schemeMatches(src, start, end, "data:");
283
+ }
284
+ function isEmptyLinkHref(href) {
285
+ let start = 0;
286
+ while (start < href.length && href.charCodeAt(start) <= 32) start++;
287
+ let end = href.length;
288
+ while (end > start && href.charCodeAt(end - 1) <= 32) end--;
289
+ switch (lowerAscii(href.charCodeAt(start))) {
290
+ case 35: return end - start === 1;
291
+ case 106: return schemeMatches(href, start, end, "javascript:");
292
+ case 100: return schemeMatches(href, start, end, "data:");
293
+ case 118: return schemeMatches(href, start, end, "vbscript:");
294
+ default: return false;
295
+ }
296
+ }
297
+ function isSafeHtmlUrl(href, image = false) {
298
+ let start = 0;
299
+ while (start < href.length && href.charCodeAt(start) <= 32) start++;
300
+ let end = href.length;
301
+ while (end > start && href.charCodeAt(end - 1) <= 32) end--;
302
+ if (start === end) return false;
303
+ for (let index = start; index < end; index++) {
304
+ const code = href.charCodeAt(index);
305
+ if (code === 9 || code === 10 || code === 13) continue;
306
+ if (code === 58) switch (lowerAscii(href.charCodeAt(start))) {
307
+ case 104: return schemeMatches(href, start, end, "http:") || schemeMatches(href, start, end, "https:");
308
+ case 109: return !image && schemeMatches(href, start, end, "mailto:");
309
+ case 116: return !image && schemeMatches(href, start, end, "tel:");
310
+ case 102: return !image && schemeMatches(href, start, end, "ftp:");
311
+ default: return false;
312
+ }
313
+ if (code === 47 || code === 63 || code === 35) return true;
314
+ const lower = lowerAscii(code);
315
+ if (!(lower >= 97 && lower <= 122 || code >= 48 && code <= 57 || code === 43 || code === 45 || code === 46)) return true;
316
+ }
317
+ return true;
318
+ }
319
+ function escapeHtml(value, attribute = false, protectMarkdown = false) {
320
+ let escaped = "";
321
+ let copiedUntil = 0;
322
+ for (let index = 0; index < value.length; index++) {
323
+ const code = value.charCodeAt(index);
324
+ let replacement;
325
+ if (code === 38) replacement = "&amp;";
326
+ else if (code === 60) replacement = "&lt;";
327
+ else if (code === 62) replacement = "&gt;";
328
+ else if (attribute && code === 34) replacement = "&quot;";
329
+ else if (protectMarkdown && code === 91) replacement = "&#91;";
330
+ else if (protectMarkdown && code === 93) replacement = "&#93;";
331
+ if (replacement !== void 0) {
332
+ escaped += value.slice(copiedUntil, index) + replacement;
333
+ copiedUntil = index + 1;
334
+ }
335
+ }
336
+ return copiedUntil === 0 ? value : escaped + value.slice(copiedUntil);
337
+ }
338
+ function continuationPrefix(node, listIndentWidths, includeBlockquotes = true) {
339
+ const chain = [];
340
+ let current = node.parent;
341
+ while (current) {
342
+ chain.push(current);
343
+ current = current.parent;
344
+ }
345
+ let prefix = "";
346
+ let listIndex = 0;
347
+ for (let i = chain.length - 1; i >= 0; i--) {
348
+ const tagId = chain[i].tagId;
349
+ if (tagId === 22 && includeBlockquotes) prefix += "> ";
350
+ else if (tagId === 25) {
351
+ prefix += " ".repeat(listIndentWidths[listIndex] ?? 2);
352
+ listIndex++;
353
+ }
354
+ }
355
+ return prefix;
356
+ }
357
+ const C1_REPLACEMENTS = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ";
358
+ function isAsciiAlphaNumeric(code) {
359
+ return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122;
360
+ }
361
+ function isHtmlAsciiWhitespace(code) {
362
+ return code === 32 || code === 9 || code === 10 || code === 12 || code === 13;
363
+ }
364
+ const LANGUAGE_PREFIX = [
365
+ 108,
366
+ 97,
367
+ 110,
368
+ 103,
369
+ 117,
370
+ 97,
371
+ 103,
372
+ 101,
373
+ 45
374
+ ];
375
+ function hasLanguagePrefix(value, start) {
376
+ for (let offset = 0; offset < 9; offset++) if (value.charCodeAt(start + offset) !== LANGUAGE_PREFIX[offset]) return false;
377
+ return true;
378
+ }
379
+ function isUnsafeFenceInfoCode(code) {
380
+ if (code < 32 || code === 127) return true;
381
+ return code === 34 || code === 39 || code === 38 || code === 60 || code === 62 || code === 96 || code === 126;
382
+ }
383
+ function getLanguageFromClass(className) {
384
+ if (!className) return "";
385
+ const length = className.length;
386
+ let index = 0;
387
+ while (index < length) {
388
+ if (isHtmlAsciiWhitespace(className.charCodeAt(index))) {
389
+ index++;
390
+ continue;
391
+ }
392
+ const tokenStart = index;
393
+ do
394
+ index++;
395
+ while (index < length && !isHtmlAsciiWhitespace(className.charCodeAt(index)));
396
+ const tokenEnd = index;
397
+ const languageStart = tokenStart + 9;
398
+ if (languageStart >= tokenEnd || !hasLanguagePrefix(className, tokenStart)) continue;
399
+ let valid = true;
400
+ for (let cursor = languageStart; cursor < tokenEnd; cursor++) if (isUnsafeFenceInfoCode(className.charCodeAt(cursor))) {
401
+ valid = false;
402
+ break;
403
+ }
404
+ if (valid) return className.slice(languageStart, tokenEnd);
405
+ }
406
+ return "";
407
+ }
408
+ function parseUnsignedInteger(raw) {
409
+ if (raw === void 0 || !/^[\t\n\f\r ]*\+?\d+[\t\n\f\r ]*$/.test(raw)) return void 0;
410
+ const value = Number(raw);
411
+ return value <= 4294967295 ? value : void 0;
412
+ }
413
+ function lastOutputChar(buffer, end = buffer.length) {
414
+ for (let index = end - 1; index >= 0; index--) {
415
+ const fragment = buffer[index];
416
+ if (fragment.length > 0) return fragment.charCodeAt(fragment.length - 1);
417
+ }
418
+ return -1;
419
+ }
420
+ function blockOpenPrefix(buffer, prefix, end = buffer.length) {
421
+ switch (lastOutputChar(buffer, end)) {
422
+ case -1: return;
423
+ case 32: {
424
+ let fragment = end - 1;
425
+ let index = buffer[fragment].length;
426
+ for (;;) {
427
+ if (index === 0) {
428
+ if (--fragment < 0) return void 0;
429
+ index = buffer[fragment].length;
430
+ continue;
431
+ }
432
+ const code = buffer[fragment].charCodeAt(--index);
433
+ if (code !== 32) return code === 10 || listMarkerLineStart(buffer, fragment, index) ? void 0 : `\n\n${prefix ?? ""}`;
434
+ }
435
+ }
436
+ case 10: return prefix || void 0;
437
+ default: return `\n\n${prefix ?? ""}`;
438
+ }
439
+ }
440
+ function figcaptionOwnsBlockSpacing(node, plainText) {
441
+ let parent = node.parent;
442
+ while (parent) {
443
+ if (parent.tagId === 32 || parent.tagId === 31) return false;
444
+ if (!plainText && parent.tagId !== 37 && parent.tagHandler?.collapsesInnerWhiteSpace) return false;
445
+ parent = parent.parent;
446
+ }
447
+ return true;
448
+ }
449
+ function listMarkerLineStart(buffer, fragmentIndex, markerIndex) {
450
+ const marker = buffer[fragmentIndex].charCodeAt(markerIndex);
451
+ const ordered = marker === 46 || marker === 41;
452
+ if (!ordered && marker !== 45 && marker !== 42 && marker !== 43) return false;
453
+ let digits = 0;
454
+ let spaces = 0;
455
+ let fragment = fragmentIndex;
456
+ let cursor = markerIndex;
457
+ for (;;) {
458
+ if (cursor === 0) {
459
+ if (--fragment < 0) return !ordered || digits > 0;
460
+ cursor = buffer[fragment].length;
461
+ continue;
462
+ }
463
+ const code = buffer[fragment].charCodeAt(--cursor);
464
+ if (ordered && spaces === 0 && code >= 48 && code <= 57) {
465
+ if (++digits > 9) return false;
466
+ continue;
467
+ }
468
+ if (ordered && digits === 0) return false;
469
+ if (code === 32) {
470
+ if (++spaces > 3) return false;
471
+ continue;
472
+ }
473
+ return code === 10;
474
+ }
475
+ }
476
+ const MAX_ORDERED_START = 999999999;
477
+ function orderedItemNumber(list, index) {
478
+ const raw = list?.attributes?.start;
479
+ if (raw === void 0) return index + 1;
480
+ const start = parseUnsignedInteger(raw);
481
+ if (start === void 0 || start > MAX_ORDERED_START) return Math.min(1 + index, MAX_ORDERED_START);
482
+ return Math.min(start + index, MAX_ORDERED_START);
483
+ }
484
+ function numericReplacement(codePoint) {
485
+ if (codePoint === 0 || codePoint > 1114111 || codePoint >= 55296 && codePoint <= 57343) return "�";
486
+ if (codePoint >= 128 && codePoint <= 159) return C1_REPLACEMENTS[codePoint - 128];
487
+ return String.fromCodePoint(codePoint);
488
+ }
489
+ function isCharacterReferenceTail(text, start) {
490
+ let index = start;
491
+ if (text.charCodeAt(index) === 35) {
492
+ index++;
493
+ const hex = text.charCodeAt(index) === 120 || text.charCodeAt(index) === 88;
494
+ if (hex) index++;
495
+ const digitStart = index;
496
+ while (index < text.length) {
497
+ const code = text.charCodeAt(index);
498
+ if (!(code >= 48 && code <= 57) && !(hex && (code >= 65 && code <= 70 || code >= 97 && code <= 102))) break;
499
+ index++;
500
+ }
501
+ return index > digitStart && text.charCodeAt(index) === 59;
502
+ }
503
+ const nameStart = index;
504
+ while (index < text.length && isAsciiAlphaNumeric(text.charCodeAt(index))) index++;
505
+ return index > nameStart && text.charCodeAt(index) === 59;
506
+ }
507
+ function decodedReference(replacement, text, next, protectDecodedEntityReferences) {
508
+ return replacement === "&" && protectDecodedEntityReferences && isCharacterReferenceTail(text, next) ? "\\&" : replacement;
509
+ }
510
+ function decodeHTMLEntities(text, inAttribute = false, protectDecodedEntityReferences = false) {
511
+ let result = "";
512
+ let i = 0;
513
+ const len = text.length;
514
+ while (i < len) {
515
+ if (text.charCodeAt(i) !== 38) {
516
+ const plainStart = i;
517
+ while (i < len && text.charCodeAt(i) !== 38) i++;
518
+ result += text.slice(plainStart, i);
519
+ continue;
520
+ }
521
+ if (i + 2 < len && text.charCodeAt(i + 1) === 35) {
522
+ let end = i + 2;
523
+ const isHex = text.charCodeAt(end) === 120 || text.charCodeAt(end) === 88;
524
+ if (isHex) end++;
525
+ const digitStart = end;
526
+ let codePoint = 0;
527
+ while (end < len) {
528
+ const code = text.charCodeAt(end);
529
+ let digit = -1;
530
+ if (code >= 48 && code <= 57) digit = code - 48;
531
+ else if (isHex && code >= 65 && code <= 70) digit = code - 55;
532
+ else if (isHex && code >= 97 && code <= 102) digit = code - 87;
533
+ if (digit < 0) break;
534
+ codePoint = codePoint * (isHex ? 16 : 10) + digit;
535
+ end++;
536
+ }
537
+ if (end > digitStart) {
538
+ result += decodedReference(numericReplacement(codePoint), text, text.charCodeAt(end) === 59 ? end + 1 : end, protectDecodedEntityReferences);
539
+ if (text.charCodeAt(end) === 59) end++;
540
+ i = end;
541
+ continue;
542
+ }
543
+ }
544
+ const nameStart = i + 1;
545
+ let nameEnd = nameStart;
546
+ const scanEnd = Math.min(len, nameStart + 8);
547
+ while (nameEnd < scanEnd && isAsciiAlphaNumeric(text.charCodeAt(nameEnd))) nameEnd++;
548
+ if (nameEnd > nameStart && text.charCodeAt(nameEnd) === 59) {
549
+ const name = text.slice(nameStart, nameEnd);
550
+ const direct = HTML_ENTITIES[name];
551
+ const replacement = typeof direct === "string" ? direct : HTML_ENTITIES[`$${name}`];
552
+ if (replacement !== void 0) {
553
+ result += decodedReference(replacement, text, nameEnd + 1, protectDecodedEntityReferences);
554
+ i = nameEnd + 1;
555
+ continue;
556
+ }
557
+ }
558
+ let legacyEnd = Math.min(nameEnd, nameStart + 6);
559
+ let decodedLegacy = false;
560
+ while (legacyEnd > nameStart) {
561
+ const name = text.slice(nameStart, legacyEnd);
562
+ const replacement = HTML_ENTITIES[name];
563
+ if (typeof replacement === "string") {
564
+ const next = text.charCodeAt(legacyEnd);
565
+ if (replacement !== void 0 && !(inAttribute && (next === 61 || isAsciiAlphaNumeric(next)))) {
566
+ result += decodedReference(replacement, text, legacyEnd, protectDecodedEntityReferences);
567
+ i = legacyEnd;
568
+ decodedLegacy = true;
569
+ }
570
+ break;
571
+ }
572
+ legacyEnd--;
573
+ }
574
+ if (decodedLegacy) continue;
575
+ result += "&";
576
+ i++;
577
+ }
578
+ return result;
579
+ }
580
+ function isInlineNode(node) {
581
+ const isInline = node.tagHandler?.isInline;
582
+ return isInline === void 0 ? node.tagId === -1 : isInline;
583
+ }
584
+ function traverseUpToFirstBlockNode(node) {
585
+ let firstBlockParent = node;
586
+ const parentsToIncrement = [firstBlockParent];
587
+ while (isInlineNode(firstBlockParent)) {
588
+ if (!firstBlockParent.parent) break;
589
+ firstBlockParent = firstBlockParent.parent;
590
+ parentsToIncrement.push(firstBlockParent);
591
+ }
592
+ return parentsToIncrement;
593
+ }
594
+ function markRenderedChildContent(node) {
595
+ let parent = node.parent;
596
+ let anchorInScope = false;
597
+ while (parent) {
598
+ parent.childTextNodeIndex = (parent.childTextNodeIndex || 0) + 1;
599
+ if (parent.tagId === 26) anchorInScope = true;
600
+ if (!isInlineNode(parent)) break;
601
+ parent = parent.parent;
602
+ }
603
+ if (anchorInScope) return;
604
+ let anchorFound = false;
605
+ while (parent?.parent) {
606
+ parent = parent.parent;
607
+ if (!anchorFound) {
608
+ if (parent.tagId !== 26) continue;
609
+ anchorFound = true;
610
+ }
611
+ parent.childTextNodeIndex = (parent.childTextNodeIndex || 0) + 1;
612
+ if (!isInlineNode(parent)) return;
613
+ }
614
+ }
615
+ const TRACKING_PARAM_RE = /^(?:utm_|fbclid|gclid|mc_eid|msclkid|oly_)/;
616
+ const URL_SCHEME_RE = /^[A-Z][\dA-Z+.-]*:/i;
617
+ const SLASH_CHAR$1 = 47;
618
+ function stripTrackingParams(url) {
619
+ const queryStart = url.indexOf("?");
620
+ const fragmentStart = url.indexOf("#");
621
+ if (queryStart === -1 || fragmentStart !== -1 && fragmentStart < queryStart) return url;
622
+ const queryEnd = fragmentStart === -1 ? url.length : fragmentStart;
623
+ const query = url.slice(queryStart + 1, queryEnd).split("&").filter((parameter) => !TRACKING_PARAM_RE.test(parameter)).join("&");
624
+ return `${url.slice(0, queryStart)}${query ? `?${query}` : ""}${url.slice(queryEnd)}`;
625
+ }
626
+ function pathEnd(value, from) {
627
+ const query = value.indexOf("?", from);
628
+ const fragment = value.indexOf("#", from);
629
+ if (query === -1) return fragment === -1 ? value.length : fragment;
630
+ return fragment === -1 ? query : Math.min(query, fragment);
631
+ }
632
+ function hasDotSegment(path) {
633
+ return path.includes(".") && (path === "." || path === ".." || path.startsWith("./") || path.startsWith("../") || path.includes("/./") || path.includes("/../") || path.endsWith("/.") || path.endsWith("/.."));
634
+ }
635
+ function mergeDotSegments(dir, rest) {
636
+ let out = dir;
637
+ let index = 0;
638
+ for (;;) {
639
+ let end = rest.indexOf("/", index);
640
+ const last = end === -1;
641
+ if (last) end = rest.length;
642
+ const segment = rest.slice(index, end);
643
+ if (segment === "..") out = out.slice(0, out.lastIndexOf("/", out.length - 2) + 1);
644
+ else if (segment !== ".") out += last ? segment : `${segment}/`;
645
+ if (last) return out;
646
+ index = end + 1;
647
+ }
648
+ }
649
+ let baseOrigin;
650
+ let baseRoot = "";
651
+ let basePath = "";
652
+ let baseDir = "";
653
+ function loadBase(origin) {
654
+ if (origin !== baseOrigin) {
655
+ baseOrigin = origin;
656
+ baseRoot = "";
657
+ const authority = origin.indexOf("://");
658
+ if (authority !== -1) {
659
+ const end = pathEnd(origin, authority + 3);
660
+ const slash = origin.indexOf("/", authority + 3);
661
+ const rootEnd = slash === -1 || slash > end ? end : slash;
662
+ baseRoot = origin.slice(0, rootEnd);
663
+ basePath = origin.slice(rootEnd, end);
664
+ baseDir = basePath.slice(0, basePath.lastIndexOf("/") + 1) || "/";
665
+ }
666
+ }
667
+ return baseRoot !== "";
668
+ }
669
+ function resolveAgainstBase(origin, url) {
670
+ if (!loadBase(origin)) {
671
+ let prefix = origin;
672
+ while (prefix.endsWith("/")) prefix = prefix.slice(0, -1);
673
+ const path = url.startsWith("./") ? url.slice(2) : url;
674
+ return `${prefix}${path.charCodeAt(0) === SLASH_CHAR$1 ? "" : "/"}${path}`;
675
+ }
676
+ const end = pathEnd(url, 0);
677
+ const path = url.slice(0, end);
678
+ const suffix = end === url.length ? "" : url.slice(end);
679
+ if (!path) return `${baseRoot}${basePath}${suffix}`;
680
+ const dot = hasDotSegment(path);
681
+ if (path.charCodeAt(0) === SLASH_CHAR$1) return `${baseRoot}${dot ? mergeDotSegments("/", path.slice(1)) : path}${suffix}`;
682
+ return `${baseRoot}${dot ? mergeDotSegments(baseDir, path) : baseDir + path}${suffix}`;
683
+ }
684
+ function resolveUrl(url, origin, clean) {
685
+ if (!url || url[0] === "#") return url;
686
+ const isSlash = url.charCodeAt(0) === SLASH_CHAR$1;
687
+ let resolved = url;
688
+ if (isSlash && url.charCodeAt(1) === SLASH_CHAR$1) {
689
+ let scheme = "https";
690
+ if (origin && loadBase(origin)) scheme = baseRoot.slice(0, baseRoot.indexOf(":"));
691
+ resolved = `${scheme}:${url}`;
692
+ } else if (origin && (isSlash || !URL_SCHEME_RE.test(url))) resolved = resolveAgainstBase(origin, url);
693
+ return (clean === true || !!clean && clean.urls === true) && resolved.includes("?") ? stripTrackingParams(resolved) : resolved;
694
+ }
695
+ function safeAnchorOutput(node, options, entering, protectMarkdown = false) {
696
+ const href = node.attributes?.href;
697
+ if (!href || !isSafeHtmlUrl(href)) return;
698
+ const resolved = resolveUrl(href, options?.origin, options?.clean);
699
+ if (!isSafeHtmlUrl(resolved)) return;
700
+ if (!entering) return "</a>";
701
+ return `<a href="${escapeHtml(resolved, true, protectMarkdown)}"${node.attributes?.title === void 0 ? "" : ` title="${escapeHtml(node.attributes.title, true, protectMarkdown)}"`}>`;
702
+ }
703
+ function serializeMarkdownDestination(destination) {
704
+ if (!/[\t\n\f\r ()\\<>]/.test(destination)) return destination;
705
+ return `<${/[\\<>]/.test(destination) ? destination.replace(/[\\<>]/g, "\\$&") : destination}>`;
706
+ }
707
+ function stripsEmptyLink(state, href) {
708
+ const clean = state.options?.clean;
709
+ if (!(clean === true || typeof clean === "object" && clean.emptyLinks)) return false;
710
+ return isEmptyLinkHref(href);
711
+ }
712
+ function serializeMarkdownTitle(title) {
713
+ return /[\\"]/.test(title) ? title.replace(/[\\"]/g, "\\$&") : title;
714
+ }
715
+ function serializeMarkdownResource(destination, title) {
716
+ const serializedTitle = title ? ` "${serializeMarkdownTitle(title)}"` : "";
717
+ return `(${serializeMarkdownDestination(destination)}${serializedTitle})`;
718
+ }
719
+ function serializeImageDescription(alt) {
720
+ return /[\\[\]*_`~<&]/.test(alt) ? alt.replace(/[\\[\]*_`~<&]/g, "\\$&") : alt;
721
+ }
722
+ function isAutolinkUri(s) {
723
+ if (!(s.startsWith("http://") || s.startsWith("https://") || s.startsWith("ftp://") || s.startsWith("mailto:"))) return false;
724
+ for (let i = 0; i < s.length; i++) {
725
+ const c = s.charCodeAt(i);
726
+ if (c === 32 || c === 60 || c === 62 || c === 10 || c === 13 || c === 9) return false;
727
+ }
728
+ return true;
729
+ }
730
+ function renderBreak(node, state) {
731
+ const depthMap = state.depthMap;
732
+ if (isInsideTableCell(state) || isInsideRawHtmlBlock(depthMap) || isInsideHeading(depthMap)) return "<br>";
733
+ if (depthMap[34] || depthMap[23]) return "\n";
734
+ return ` \n${continuationPrefix(node, state.listIndentWidths || [], !state.bufferedBlockquoteDepth)}`;
735
+ }
736
+ const breakHandler = {
737
+ enter: ({ node, state }) => renderBreak(node, state),
738
+ isSelfClosing: true,
739
+ spacing: NO_SPACING,
740
+ collapsesInnerWhiteSpace: true,
741
+ isInline: true
742
+ };
743
+ function escapeTrailingHeadingHashes(buffer) {
744
+ let index = buffer.length - 1;
745
+ while (index >= 0 && buffer[index] === "") index--;
746
+ if (index < 0) return;
747
+ const entry = buffer[index];
748
+ let end = entry.length;
749
+ while (end > 0 && (entry[end - 1] === " " || entry[end - 1] === " ")) end--;
750
+ let run = end;
751
+ while (run > 0 && entry[run - 1] === "#") run--;
752
+ if (run === end) return;
753
+ const previous = buffer[index - 1];
754
+ const before = run > 0 ? entry[run - 1] : previous?.charAt(previous.length - 1);
755
+ if (before !== " " && before !== " ") return;
756
+ buffer[index] = `${entry.slice(0, run)}\\${entry.slice(run)}`;
757
+ }
758
+ const LINE_FRESH = -1;
759
+ const LINE_OPEN = 0;
760
+ const LINE_ROW = 1;
761
+ const LINE_CONTENT = 2;
762
+ function lineStateBeforeRow(buffer) {
763
+ let fragment = buffer.length - 1;
764
+ while (fragment >= 0 && buffer[fragment].length === 0) fragment--;
765
+ if (fragment < 0) return LINE_OPEN;
766
+ const tail = buffer[fragment];
767
+ if (tail.charCodeAt(tail.length - 1) === 10) return LINE_FRESH;
768
+ let firstNonSpace = -1;
769
+ let markerFragment = -1;
770
+ let markerIndex = -1;
771
+ let cursor = tail.length;
772
+ for (;;) {
773
+ if (cursor === 0) {
774
+ if (--fragment < 0) break;
775
+ cursor = buffer[fragment].length;
776
+ continue;
777
+ }
778
+ const code = buffer[fragment].charCodeAt(--cursor);
779
+ if (code === 10) break;
780
+ if (code !== 32 && code !== 9) {
781
+ firstNonSpace = code;
782
+ if (markerFragment < 0) {
783
+ markerFragment = fragment;
784
+ markerIndex = cursor;
785
+ }
786
+ }
787
+ }
788
+ if (firstNonSpace === -1) return LINE_OPEN;
789
+ if (firstNonSpace === 124) return LINE_ROW;
790
+ return listMarkerLineStart(buffer, markerFragment, markerIndex) ? LINE_OPEN : LINE_CONTENT;
791
+ }
792
+ function rowMarker(state) {
793
+ const indent = state.listIndent;
794
+ const lineState = lineStateBeforeRow(state.buffer);
795
+ if (!indent) return lineState === LINE_ROW ? "\n| " : lineState === LINE_CONTENT ? "\n\n| " : "| ";
796
+ switch (lineState) {
797
+ case LINE_ROW: return `\n${indent}| `;
798
+ case LINE_CONTENT: return `\n\n${indent}| `;
799
+ case LINE_FRESH: return `${indent}| `;
800
+ default: return "| ";
801
+ }
802
+ }
803
+ const MAX_CELL_SPAN = 64;
804
+ function cellEnter(node, state) {
805
+ if (node.index === 0) return "";
806
+ const header = state.tableHeaderCells || 0;
807
+ return header > 0 && (state.tableCurrentRowCells || 0) >= header ? " " : " | ";
808
+ }
809
+ function cellExit(node, state) {
810
+ const parsedSpan = parseUnsignedInteger(node.attributes?.colspan);
811
+ const span = parsedSpan && parsedSpan < 256 ? Math.min(parsedSpan, MAX_CELL_SPAN) : 1;
812
+ state.tableCurrentRowCells += span;
813
+ return span > 1 ? " |".repeat(span - 1) : void 0;
814
+ }
815
+ function handleHeading(depth) {
816
+ return {
817
+ enter: ({ state }) => {
818
+ if ((state.depthMap?.[26] || 0) > 0 || isInsideTableCell(state)) return `<h${depth}>`;
819
+ return `${"#".repeat(depth)} `;
820
+ },
821
+ exit: ({ state }) => {
822
+ if ((state.depthMap?.[26] || 0) > 0 || isInsideTableCell(state)) return `</h${depth}>`;
823
+ escapeTrailingHeadingHashes(state.buffer);
824
+ },
825
+ collapsesInnerWhiteSpace: true
826
+ };
827
+ }
828
+ const Strong = {
829
+ enter: ({ state }) => {
830
+ if ((state.depthMap?.[15] || 0) > 1) return "";
831
+ return "**";
832
+ },
833
+ exit: ({ node, state }) => {
834
+ if ((state.depthMap?.[15] || 0) + (node.tagId === 15 ? 1 : 0) > 1) return "";
835
+ return "**";
836
+ },
837
+ collapsesInnerWhiteSpace: true,
838
+ spacing: NO_SPACING,
839
+ isInline: true
840
+ };
841
+ const Emphasis = {
842
+ enter: ({ state }) => {
843
+ if ((state.depthMap?.[17] || 0) > 1) return "";
844
+ return "*";
845
+ },
846
+ exit: ({ node, state }) => {
847
+ if ((state.depthMap?.[17] || 0) + (node.tagId === 17 ? 1 : 0) > 1) return "";
848
+ return "*";
849
+ },
850
+ collapsesInnerWhiteSpace: true,
851
+ spacing: NO_SPACING,
852
+ isInline: true
853
+ };
854
+ const Strikethrough = {
855
+ enter: () => "~~",
856
+ exit: () => "~~",
857
+ collapsesInnerWhiteSpace: true,
858
+ spacing: NO_SPACING,
859
+ isInline: true
860
+ };
861
+ const INERT_RAWTEXT = {
862
+ isNonNesting: true,
863
+ excludesTextNodes: true,
864
+ spacing: NO_SPACING
865
+ };
866
+ const tagHandlers = {
867
+ [1]: {
868
+ spacing: NO_SPACING,
869
+ collapsesInnerWhiteSpace: true
870
+ },
871
+ [2]: {
872
+ enter: () => "<details>",
873
+ exit: ({ state }) => isInsideTableCell(state) ? "</details>" : "</details>\n\n"
874
+ },
875
+ [3]: {
876
+ enter: () => "<summary>",
877
+ exit: ({ state }) => isInsideTableCell(state) ? "</summary>" : "</summary>\n\n"
878
+ },
879
+ [4]: {
880
+ excludesTextNodes: true,
881
+ collapsesInnerWhiteSpace: true,
882
+ isNonNesting: true,
883
+ spacing: NO_SPACING
884
+ },
885
+ [52]: {
886
+ excludesTextNodes: true,
887
+ isNonNesting: true
888
+ },
889
+ [53]: {
890
+ isNonNesting: true,
891
+ excludesTextNodes: true
892
+ },
893
+ [5]: {
894
+ collapsesInnerWhiteSpace: true,
895
+ isSelfClosing: true,
896
+ spacing: NO_SPACING
897
+ },
898
+ [6]: breakHandler,
899
+ [7]: handleHeading(1),
900
+ [8]: handleHeading(2),
901
+ [9]: handleHeading(3),
902
+ [10]: handleHeading(4),
903
+ [11]: handleHeading(5),
904
+ [12]: handleHeading(6),
905
+ [13]: {
906
+ enter: ({ node, state }) => {
907
+ if (isInsideTableCell(state)) return "<hr>";
908
+ if (!(state.depthMap?.[25] || state.bufferedBlockquoteDepth)) return "---";
909
+ const prefix = continuationPrefix(node, state.listIndentWidths || [], !state.bufferedBlockquoteDepth);
910
+ if (!prefix) return "---";
911
+ if (state.depthMap?.[25]) state.listRulePending = prefix;
912
+ const open = blockOpenPrefix(state.buffer, prefix);
913
+ return open === void 0 ? "***" : `${open}---`;
914
+ },
915
+ isSelfClosing: true
916
+ },
917
+ [14]: Strong,
918
+ [15]: Strong,
919
+ [16]: Emphasis,
920
+ [17]: Emphasis,
921
+ [18]: Strikethrough,
922
+ [110]: Strikethrough,
923
+ [111]: Strikethrough,
924
+ [19]: {
925
+ enter: () => "<sub>",
926
+ exit: () => "</sub>",
927
+ collapsesInnerWhiteSpace: true,
928
+ spacing: NO_SPACING,
929
+ isInline: true
930
+ },
931
+ [20]: {
932
+ enter: () => "<sup>",
933
+ exit: () => "</sup>",
934
+ collapsesInnerWhiteSpace: true,
935
+ spacing: NO_SPACING,
936
+ isInline: true
937
+ },
938
+ [21]: {
939
+ enter: () => "<ins>",
940
+ exit: () => "</ins>",
941
+ collapsesInnerWhiteSpace: true,
942
+ spacing: NO_SPACING,
943
+ isInline: true
944
+ },
945
+ [22]: {
946
+ enter: ({ state }) => {
947
+ return {
948
+ _tag: "BlockquoteEnter",
949
+ output: (state.depthMap?.[25] || 0) > 0 ? "\n" : void 0
950
+ };
951
+ },
952
+ exit: () => ({ _tag: "BlockquoteExit" }),
953
+ spacing: BLOCKQUOTE_SPACING
954
+ },
955
+ [34]: {
956
+ enter: ({ node, state }) => {
957
+ if (isInsideTableCell(state)) return "<pre>";
958
+ return {
959
+ _tag: "PreEnter",
960
+ language: getLanguageFromClass(node.attributes?.class)
961
+ };
962
+ },
963
+ exit: ({ state }) => {
964
+ if (isInsideTableCell(state)) return "</pre>";
965
+ return { _tag: "PreExit" };
966
+ }
967
+ },
968
+ [23]: {
969
+ enter: ({ node, state }) => {
970
+ if ((state.depthMap?.[34] || 0) > 0) {
971
+ if (isInsideTableCell(state)) return "<code>";
972
+ if (state.preFenceOpen) return;
973
+ const language = getLanguageFromClass(node.attributes?.class);
974
+ if ((state.depthMap?.[25] || 0) > 0) {
975
+ const indent = state.listIndent;
976
+ return {
977
+ _tag: "CodeFenceEnter",
978
+ language,
979
+ output: `${blockOpenPrefix(state.buffer, indent) ?? ""}\`\`\`${language}\n`
980
+ };
981
+ }
982
+ return {
983
+ _tag: "CodeFenceEnter",
984
+ language,
985
+ output: `\`\`\`${language}\n`
986
+ };
987
+ }
988
+ if (isInsideRawHtmlBlock(state.depthMap)) return "<code>";
989
+ if ((state.depthMap?.[25] || 0) > 0) {
990
+ const lastEntry = state.buffer.at(-1);
991
+ const lastChar = lastEntry?.charAt(lastEntry.length - 1) || "";
992
+ if (lastChar && lastChar !== " " && lastChar !== "\n" && lastChar !== " " && lastChar !== "*" && lastChar !== "_" && lastChar !== "~" && lastChar !== "[" && lastChar !== ">") return {
993
+ _tag: "CodeSpanEnter",
994
+ output: ` \``
995
+ };
996
+ }
997
+ return {
998
+ _tag: "CodeSpanEnter",
999
+ output: "`"
1000
+ };
1001
+ },
1002
+ exit: ({ state }) => {
1003
+ if ((state.depthMap?.[34] || 0) > 0) {
1004
+ if (isInsideTableCell(state)) return "</code>";
1005
+ return;
1006
+ }
1007
+ if (isInsideRawHtmlBlock(state.depthMap)) return "</code>";
1008
+ return { _tag: "CodeSpanExit" };
1009
+ },
1010
+ collapsesInnerWhiteSpace: true,
1011
+ spacing: NO_SPACING,
1012
+ isInline: true
1013
+ },
1014
+ [24]: {
1015
+ enter: ({ state }) => isInsideTableCell(state) ? "<ul>" : void 0,
1016
+ exit: ({ state }) => isInsideTableCell(state) ? "</ul>" : void 0
1017
+ },
1018
+ [33]: {
1019
+ enter: ({ state }) => isInsideTableCell(state) ? "<ol>" : void 0,
1020
+ exit: ({ state }) => isInsideTableCell(state) ? "</ol>" : void 0
1021
+ },
1022
+ [25]: {
1023
+ enter: ({ node, state }) => {
1024
+ if (isInsideTableCell(state)) return "<li>";
1025
+ const marker = node.parent?.tagId === 33 ? `${orderedItemNumber(node.parent, node.index)}. ` : "- ";
1026
+ return `${state.listIndent}${marker}`;
1027
+ },
1028
+ exit: ({ state }) => isInsideTableCell(state) ? "</li>" : void 0,
1029
+ spacing: LIST_ITEM_SPACING
1030
+ },
1031
+ [26]: {
1032
+ enter: ({ node, state }) => {
1033
+ if (node.attributes?.href !== void 0) {
1034
+ if (stripsEmptyLink(state, node.attributes.href)) return;
1035
+ if (isInsideRawHtmlBlock(state.depthMap)) return safeAnchorOutput(node, state.options, true, true);
1036
+ return "[";
1037
+ }
1038
+ },
1039
+ exit: ({ node, state }) => {
1040
+ if (node.attributes?.href === void 0) return "";
1041
+ if (stripsEmptyLink(state, node.attributes.href)) return "";
1042
+ if (isInsideRawHtmlBlock(state.depthMap) && !node.tagHandler?.literalEnter) return safeAnchorOutput(node, state.options, false, true);
1043
+ const href = resolveUrl(node.attributes.href, state.options?.origin, state.options?.clean);
1044
+ let title = node.attributes?.title;
1045
+ if (state.lastContentCache === title) title = "";
1046
+ if (!title && isAutolinkUri(href)) {
1047
+ const buf = state.buffer;
1048
+ let i = buf.length - 1;
1049
+ let textLen = 0;
1050
+ let captionBracket = -1;
1051
+ let captionTextLen = 0;
1052
+ while (i >= 0) {
1053
+ const entry = buf[i];
1054
+ if (entry === "[") break;
1055
+ if (captionBracket < 0 && state.depthMap?.[106] && entry.endsWith("*[")) {
1056
+ captionBracket = i;
1057
+ captionTextLen = textLen;
1058
+ }
1059
+ textLen += entry.length;
1060
+ i--;
1061
+ }
1062
+ const captionLink = i < 0 && captionBracket >= 0;
1063
+ if (captionLink) {
1064
+ i = captionBracket;
1065
+ textLen = captionTextLen;
1066
+ }
1067
+ if (i >= 0 && textLen === href.length && buf.slice(i + 1).join("") === href) {
1068
+ if (captionLink) buf[i] = buf[i].slice(0, -1);
1069
+ buf.length = i + (captionLink ? 1 : 0);
1070
+ const auto = `<${href}>`;
1071
+ buf.push(auto);
1072
+ state.lastContentCache = auto;
1073
+ return "";
1074
+ }
1075
+ }
1076
+ return `]${serializeMarkdownResource(href, title)}`;
1077
+ },
1078
+ collapsesInnerWhiteSpace: true,
1079
+ spacing: NO_SPACING,
1080
+ isInline: true
1081
+ },
1082
+ [27]: {
1083
+ enter: ({ node, state }) => {
1084
+ const alt = node.attributes?.alt || "";
1085
+ const rawSrc = node.attributes?.src || "";
1086
+ const src = isDataUrl(rawSrc) ? "" : resolveUrl(rawSrc, state.options?.origin, state.options?.clean);
1087
+ const clean = state.options?.clean;
1088
+ if ((clean === true || clean !== void 0 && clean !== false && clean.emptyImages === true) && !alt.trim()) {
1089
+ if (state.depthMap?.[106]) return void 0;
1090
+ } else markRenderedChildContent(node);
1091
+ return `![${serializeImageDescription(alt)}]${serializeMarkdownResource(src, node.attributes?.title)}`;
1092
+ },
1093
+ collapsesInnerWhiteSpace: true,
1094
+ isSelfClosing: true,
1095
+ spacing: NO_SPACING,
1096
+ isInline: true
1097
+ },
1098
+ [28]: {
1099
+ enter: ({ state }) => {
1100
+ if (isInsideTableCell(state)) return "<table>";
1101
+ if ((state.depthMap?.[28] || 0) <= 1) state.tableRenderedTable = false;
1102
+ state.tableColumnAlignments = [];
1103
+ state.tableHeaderCells = 0;
1104
+ },
1105
+ exit: ({ state }) => isInsideTableCell(state) ? "</table>" : void 0
1106
+ },
1107
+ [107]: { enter: ({ state }) => {
1108
+ if ((state.depthMap?.[25] || 0) === 0 || isInsideTableCell(state)) return void 0;
1109
+ return blockOpenPrefix(state.buffer, state.listIndent);
1110
+ } },
1111
+ [29]: {
1112
+ enter: ({ state }) => {
1113
+ if (isInsideTableCell(state)) return "<thead>";
1114
+ },
1115
+ exit: ({ state }) => isInsideTableCell(state) ? "</thead>" : void 0,
1116
+ spacing: TABLE_ROW_SPACING,
1117
+ excludesTextNodes: true
1118
+ },
1119
+ [30]: {
1120
+ enter: ({ state }) => {
1121
+ if (isInsideTableCell(state)) return "<tr>";
1122
+ state.tableCurrentRowCells = 0;
1123
+ return rowMarker(state);
1124
+ },
1125
+ exit: ({ state }) => {
1126
+ if (isInsideTableCell(state) || (state.depthMap?.[28] || 0) > 1) return "</tr>";
1127
+ if (!state.tableRenderedTable) {
1128
+ state.tableRenderedTable = true;
1129
+ const alignments = state.tableColumnAlignments;
1130
+ while (alignments.length < state.tableCurrentRowCells) alignments.push("");
1131
+ const alignmentMarkers = alignments.map((align) => {
1132
+ switch (align) {
1133
+ case "left": return ":---";
1134
+ case "center": return ":---:";
1135
+ case "right": return "---:";
1136
+ default: return "---";
1137
+ }
1138
+ });
1139
+ state.tableHeaderCells = alignments.length;
1140
+ return ` |\n${(state.depthMap?.[25] || 0) > 0 ? state.listIndent : ""}| ${alignmentMarkers.join(" | ")} |`;
1141
+ }
1142
+ return " |";
1143
+ },
1144
+ excludesTextNodes: true,
1145
+ spacing: TABLE_ROW_SPACING
1146
+ },
1147
+ [31]: {
1148
+ enter: ({ node, state }) => {
1149
+ if ((state.depthMap?.[28] || 0) > 1) return "<th>";
1150
+ const align = node.attributes?.align?.toLowerCase();
1151
+ if (align) state.tableColumnAlignments.push(align);
1152
+ else if (state.tableColumnAlignments.length <= state.tableCurrentRowCells) state.tableColumnAlignments.push("");
1153
+ return cellEnter(node, state);
1154
+ },
1155
+ exit: ({ node, state }) => {
1156
+ if ((state.depthMap?.[28] || 0) > 1) return "</th>";
1157
+ return cellExit(node, state);
1158
+ },
1159
+ collapsesInnerWhiteSpace: true,
1160
+ spacing: NO_SPACING
1161
+ },
1162
+ [32]: {
1163
+ enter: ({ node, state }) => {
1164
+ if ((state.depthMap?.[28] || 0) > 1) return "<td>";
1165
+ return cellEnter(node, state);
1166
+ },
1167
+ exit: ({ node, state }) => {
1168
+ if ((state.depthMap?.[28] || 0) > 1) return "</td>";
1169
+ return cellExit(node, state);
1170
+ },
1171
+ collapsesInnerWhiteSpace: true,
1172
+ spacing: NO_SPACING
1173
+ },
1174
+ [35]: { enter: ({ state }) => {
1175
+ if ((state.depthMap?.[25] || 0) > 0 && !isInsideTableCell(state)) {
1176
+ const lastEntry = state.buffer.at(-1);
1177
+ const lastChar = lastEntry?.charAt(lastEntry.length - 1) || "";
1178
+ if (lastChar && lastChar !== " " && lastChar !== "\n") return `\n\n${state.listIndent}`;
1179
+ }
1180
+ } },
1181
+ [36]: {},
1182
+ [37]: {
1183
+ collapsesInnerWhiteSpace: true,
1184
+ spacing: NO_SPACING,
1185
+ isInline: true
1186
+ },
1187
+ [41]: {},
1188
+ [42]: {
1189
+ collapsesInnerWhiteSpace: true,
1190
+ spacing: NO_SPACING,
1191
+ isInline: true
1192
+ },
1193
+ [43]: {
1194
+ collapsesInnerWhiteSpace: true,
1195
+ spacing: NO_SPACING,
1196
+ isInline: true
1197
+ },
1198
+ [44]: { spacing: NO_SPACING },
1199
+ [45]: {
1200
+ enter: ({ state }) => {
1201
+ if ((state.depthMap?.[28] || 0) > 1) return "<center>";
1202
+ },
1203
+ exit: ({ state }) => {
1204
+ if ((state.depthMap?.[28] || 0) > 1) return "</center>";
1205
+ },
1206
+ spacing: NO_SPACING
1207
+ },
1208
+ [38]: {
1209
+ spacing: NO_SPACING,
1210
+ excludesTextNodes: true
1211
+ },
1212
+ [39]: {
1213
+ spacing: TABLE_ROW_SPACING,
1214
+ excludesTextNodes: true
1215
+ },
1216
+ [46]: {
1217
+ enter: () => "`",
1218
+ exit: () => "`",
1219
+ collapsesInnerWhiteSpace: true,
1220
+ spacing: NO_SPACING,
1221
+ isInline: true
1222
+ },
1223
+ [47]: { spacing: NO_SPACING },
1224
+ [40]: { spacing: NO_SPACING },
1225
+ [54]: {
1226
+ isSelfClosing: true,
1227
+ spacing: NO_SPACING,
1228
+ collapsesInnerWhiteSpace: true,
1229
+ isInline: true
1230
+ },
1231
+ [55]: {
1232
+ isSelfClosing: true,
1233
+ spacing: NO_SPACING,
1234
+ isInline: true,
1235
+ collapsesInnerWhiteSpace: true
1236
+ },
1237
+ [56]: {
1238
+ isSelfClosing: true,
1239
+ spacing: NO_SPACING,
1240
+ isInline: true,
1241
+ collapsesInnerWhiteSpace: true
1242
+ },
1243
+ [57]: {
1244
+ isSelfClosing: true,
1245
+ spacing: NO_SPACING
1246
+ },
1247
+ [58]: {
1248
+ isSelfClosing: true,
1249
+ spacing: NO_SPACING
1250
+ },
1251
+ [59]: {
1252
+ isSelfClosing: true,
1253
+ spacing: NO_SPACING,
1254
+ isInline: true,
1255
+ collapsesInnerWhiteSpace: true
1256
+ },
1257
+ [60]: {
1258
+ isSelfClosing: true,
1259
+ spacing: NO_SPACING,
1260
+ isInline: true,
1261
+ collapsesInnerWhiteSpace: true
1262
+ },
1263
+ [61]: {
1264
+ isSelfClosing: true,
1265
+ spacing: NO_SPACING
1266
+ },
1267
+ [62]: {
1268
+ isSelfClosing: true,
1269
+ spacing: NO_SPACING
1270
+ },
1271
+ [63]: {
1272
+ isSelfClosing: true,
1273
+ spacing: NO_SPACING
1274
+ },
1275
+ [64]: {
1276
+ isSelfClosing: true,
1277
+ spacing: NO_SPACING,
1278
+ isInline: true,
1279
+ collapsesInnerWhiteSpace: true
1280
+ },
1281
+ [49]: { spacing: NO_SPACING },
1282
+ [65]: { spacing: NO_SPACING },
1283
+ [66]: {
1284
+ isNonNesting: true,
1285
+ spacing: NO_SPACING
1286
+ },
1287
+ [67]: { spacing: NO_SPACING },
1288
+ [109]: { spacing: NO_SPACING },
1289
+ [68]: { spacing: NO_SPACING },
1290
+ [69]: { spacing: NO_SPACING },
1291
+ [70]: { spacing: NO_SPACING },
1292
+ [71]: { spacing: NO_SPACING },
1293
+ [72]: { spacing: NO_SPACING },
1294
+ [73]: { ...INERT_RAWTEXT },
1295
+ [74]: { spacing: NO_SPACING },
1296
+ [75]: { spacing: NO_SPACING },
1297
+ [76]: { spacing: NO_SPACING },
1298
+ [77]: { spacing: NO_SPACING },
1299
+ [78]: {
1300
+ excludesTextNodes: true,
1301
+ spacing: NO_SPACING
1302
+ },
1303
+ [79]: {
1304
+ enter: () => "",
1305
+ exit: () => "",
1306
+ collapsesInnerWhiteSpace: true,
1307
+ spacing: NO_SPACING,
1308
+ isInline: true
1309
+ },
1310
+ [80]: {
1311
+ enter: () => "<mark>",
1312
+ exit: () => "</mark>",
1313
+ collapsesInnerWhiteSpace: true,
1314
+ spacing: NO_SPACING,
1315
+ isInline: true
1316
+ },
1317
+ [81]: {
1318
+ enter: () => "\"",
1319
+ exit: () => "\"",
1320
+ collapsesInnerWhiteSpace: true,
1321
+ spacing: NO_SPACING,
1322
+ isInline: true
1323
+ },
1324
+ [82]: {
1325
+ enter: () => "`",
1326
+ exit: () => "`",
1327
+ collapsesInnerWhiteSpace: true,
1328
+ spacing: NO_SPACING,
1329
+ isInline: true
1330
+ },
1331
+ [83]: {
1332
+ enter: () => "",
1333
+ exit: () => "",
1334
+ collapsesInnerWhiteSpace: true,
1335
+ spacing: NO_SPACING,
1336
+ isInline: true
1337
+ },
1338
+ [84]: { ...INERT_RAWTEXT },
1339
+ [112]: { ...INERT_RAWTEXT },
1340
+ [108]: {
1341
+ isNonNesting: true,
1342
+ excludesTextNodes: true,
1343
+ spacing: NO_SPACING
1344
+ },
1345
+ [85]: { ...INERT_RAWTEXT },
1346
+ [86]: {
1347
+ isNonNesting: true,
1348
+ spacing: NO_SPACING
1349
+ },
1350
+ [87]: {
1351
+ isNonNesting: true,
1352
+ spacing: NO_SPACING
1353
+ },
1354
+ [88]: { spacing: NO_SPACING },
1355
+ [89]: {
1356
+ enter: () => {
1357
+ return "<u>";
1358
+ },
1359
+ exit: () => {
1360
+ return "</u>";
1361
+ },
1362
+ collapsesInnerWhiteSpace: true,
1363
+ spacing: NO_SPACING,
1364
+ isInline: true
1365
+ },
1366
+ [90]: {
1367
+ enter: () => "*",
1368
+ exit: () => "*",
1369
+ collapsesInnerWhiteSpace: true,
1370
+ spacing: NO_SPACING,
1371
+ isInline: true
1372
+ },
1373
+ [91]: {
1374
+ enter: () => "**",
1375
+ exit: () => "**",
1376
+ collapsesInnerWhiteSpace: true,
1377
+ spacing: NO_SPACING,
1378
+ isInline: true
1379
+ },
1380
+ [92]: {
1381
+ enter: () => "`",
1382
+ exit: () => "`",
1383
+ collapsesInnerWhiteSpace: true,
1384
+ spacing: NO_SPACING,
1385
+ isInline: true
1386
+ },
1387
+ [93]: {
1388
+ enter: () => "",
1389
+ exit: () => "",
1390
+ collapsesInnerWhiteSpace: true,
1391
+ spacing: NO_SPACING,
1392
+ isInline: true
1393
+ },
1394
+ [94]: {
1395
+ enter: () => "",
1396
+ exit: () => "",
1397
+ collapsesInnerWhiteSpace: true,
1398
+ spacing: NO_SPACING,
1399
+ isInline: true
1400
+ },
1401
+ [95]: {
1402
+ enter: () => "",
1403
+ exit: () => "",
1404
+ collapsesInnerWhiteSpace: true,
1405
+ spacing: NO_SPACING,
1406
+ isInline: true
1407
+ },
1408
+ [96]: {
1409
+ enter: () => "",
1410
+ exit: () => "",
1411
+ collapsesInnerWhiteSpace: true,
1412
+ spacing: NO_SPACING,
1413
+ isInline: true
1414
+ },
1415
+ [97]: {
1416
+ enter: () => "",
1417
+ exit: () => "",
1418
+ collapsesInnerWhiteSpace: true,
1419
+ spacing: NO_SPACING,
1420
+ isInline: true
1421
+ },
1422
+ [100]: {
1423
+ enter: () => "<address>",
1424
+ exit: () => "</address>",
1425
+ spacing: NO_SPACING,
1426
+ collapsesInnerWhiteSpace: true
1427
+ },
1428
+ [101]: {
1429
+ spacing: NO_SPACING,
1430
+ enter: () => "<dl>",
1431
+ exit: () => "</dl>"
1432
+ },
1433
+ [99]: {
1434
+ enter: () => "<dt>",
1435
+ exit: () => "</dt>",
1436
+ collapsesInnerWhiteSpace: true,
1437
+ spacing: [0, 1]
1438
+ },
1439
+ [98]: {
1440
+ enter: () => "<dd>",
1441
+ exit: () => "</dd>",
1442
+ spacing: [0, 1]
1443
+ },
1444
+ [50]: {},
1445
+ [51]: {},
1446
+ [105]: {},
1447
+ [104]: {},
1448
+ [102]: {},
1449
+ [106]: {
1450
+ exit: () => "*",
1451
+ collapsesInnerWhiteSpace: true,
1452
+ isInline: true
1453
+ }
1454
+ };
1455
+ function buildTagOverrideHandlers(overrides) {
1456
+ const result = /* @__PURE__ */ new Map();
1457
+ for (const tagName in overrides) {
1458
+ const override = overrides[tagName];
1459
+ if (!override) continue;
1460
+ if (typeof override === "string") {
1461
+ const targetId = TagIdMap[override];
1462
+ if (targetId !== void 0) {
1463
+ const baseHandler = tagHandlers[targetId];
1464
+ if (baseHandler) result.set(tagName, {
1465
+ ...baseHandler,
1466
+ aliasTagId: targetId
1467
+ });
1468
+ }
1469
+ } else {
1470
+ const baseId = TagIdMap[tagName];
1471
+ const baseHandler = baseId !== void 0 ? tagHandlers[baseId] : void 0;
1472
+ const handler = baseHandler ? { ...baseHandler } : {};
1473
+ if (override.enter !== void 0) {
1474
+ const enterStr = override.enter;
1475
+ handler.enter = () => enterStr;
1476
+ handler.literalEnter = true;
1477
+ }
1478
+ if (override.exit !== void 0) {
1479
+ const exitStr = override.exit;
1480
+ handler.exit = () => exitStr;
1481
+ handler.literalExit = true;
1482
+ }
1483
+ if (override.spacing !== void 0) handler.spacing = override.spacing;
1484
+ if (override.isInline !== void 0) handler.isInline = override.isInline;
1485
+ if (override.isSelfClosing !== void 0) handler.isSelfClosing = override.isSelfClosing;
1486
+ if (override.collapsesInnerWhiteSpace !== void 0) handler.collapsesInnerWhiteSpace = override.collapsesInnerWhiteSpace;
1487
+ result.set(tagName, handler);
1488
+ }
1489
+ }
1490
+ return result;
1491
+ }
1492
+ const UNKNOWN_TAG_HANDLER = {
1493
+ isInline: true,
1494
+ spacing: NO_SPACING
1495
+ };
1496
+ const LT_CHAR = 60;
1497
+ const GT_CHAR = 62;
1498
+ const SLASH_CHAR = 47;
1499
+ const EQUALS_CHAR = 61;
1500
+ const QUOTE_CHAR = 34;
1501
+ const APOS_CHAR = 39;
1502
+ const EXCLAMATION_CHAR = 33;
1503
+ const QUESTION_CHAR = 63;
1504
+ const AMPERSAND_CHAR = 38;
1505
+ const DASH_CHAR = 45;
1506
+ const SPACE_CHAR = 32;
1507
+ const TAB_CHAR = 9;
1508
+ const NEWLINE_CHAR = 10;
1509
+ const FORM_FEED_CHAR = 12;
1510
+ const CARRIAGE_RETURN_CHAR = 13;
1511
+ const OPEN_BRACKET_CHAR = 91;
1512
+ const ATTRIBUTE_GAP = 0;
1513
+ const ATTRIBUTE_NAME = 1;
1514
+ const ATTRIBUTE_AFTER_NAME = 2;
1515
+ const ATTRIBUTE_BEFORE_VALUE = 3;
1516
+ const ATTRIBUTE_QUOTED_VALUE = 4;
1517
+ const ATTRIBUTE_UNQUOTED_VALUE = 5;
1518
+ function isAsciiAlpha(code) {
1519
+ return code >= 65 && code <= 90 || code >= 97 && code <= 122;
1520
+ }
1521
+ function shouldProtectDecodedEntityReferences(state) {
1522
+ const depthMap = state.depthMap;
1523
+ return !state.plainText && !depthMap[34] && !depthMap[23] && !isInsideRawHtmlBlock(depthMap);
1524
+ }
1525
+ const SCRIPT_DATA = 0;
1526
+ const SCRIPT_DATA_ESCAPED = 1;
1527
+ const SCRIPT_DATA_ESCAPED_DASH = 2;
1528
+ const SCRIPT_DATA_ESCAPED_DASH_DASH = 3;
1529
+ const SCRIPT_DATA_DOUBLE_ESCAPED = 4;
1530
+ const SCRIPT_DATA_DOUBLE_ESCAPED_DASH = 5;
1531
+ const SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH = 6;
1532
+ const SCRIPT_SEQUENCE_NO_MATCH = -1;
1533
+ const SCRIPT_SEQUENCE_INCOMPLETE = -2;
1534
+ const SCRIPT_SCAN_COMPLETE = -1;
1535
+ const MAX_ELEMENT_DEPTH = 512;
1536
+ const HEAD_CONTENT_TAGS = /* @__PURE__ */ new Set([
1537
+ 4,
1538
+ 5,
1539
+ 54,
1540
+ 56,
1541
+ 53,
1542
+ 52,
1543
+ 84,
1544
+ 78
1545
+ ]);
1546
+ const CLOSES_P = (() => {
1547
+ const t = /* @__PURE__ */ new Uint8Array(113);
1548
+ for (const id of [
1549
+ 36,
1550
+ 35,
1551
+ 24,
1552
+ 33,
1553
+ 101,
1554
+ 25,
1555
+ 98,
1556
+ 99,
1557
+ 28,
1558
+ 7,
1559
+ 8,
1560
+ 9,
1561
+ 10,
1562
+ 11,
1563
+ 12,
1564
+ 22,
1565
+ 51,
1566
+ 50,
1567
+ 105,
1568
+ 47,
1569
+ 41,
1570
+ 88,
1571
+ 34,
1572
+ 13,
1573
+ 40,
1574
+ 68,
1575
+ 102,
1576
+ 106,
1577
+ 100,
1578
+ 104,
1579
+ 45,
1580
+ 2,
1581
+ 3,
1582
+ 75
1583
+ ]) t[id] = 1;
1584
+ return t;
1585
+ })();
1586
+ const NEEDS_IMPLIED_END_RECOVERY = (() => {
1587
+ const t = CLOSES_P.slice();
1588
+ for (const id of [
1589
+ 26,
1590
+ 32,
1591
+ 31,
1592
+ 30,
1593
+ 29,
1594
+ 38,
1595
+ 39,
1596
+ 67,
1597
+ 109,
1598
+ 65
1599
+ ]) t[id] = 1;
1600
+ return t;
1601
+ })();
1602
+ const P_SCOPE_BOUNDARY = /* @__PURE__ */ new Set([
1603
+ 43,
1604
+ 32,
1605
+ 31,
1606
+ 107,
1607
+ 28,
1608
+ 78,
1609
+ 0,
1610
+ 24,
1611
+ 33,
1612
+ 101,
1613
+ 25
1614
+ ]);
1615
+ const LI_SCOPE_BOUNDARY = /* @__PURE__ */ new Set([
1616
+ 24,
1617
+ 33,
1618
+ 28,
1619
+ 32,
1620
+ 31,
1621
+ 107,
1622
+ 78,
1623
+ 0
1624
+ ]);
1625
+ const DL_SCOPE_BOUNDARY = /* @__PURE__ */ new Set([
1626
+ 101,
1627
+ 24,
1628
+ 33,
1629
+ 25,
1630
+ 28,
1631
+ 32,
1632
+ 31,
1633
+ 107,
1634
+ 78,
1635
+ 0
1636
+ ]);
1637
+ const CELL_SCOPE_BOUNDARY = /* @__PURE__ */ new Set([
1638
+ 30,
1639
+ 29,
1640
+ 38,
1641
+ 39,
1642
+ 28,
1643
+ 107,
1644
+ 78,
1645
+ 0
1646
+ ]);
1647
+ const A_SCOPE_BOUNDARY = /* @__PURE__ */ new Set([
1648
+ 35,
1649
+ 36,
1650
+ 25,
1651
+ 24,
1652
+ 33,
1653
+ 101,
1654
+ 98,
1655
+ 99,
1656
+ 28,
1657
+ 32,
1658
+ 31,
1659
+ 30,
1660
+ 107,
1661
+ 22,
1662
+ 51,
1663
+ 50,
1664
+ 105,
1665
+ 47,
1666
+ 41,
1667
+ 88,
1668
+ 104,
1669
+ 40,
1670
+ 68,
1671
+ 102,
1672
+ 43,
1673
+ 7,
1674
+ 8,
1675
+ 9,
1676
+ 10,
1677
+ 11,
1678
+ 12,
1679
+ 78,
1680
+ 0
1681
+ ]);
1682
+ const HEADINGS = /* @__PURE__ */ new Set([
1683
+ 7,
1684
+ 8,
1685
+ 9,
1686
+ 10,
1687
+ 11,
1688
+ 12
1689
+ ]);
1690
+ const SINGLE_P = /* @__PURE__ */ new Set([35]);
1691
+ const SINGLE_LI = /* @__PURE__ */ new Set([25]);
1692
+ const SINGLE_A = /* @__PURE__ */ new Set([26]);
1693
+ const DT_DD = /* @__PURE__ */ new Set([99, 98]);
1694
+ const TD_TH = /* @__PURE__ */ new Set([32, 31]);
1695
+ const TR_CELLS = /* @__PURE__ */ new Set([
1696
+ 32,
1697
+ 31,
1698
+ 30
1699
+ ]);
1700
+ const SECTION_CELLS = /* @__PURE__ */ new Set([
1701
+ 32,
1702
+ 31,
1703
+ 30,
1704
+ 29,
1705
+ 38,
1706
+ 39,
1707
+ 107
1708
+ ]);
1709
+ function closeImpliedTo(state, target, boundary, handleEvent) {
1710
+ if (state.flattenedTagName) {
1711
+ const id = state.flattenedTagId;
1712
+ if (id !== void 0 && target.has(id)) {
1713
+ clearFlattenedElements(state);
1714
+ return;
1715
+ }
1716
+ if (id !== void 0 && boundary.has(id)) return;
1717
+ }
1718
+ let found = false;
1719
+ for (let node = state.currentNode; node; node = node.parent) {
1720
+ const id = node.tagId;
1721
+ if (id !== void 0 && target.has(id)) {
1722
+ found = true;
1723
+ break;
1724
+ }
1725
+ if (id !== void 0 && boundary.has(id)) break;
1726
+ }
1727
+ if (!found) return;
1728
+ clearFlattenedElements(state);
1729
+ while (state.currentNode) {
1730
+ const id = state.currentNode.tagId;
1731
+ const isTarget = id !== void 0 && target.has(id);
1732
+ closeNode(state.currentNode, state, handleEvent);
1733
+ if (isTarget) break;
1734
+ }
1735
+ }
1736
+ function closeTableContext(state, closeable, handleEvent) {
1737
+ if (state.flattenedTagName) {
1738
+ const id = state.flattenedTagId;
1739
+ if (id === void 0 || !closeable.has(id)) return;
1740
+ clearFlattenedElements(state);
1741
+ }
1742
+ let closeCount = 0;
1743
+ let walked = 0;
1744
+ for (let node = state.currentNode; node; node = node.parent) {
1745
+ const id = node.tagId;
1746
+ if (id !== void 0 && closeable.has(id)) {
1747
+ walked++;
1748
+ closeCount = walked;
1749
+ } else if (id === 28 || id === 78 || id === 107) break;
1750
+ else walked++;
1751
+ }
1752
+ for (let i = 0; i < closeCount && state.currentNode; i++) closeNode(state.currentNode, state, handleEvent);
1753
+ }
1754
+ function closeSelectTo(state, targetId, handleEvent) {
1755
+ if (state.flattenedTagName) {
1756
+ const id = state.flattenedTagId;
1757
+ if (id === targetId) {
1758
+ clearFlattenedElements(state);
1759
+ return true;
1760
+ }
1761
+ if (id === 65 && targetId !== 65 || id === 78) return false;
1762
+ }
1763
+ let target;
1764
+ for (let node = state.currentNode; node; node = node.parent) {
1765
+ if (node.tagId === targetId) {
1766
+ target = node;
1767
+ break;
1768
+ }
1769
+ if (node.tagId === 65 || node.tagId === 78) break;
1770
+ }
1771
+ if (!target) return false;
1772
+ clearFlattenedElements(state);
1773
+ while (state.currentNode && state.currentNode !== target) closeNode(state.currentNode, state, handleEvent);
1774
+ closeNode(target, state, handleEvent);
1775
+ return true;
1776
+ }
1777
+ function parserTagDepth(state, tagId) {
1778
+ return (state.depthMap[tagId] || 0) + (state.flattenedTagId === tagId ? state.flattenedTagDepth || 0 : 0);
1779
+ }
1780
+ function parserLastTagId(state) {
1781
+ return state.flattenedTagName ? state.flattenedTagId : state.currentNode?.tagId;
1782
+ }
1783
+ function popParserTop(state, handleEvent) {
1784
+ if (state.flattenedTagName) clearFlattenedElements(state);
1785
+ else closeNode(state.currentNode, state, handleEvent);
1786
+ }
1787
+ function findIncompleteTagResidualIndex(leftover) {
1788
+ let index = leftover.indexOf("<");
1789
+ while (index !== -1) {
1790
+ if (index + 1 === leftover.length) return index;
1791
+ const c = leftover.charCodeAt(index + 1);
1792
+ if (isAsciiAlpha(c) || c === SLASH_CHAR || c === EXCLAMATION_CHAR || c === QUESTION_CHAR) return index;
1793
+ index = leftover.indexOf("<", index + 1);
1794
+ }
1795
+ return -1;
1796
+ }
1797
+ function finalizeParse(leftover, state, handleEvent) {
1798
+ if (state.currentNode && isScriptElement(state.currentNode)) {
1799
+ pushScriptTextChunk(state, leftover);
1800
+ const scriptText = takeScriptText(state);
1801
+ if (scriptText) processTextBuffer(scriptText, state, handleEvent);
1802
+ } else if (leftover.length > 0) {
1803
+ const incompleteTagIndex = findIncompleteTagResidualIndex(leftover);
1804
+ const text = incompleteTagIndex === -1 ? leftover : leftover.slice(0, incompleteTagIndex);
1805
+ if (text) processTextBuffer(text, state, handleEvent);
1806
+ }
1807
+ while (state.currentNode) closeNode(state.currentNode, state, handleEvent);
1808
+ }
1809
+ const EMPTY_ATTRIBUTES = Object.freeze({});
1810
+ var ParsedElementNode = class {
1811
+ type = 1;
1812
+ name;
1813
+ attributes;
1814
+ parent;
1815
+ depth;
1816
+ index;
1817
+ tagId;
1818
+ tagHandler;
1819
+ currentWalkIndex;
1820
+ childTextNodeIndex;
1821
+ containsWhitespace;
1822
+ pluginOutput;
1823
+ context;
1824
+ cachedDepthMap;
1825
+ constructor(name, attributes, parent, depth, index, tagId, tagHandler) {
1826
+ this.name = name;
1827
+ this.attributes = attributes;
1828
+ this.parent = parent;
1829
+ this.depth = depth;
1830
+ this.index = index;
1831
+ this.tagId = tagId;
1832
+ this.tagHandler = tagHandler;
1833
+ }
1834
+ get depthMap() {
1835
+ if (this.cachedDepthMap) return this.cachedDepthMap;
1836
+ const depthMap = /* @__PURE__ */ new Uint16Array(113);
1837
+ if (this.tagId >= 0 && this.tagId < 113) depthMap[this.tagId] = 1;
1838
+ let node = this.parent;
1839
+ while (node) {
1840
+ const tagId = node.tagId;
1841
+ if (tagId !== void 0 && tagId >= 0 && tagId < 113) depthMap[tagId] = (depthMap[tagId] || 0) + 1;
1842
+ node = node.parent;
1843
+ }
1844
+ this.cachedDepthMap = depthMap;
1845
+ return depthMap;
1846
+ }
1847
+ };
1848
+ function isWhitespace(charCode) {
1849
+ return charCode === SPACE_CHAR || charCode === TAB_CHAR || charCode === NEWLINE_CHAR || charCode === FORM_FEED_CHAR || charCode === CARRIAGE_RETURN_CHAR;
1850
+ }
1851
+ function scriptSequenceEnd(html, nameStart) {
1852
+ const name = "script";
1853
+ for (let offset = 0; offset < 6; offset++) {
1854
+ const index = nameStart + offset;
1855
+ if (index >= html.length) return SCRIPT_SEQUENCE_INCOMPLETE;
1856
+ if ((html.charCodeAt(index) | 32) !== name.charCodeAt(offset)) return SCRIPT_SEQUENCE_NO_MATCH;
1857
+ }
1858
+ const delimiterIndex = nameStart + 6;
1859
+ if (delimiterIndex >= html.length) return SCRIPT_SEQUENCE_INCOMPLETE;
1860
+ const delimiter = html.charCodeAt(delimiterIndex);
1861
+ return delimiter === GT_CHAR || delimiter === SLASH_CHAR || isWhitespace(delimiter) ? delimiterIndex + 1 : SCRIPT_SEQUENCE_NO_MATCH;
1862
+ }
1863
+ function isScriptElement(node) {
1864
+ return node.tagId === 52 && node.name === "script";
1865
+ }
1866
+ function scriptScanResult(parseState, scriptState, result) {
1867
+ parseState.scriptDataState = scriptState;
1868
+ return result;
1869
+ }
1870
+ function findScriptEndTag(html, start, parseState) {
1871
+ let state = parseState.scriptDataState ?? SCRIPT_DATA;
1872
+ let i = start;
1873
+ while (i < html.length) {
1874
+ const charCode = html.charCodeAt(i);
1875
+ if (charCode === LT_CHAR) {
1876
+ if (i + 1 === html.length) return scriptScanResult(parseState, state, -i - 2);
1877
+ const next = html.charCodeAt(i + 1);
1878
+ if (state === SCRIPT_DATA) {
1879
+ if (next === SLASH_CHAR) {
1880
+ const sequenceEnd = scriptSequenceEnd(html, i + 2);
1881
+ if (sequenceEnd >= 0) return scriptScanResult(parseState, state, i);
1882
+ if (sequenceEnd === SCRIPT_SEQUENCE_INCOMPLETE) return scriptScanResult(parseState, state, -i - 2);
1883
+ } else if (next === EXCLAMATION_CHAR) {
1884
+ const marker = "<!--";
1885
+ const available = Math.min(html.length - i, 4);
1886
+ if (html.startsWith(marker.substring(0, available), i)) {
1887
+ if (available < 4) return scriptScanResult(parseState, state, -i - 2);
1888
+ state = SCRIPT_DATA_ESCAPED_DASH_DASH;
1889
+ i += 4;
1890
+ continue;
1891
+ }
1892
+ }
1893
+ } else {
1894
+ const escaped = state < SCRIPT_DATA_DOUBLE_ESCAPED;
1895
+ state = escaped ? SCRIPT_DATA_ESCAPED : SCRIPT_DATA_DOUBLE_ESCAPED;
1896
+ const isEndTag = next === SLASH_CHAR;
1897
+ if (isEndTag || escaped) {
1898
+ const sequenceEnd = scriptSequenceEnd(html, i + (isEndTag ? 2 : 1));
1899
+ if (sequenceEnd >= 0) {
1900
+ if (isEndTag) {
1901
+ if (escaped) return scriptScanResult(parseState, state, i);
1902
+ state = SCRIPT_DATA_ESCAPED;
1903
+ } else state = SCRIPT_DATA_DOUBLE_ESCAPED;
1904
+ i = sequenceEnd;
1905
+ continue;
1906
+ }
1907
+ if (sequenceEnd === SCRIPT_SEQUENCE_INCOMPLETE) return scriptScanResult(parseState, state, -i - 2);
1908
+ }
1909
+ }
1910
+ } else if (charCode === DASH_CHAR) {
1911
+ if (state === SCRIPT_DATA_ESCAPED || state === SCRIPT_DATA_ESCAPED_DASH) state++;
1912
+ else if (state === SCRIPT_DATA_DOUBLE_ESCAPED || state === SCRIPT_DATA_DOUBLE_ESCAPED_DASH) state++;
1913
+ } else if (state === SCRIPT_DATA_ESCAPED_DASH || state === SCRIPT_DATA_ESCAPED_DASH_DASH) state = charCode === GT_CHAR && state === SCRIPT_DATA_ESCAPED_DASH_DASH ? SCRIPT_DATA : SCRIPT_DATA_ESCAPED;
1914
+ else if (state === SCRIPT_DATA_DOUBLE_ESCAPED_DASH || state === SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH) state = charCode === GT_CHAR && state === SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH ? SCRIPT_DATA : SCRIPT_DATA_DOUBLE_ESCAPED;
1915
+ i++;
1916
+ }
1917
+ return scriptScanResult(parseState, state, SCRIPT_SCAN_COMPLETE);
1918
+ }
1919
+ function pushScriptTextChunk(state, text) {
1920
+ if (!text) return;
1921
+ (state.scriptTextChunks ??= []).push(text);
1922
+ state.textBufferContainsNonWhitespace = true;
1923
+ state.lastCharWasWhitespace = false;
1924
+ state.justClosedTag = false;
1925
+ }
1926
+ function scanScriptChunk(html, start, state) {
1927
+ const result = findScriptEndTag(html, start, state);
1928
+ if (result === SCRIPT_SCAN_COMPLETE) pushScriptTextChunk(state, html.substring(start));
1929
+ else if (result <= SCRIPT_SEQUENCE_INCOMPLETE) pushScriptTextChunk(state, html.substring(start, -result - 2));
1930
+ else pushScriptTextChunk(state, html.substring(start, result));
1931
+ return result;
1932
+ }
1933
+ function takeScriptText(state) {
1934
+ const chunks = state.scriptTextChunks;
1935
+ const text = chunks?.length ? chunks.length === 1 ? chunks[0] : chunks.join("") : "";
1936
+ if (chunks) chunks.length = 0;
1937
+ state.scriptDataState = SCRIPT_DATA;
1938
+ return text;
1939
+ }
1940
+ function normalizeTagName(tagName) {
1941
+ for (let i = 0; i < tagName.length; i++) {
1942
+ const code = tagName.charCodeAt(i);
1943
+ if (code >= 65 && code <= 90) return tagName.toLowerCase();
1944
+ }
1945
+ return tagName;
1946
+ }
1947
+ function effectiveTagId(tagName, fallbackTagId, state) {
1948
+ return state.tagOverrideHandlers?.get(tagName)?.aliasTagId ?? fallbackTagId;
1949
+ }
1950
+ function matchesClosingTag(node, tagName, tagId, closingIsAlias) {
1951
+ if (node.tagId !== tagId) return false;
1952
+ if (tagId === -1) return node.name === tagName;
1953
+ const nodeIsAlias = node.tagHandler?.aliasTagId !== void 0;
1954
+ return node.name === tagName || !nodeIsAlias && !closingIsAlias;
1955
+ }
1956
+ function parseHtml(html, options = {}) {
1957
+ const events = [];
1958
+ const state = {
1959
+ depthMap: /* @__PURE__ */ new Uint16Array(113),
1960
+ depth: 0,
1961
+ resolvedPlugins: options.resolvedPlugins || []
1962
+ };
1963
+ let remainingHtml = parseHtmlInternal(html, state, (event) => {
1964
+ events.push(event);
1965
+ });
1966
+ if (state.scriptTextChunks?.length) remainingHtml = `${takeScriptText(state)}${remainingHtml}`;
1967
+ return {
1968
+ events,
1969
+ remainingHtml
1970
+ };
1971
+ }
1972
+ function parseHtmlStream(html, state, onEvent) {
1973
+ return parseHtmlInternal(html, state, onEvent);
1974
+ }
1975
+ function parseHtmlInternal(htmlChunk, state, handleEvent) {
1976
+ let textBuffer = "";
1977
+ let runStart = 0;
1978
+ state.depthMap ??= /* @__PURE__ */ new Uint16Array(113);
1979
+ state.depth ??= 0;
1980
+ state.lastCharWasWhitespace ??= true;
1981
+ state.justClosedTag ??= false;
1982
+ state.isFirstTextInElement ??= false;
1983
+ state.scriptDataState ??= SCRIPT_DATA;
1984
+ let i = 0;
1985
+ const chunkLength = htmlChunk.length;
1986
+ if (state.currentNode && isScriptElement(state.currentNode)) {
1987
+ const scanResult = scanScriptChunk(htmlChunk, i, state);
1988
+ if (scanResult < 0) return scanResult <= SCRIPT_SEQUENCE_INCOMPLETE ? htmlChunk.substring(-scanResult - 2) : "";
1989
+ textBuffer = takeScriptText(state);
1990
+ i = scanResult;
1991
+ }
1992
+ while (i < chunkLength) {
1993
+ const currentCharCode = htmlChunk.charCodeAt(i);
1994
+ if (currentCharCode !== LT_CHAR) {
1995
+ if (currentCharCode === AMPERSAND_CHAR) state.hasEncodedHtmlEntity = true;
1996
+ if (isWhitespace(currentCharCode)) {
1997
+ const inPreTag = (state.depthMap[34] || 0) > 0;
1998
+ if (state.justClosedTag) {
1999
+ state.justClosedTag = false;
2000
+ state.lastCharWasWhitespace = false;
2001
+ }
2002
+ if (!inPreTag && state.lastCharWasWhitespace) {
2003
+ if (textBuffer.length === 0) runStart = i + 1;
2004
+ i++;
2005
+ continue;
2006
+ }
2007
+ if (inPreTag) textBuffer += htmlChunk[i];
2008
+ else if (currentCharCode === SPACE_CHAR || !state.lastCharWasWhitespace) textBuffer += " ";
2009
+ state.lastCharWasWhitespace = true;
2010
+ state.textBufferContainsWhitespace = true;
2011
+ } else {
2012
+ state.textBufferContainsNonWhitespace = true;
2013
+ state.lastCharWasWhitespace = false;
2014
+ state.justClosedTag = false;
2015
+ textBuffer += htmlChunk[i];
2016
+ }
2017
+ i++;
2018
+ continue;
2019
+ }
2020
+ if (i + 1 >= chunkLength) {
2021
+ textBuffer += htmlChunk[i];
2022
+ break;
2023
+ }
2024
+ const nextCharCode = htmlChunk.charCodeAt(i + 1);
2025
+ if (state.flattenedRawTagName) {
2026
+ if (nextCharCode === SLASH_CHAR) {
2027
+ let peekEnd = i + 2;
2028
+ while (peekEnd < chunkLength) {
2029
+ const c = htmlChunk.charCodeAt(peekEnd);
2030
+ if (c === GT_CHAR || c === SLASH_CHAR || isWhitespace(c)) break;
2031
+ peekEnd++;
2032
+ }
2033
+ if (peekEnd === chunkLength) {
2034
+ textBuffer += htmlChunk.substring(i);
2035
+ break;
2036
+ }
2037
+ if (normalizeTagName(htmlChunk.substring(i + 2, peekEnd)) !== state.flattenedRawTagName) {
2038
+ textBuffer += htmlChunk[i++];
2039
+ continue;
2040
+ }
2041
+ } else {
2042
+ textBuffer += htmlChunk[i++];
2043
+ continue;
2044
+ }
2045
+ }
2046
+ if (nextCharCode === EXCLAMATION_CHAR) {
2047
+ if (htmlChunk.charCodeAt(i + 2) === OPEN_BRACKET_CHAR) {
2048
+ if (htmlChunk.startsWith("<![CDATA[", i)) {
2049
+ const end = htmlChunk.indexOf("]]>", i + 9);
2050
+ if (end === -1) {
2051
+ textBuffer += htmlChunk.substring(i);
2052
+ break;
2053
+ }
2054
+ if (textBuffer.length > 0) {
2055
+ processTextBuffer(textBuffer, state, handleEvent);
2056
+ textBuffer = "";
2057
+ runStart = i;
2058
+ }
2059
+ processCdataSection(htmlChunk.substring(i + 9, end), state, handleEvent);
2060
+ i = end + 3;
2061
+ runStart = i;
2062
+ continue;
2063
+ }
2064
+ if (chunkLength - i < 9 && "<![CDATA[".startsWith(htmlChunk.substring(i))) {
2065
+ textBuffer += htmlChunk.substring(i);
2066
+ break;
2067
+ }
2068
+ }
2069
+ if (textBuffer.length > 0) {
2070
+ processTextBuffer(textBuffer, state, handleEvent);
2071
+ textBuffer = "";
2072
+ runStart = i;
2073
+ }
2074
+ const result = processCommentOrDoctype(htmlChunk, i);
2075
+ if (result.complete) {
2076
+ i = result.newPosition;
2077
+ runStart = i;
2078
+ } else {
2079
+ textBuffer += result.remainingText;
2080
+ break;
2081
+ }
2082
+ } else if (nextCharCode === SLASH_CHAR) {
2083
+ if (state.currentNode?.tagHandler?.isNonNesting) {
2084
+ let peekEnd = i + 2;
2085
+ while (peekEnd < chunkLength) {
2086
+ const c = htmlChunk.charCodeAt(peekEnd);
2087
+ if (c === GT_CHAR || c === SLASH_CHAR || isWhitespace(c)) break;
2088
+ peekEnd++;
2089
+ }
2090
+ const peekTagName = normalizeTagName(htmlChunk.substring(i + 2, peekEnd));
2091
+ const peekHandler = state.tagOverrideHandlers?.get(peekTagName);
2092
+ const peekTagId = effectiveTagId(peekTagName, TagIdMap[peekTagName] ?? -1, state);
2093
+ if (!matchesClosingTag(state.currentNode, peekTagName, peekTagId, peekHandler?.aliasTagId !== void 0)) {
2094
+ textBuffer += htmlChunk[i++];
2095
+ continue;
2096
+ }
2097
+ }
2098
+ if (textBuffer.length > 0) {
2099
+ processTextBuffer(textBuffer, state, handleEvent);
2100
+ textBuffer = "";
2101
+ runStart = i;
2102
+ }
2103
+ const result = processClosingTag(htmlChunk, i, state, handleEvent);
2104
+ if (result.complete) {
2105
+ i = result.newPosition;
2106
+ runStart = i;
2107
+ } else {
2108
+ textBuffer += result.remainingText;
2109
+ break;
2110
+ }
2111
+ } else if (!isAsciiAlpha(nextCharCode) && nextCharCode !== QUESTION_CHAR) {
2112
+ state.textBufferContainsNonWhitespace = true;
2113
+ state.lastCharWasWhitespace = false;
2114
+ state.justClosedTag = false;
2115
+ textBuffer += htmlChunk[i++];
2116
+ continue;
2117
+ } else {
2118
+ let i2 = i + 1;
2119
+ const tagNameStart = i2;
2120
+ let tagNameEnd = -1;
2121
+ while (i2 < chunkLength) {
2122
+ const c = htmlChunk.charCodeAt(i2);
2123
+ if (isWhitespace(c) || c === SLASH_CHAR || c === GT_CHAR) {
2124
+ tagNameEnd = i2;
2125
+ break;
2126
+ }
2127
+ i2++;
2128
+ }
2129
+ if (tagNameEnd === -1) {
2130
+ textBuffer += htmlChunk.substring(i);
2131
+ break;
2132
+ }
2133
+ const rawTagName = htmlChunk.substring(tagNameStart, tagNameEnd);
2134
+ let tagName = rawTagName;
2135
+ if (typeof TagIdMap[tagName] !== "number") tagName = normalizeTagName(rawTagName);
2136
+ const mappedTagId = TagIdMap[tagName];
2137
+ const tagId = effectiveTagId(tagName, typeof mappedTagId === "number" ? mappedTagId : -1, state);
2138
+ i2 = tagNameEnd;
2139
+ if (state.currentNode?.tagHandler?.isNonNesting) {
2140
+ textBuffer += htmlChunk[i++];
2141
+ continue;
2142
+ }
2143
+ if (!tagName) {
2144
+ state.textBufferContainsNonWhitespace = true;
2145
+ state.lastCharWasWhitespace = false;
2146
+ state.justClosedTag = false;
2147
+ textBuffer += htmlChunk[i++];
2148
+ continue;
2149
+ }
2150
+ if (textBuffer.length > 0) {
2151
+ processTextBuffer(textBuffer, state, handleEvent);
2152
+ textBuffer = "";
2153
+ runStart = i;
2154
+ }
2155
+ const result = processOpeningTag(tagName, tagId, htmlChunk, i2, state, handleEvent);
2156
+ if (result.skip) {
2157
+ i = result.newPosition;
2158
+ runStart = i;
2159
+ } else if (result.complete) {
2160
+ i = result.newPosition;
2161
+ if (!result.selfClosing) {
2162
+ state.isFirstTextInElement = true;
2163
+ if (tagId === 52 && tagName === "script") {
2164
+ const scanResult = scanScriptChunk(htmlChunk, i, state);
2165
+ if (scanResult < 0) {
2166
+ if (scanResult <= SCRIPT_SEQUENCE_INCOMPLETE) {
2167
+ runStart = -scanResult - 2;
2168
+ textBuffer = htmlChunk.substring(runStart);
2169
+ } else textBuffer = "";
2170
+ break;
2171
+ }
2172
+ textBuffer = takeScriptText(state);
2173
+ i = scanResult;
2174
+ }
2175
+ }
2176
+ if (textBuffer.length === 0) runStart = i;
2177
+ } else {
2178
+ textBuffer += result.remainingText;
2179
+ break;
2180
+ }
2181
+ }
2182
+ }
2183
+ const remainingHtml = textBuffer.length > 0 ? htmlChunk.substring(runStart) : "";
2184
+ if (remainingHtml.length > 0 && isWhitespace(remainingHtml.charCodeAt(0))) state.lastCharWasWhitespace = false;
2185
+ return remainingHtml;
2186
+ }
2187
+ function processTextBuffer(textBuffer, state, handleEvent) {
2188
+ const containsNonWhitespace = state.textBufferContainsNonWhitespace;
2189
+ const containsWhitespace = state.textBufferContainsWhitespace;
2190
+ state.textBufferContainsNonWhitespace = false;
2191
+ state.textBufferContainsWhitespace = false;
2192
+ if (!state.currentNode) {
2193
+ let rootText = textBuffer;
2194
+ if (rootText.length === 0) return;
2195
+ if (state.hasEncodedHtmlEntity) {
2196
+ rootText = decodeHTMLEntities(String(rootText), false, shouldProtectDecodedEntityReferences(state));
2197
+ state.hasEncodedHtmlEntity = false;
2198
+ }
2199
+ const rootTextNode = {
2200
+ type: 2,
2201
+ value: rootText,
2202
+ parent: null,
2203
+ index: 0,
2204
+ depth: state.depth,
2205
+ containsWhitespace,
2206
+ excludedFromMarkdown: false
2207
+ };
2208
+ handleEvent({
2209
+ type: 0,
2210
+ node: rootTextNode
2211
+ });
2212
+ state.lastTextNode = rootTextNode;
2213
+ return;
2214
+ }
2215
+ const excludesTextNodes = (state.flattenedOpaqueDepth || 0) > 0 || state.flattenedRawExcludesText || state.currentNode?.tagHandler?.excludesTextNodes || state.currentNode?.excludedFromMarkdown;
2216
+ const inPreTag = (state.depthMap[34] || 0) > 0;
2217
+ if (!inPreTag && !containsNonWhitespace && !state.currentNode.childTextNodeIndex) return;
2218
+ let text = textBuffer;
2219
+ if (text.length === 0) return;
2220
+ const parentsToIncrement = traverseUpToFirstBlockNode(state.currentNode);
2221
+ const firstBlockParent = parentsToIncrement.at(-1);
2222
+ if (containsWhitespace && !firstBlockParent?.childTextNodeIndex) {
2223
+ let start = 0;
2224
+ while (start < text.length && (inPreTag ? text.charCodeAt(start) === NEWLINE_CHAR || text.charCodeAt(start) === CARRIAGE_RETURN_CHAR : isWhitespace(text.charCodeAt(start)))) start++;
2225
+ if (start > 0) text = text.substring(start);
2226
+ }
2227
+ if (state.hasEncodedHtmlEntity) {
2228
+ text = decodeHTMLEntities(String(text), false, shouldProtectDecodedEntityReferences(state));
2229
+ state.hasEncodedHtmlEntity = false;
2230
+ }
2231
+ const textNode = {
2232
+ type: 2,
2233
+ value: text,
2234
+ parent: state.currentNode,
2235
+ index: state.currentNode.currentWalkIndex++,
2236
+ depth: state.depth,
2237
+ containsWhitespace,
2238
+ excludedFromMarkdown: excludesTextNodes
2239
+ };
2240
+ for (const parent of parentsToIncrement) parent.childTextNodeIndex = (parent.childTextNodeIndex || 0) + 1;
2241
+ handleEvent({
2242
+ type: 0,
2243
+ node: textNode
2244
+ });
2245
+ state.lastTextNode = textNode;
2246
+ }
2247
+ function processClosingTag(htmlChunk, position, state, handleEvent) {
2248
+ let i = position + 2;
2249
+ const tagNameStart = i;
2250
+ const chunkLength = htmlChunk.length;
2251
+ let tagNameEnd = -1;
2252
+ let quoteChar = 0;
2253
+ let foundClose = false;
2254
+ while (i < chunkLength) {
2255
+ const charCode = htmlChunk.charCodeAt(i);
2256
+ if (tagNameEnd !== -1) {
2257
+ if (quoteChar) {
2258
+ if (charCode === quoteChar) quoteChar = 0;
2259
+ i++;
2260
+ continue;
2261
+ }
2262
+ if (charCode === QUOTE_CHAR || charCode === APOS_CHAR) {
2263
+ quoteChar = charCode;
2264
+ i++;
2265
+ continue;
2266
+ }
2267
+ }
2268
+ if (charCode === GT_CHAR) {
2269
+ foundClose = true;
2270
+ break;
2271
+ }
2272
+ if (tagNameEnd === -1 && (isWhitespace(charCode) || charCode === SLASH_CHAR)) tagNameEnd = i;
2273
+ i++;
2274
+ }
2275
+ if (!foundClose) return {
2276
+ complete: false,
2277
+ newPosition: position,
2278
+ remainingText: htmlChunk.substring(position)
2279
+ };
2280
+ const rawTagName = htmlChunk.substring(tagNameStart, tagNameEnd === -1 ? i : tagNameEnd);
2281
+ let tagName = rawTagName;
2282
+ if (typeof TagIdMap[tagName] !== "number") tagName = normalizeTagName(rawTagName);
2283
+ const tagHandler = state.tagOverrideHandlers?.get(tagName);
2284
+ const mappedTagId = TagIdMap[tagName];
2285
+ const tagId = effectiveTagId(tagName, typeof mappedTagId === "number" ? mappedTagId : -1, state);
2286
+ const closingIsAlias = tagHandler?.aliasTagId !== void 0;
2287
+ if ((state.flattenedOpaqueDepth || 0) > 0) {
2288
+ if (state.flattenedRawTagName !== void 0) {
2289
+ state.flattenedRawTagName = void 0;
2290
+ state.flattenedRawExcludesText = void 0;
2291
+ }
2292
+ if (tagName === state.flattenedOpaqueTagName) {
2293
+ state.flattenedOpaqueDepth--;
2294
+ if (!state.flattenedOpaqueDepth) {
2295
+ state.flattenedOpaqueTagName = void 0;
2296
+ if (tagName === state.flattenedTagName) {
2297
+ state.flattenedTagDepth--;
2298
+ if (!state.flattenedTagDepth) clearFlattenedElements(state);
2299
+ }
2300
+ }
2301
+ }
2302
+ state.justClosedTag = true;
2303
+ return {
2304
+ complete: true,
2305
+ newPosition: i + 1,
2306
+ remainingText: ""
2307
+ };
2308
+ }
2309
+ const stopAtTemplate = tagId !== 78 && (state.depthMap[78] || 0) > 0;
2310
+ let curr;
2311
+ if (state.flattenedTagName) {
2312
+ const closedRaw = state.flattenedRawTagName !== void 0;
2313
+ if (closedRaw) {
2314
+ state.flattenedRawTagName = void 0;
2315
+ state.flattenedRawExcludesText = void 0;
2316
+ }
2317
+ if (tagName === state.flattenedTagName) {
2318
+ state.flattenedTagDepth--;
2319
+ if (!state.flattenedTagDepth) clearFlattenedElements(state);
2320
+ state.justClosedTag = true;
2321
+ return {
2322
+ complete: true,
2323
+ newPosition: i + 1,
2324
+ remainingText: ""
2325
+ };
2326
+ }
2327
+ if (!closedRaw) {
2328
+ curr = state.currentNode;
2329
+ while (curr && !matchesClosingTag(curr, tagName, tagId, closingIsAlias)) {
2330
+ if (stopAtTemplate && curr.tagId === 78) {
2331
+ curr = null;
2332
+ break;
2333
+ }
2334
+ curr = curr.parent;
2335
+ }
2336
+ if (curr) clearFlattenedElements(state);
2337
+ else {
2338
+ state.justClosedTag = true;
2339
+ return {
2340
+ complete: true,
2341
+ newPosition: i + 1,
2342
+ remainingText: ""
2343
+ };
2344
+ }
2345
+ }
2346
+ if (closedRaw) {
2347
+ state.justClosedTag = true;
2348
+ return {
2349
+ complete: true,
2350
+ newPosition: i + 1,
2351
+ remainingText: ""
2352
+ };
2353
+ }
2354
+ }
2355
+ if (state.currentNode?.tagHandler?.isNonNesting && !matchesClosingTag(state.currentNode, tagName, tagId, closingIsAlias)) return {
2356
+ complete: false,
2357
+ newPosition: position,
2358
+ remainingText: htmlChunk.substring(position)
2359
+ };
2360
+ if (!curr) {
2361
+ curr = state.currentNode;
2362
+ while (curr && !matchesClosingTag(curr, tagName, tagId, closingIsAlias)) {
2363
+ if (stopAtTemplate && curr.tagId === 78) {
2364
+ curr = null;
2365
+ break;
2366
+ }
2367
+ curr = curr.parent;
2368
+ }
2369
+ }
2370
+ if (curr) {
2371
+ while (state.currentNode && state.currentNode !== curr) closeNode(state.currentNode, state, handleEvent);
2372
+ closeNode(curr, state, handleEvent);
2373
+ }
2374
+ state.justClosedTag = true;
2375
+ return {
2376
+ complete: true,
2377
+ newPosition: i + 1,
2378
+ remainingText: ""
2379
+ };
2380
+ }
2381
+ function closeNode(node, state, handleEvent) {
2382
+ if (!node) return;
2383
+ if (node.tagId === 26 && !node.childTextNodeIndex) {
2384
+ const prefix = node.attributes?.title || node.attributes?.["aria-label"] || "";
2385
+ if (prefix) {
2386
+ node.childTextNodeIndex = 1;
2387
+ handleEvent({
2388
+ type: 0,
2389
+ node: {
2390
+ type: 2,
2391
+ value: prefix,
2392
+ parent: node,
2393
+ index: 0,
2394
+ depth: node.depth + 1
2395
+ }
2396
+ });
2397
+ for (const parent of traverseUpToFirstBlockNode(node)) parent.childTextNodeIndex = (parent.childTextNodeIndex || 0) + 1;
2398
+ }
2399
+ }
2400
+ const tagId = node.tagId;
2401
+ if (tagId !== void 0 && tagId >= 0 && tagId < 113) state.depthMap[tagId] = Math.max(0, (state.depthMap[tagId] || 0) - 1);
2402
+ state.depth--;
2403
+ handleEvent({
2404
+ type: 1,
2405
+ node
2406
+ });
2407
+ state.currentNode = state.currentNode.parent;
2408
+ state.hasEncodedHtmlEntity = false;
2409
+ state.justClosedTag = true;
2410
+ }
2411
+ function clearFlattenedElements(state) {
2412
+ state.flattenedTagName = void 0;
2413
+ state.flattenedTagId = void 0;
2414
+ state.flattenedTagDepth = void 0;
2415
+ state.flattenedRawTagName = void 0;
2416
+ state.flattenedRawExcludesText = void 0;
2417
+ }
2418
+ function startsOpaqueFlattening(state, tagName, tagId, attributes, tagHandler) {
2419
+ if (tagId === 78) return true;
2420
+ const plugins = state.resolvedPlugins;
2421
+ if (!plugins) return false;
2422
+ let node;
2423
+ for (const plugin of plugins) {
2424
+ if (!plugin.excludesOverflowSubtree) continue;
2425
+ node ||= new ParsedElementNode(tagName, attributes, state.currentNode, state.depth + 1, 0, tagId, tagHandler);
2426
+ if (plugin.excludesOverflowSubtree(node)) return true;
2427
+ }
2428
+ return false;
2429
+ }
2430
+ function enterOpaqueFlattening(state, tagName, tagHandler) {
2431
+ state.flattenedOpaqueTagName = tagName;
2432
+ state.flattenedOpaqueDepth = 1;
2433
+ if (tagHandler?.isNonNesting) {
2434
+ state.flattenedRawTagName = tagName;
2435
+ state.flattenedRawExcludesText = tagHandler.excludesTextNodes;
2436
+ }
2437
+ }
2438
+ function processCommentOrDoctype(htmlChunk, position) {
2439
+ let i = position;
2440
+ const chunkLength = htmlChunk.length;
2441
+ if (i + 3 < chunkLength && htmlChunk.charCodeAt(i + 2) === DASH_CHAR && htmlChunk.charCodeAt(i + 3) === DASH_CHAR) {
2442
+ i += 4;
2443
+ if (i < chunkLength && htmlChunk.charCodeAt(i) === GT_CHAR) return {
2444
+ complete: true,
2445
+ newPosition: i + 1,
2446
+ remainingText: ""
2447
+ };
2448
+ if (i + 1 < chunkLength && htmlChunk.charCodeAt(i) === DASH_CHAR && htmlChunk.charCodeAt(i + 1) === GT_CHAR) return {
2449
+ complete: true,
2450
+ newPosition: i + 2,
2451
+ remainingText: ""
2452
+ };
2453
+ while (i + 2 < chunkLength) {
2454
+ const dash = htmlChunk.indexOf("-", i);
2455
+ if (dash < 0 || dash + 2 >= chunkLength) break;
2456
+ i = dash;
2457
+ if (htmlChunk.charCodeAt(i + 1) === DASH_CHAR) {
2458
+ const afterDashes = htmlChunk.charCodeAt(i + 2);
2459
+ if (afterDashes === GT_CHAR) return {
2460
+ complete: true,
2461
+ newPosition: i + 3,
2462
+ remainingText: ""
2463
+ };
2464
+ if (afterDashes === EXCLAMATION_CHAR && i + 3 < chunkLength && htmlChunk.charCodeAt(i + 3) === GT_CHAR) return {
2465
+ complete: true,
2466
+ newPosition: i + 4,
2467
+ remainingText: ""
2468
+ };
2469
+ }
2470
+ i++;
2471
+ }
2472
+ return {
2473
+ complete: false,
2474
+ newPosition: position,
2475
+ remainingText: htmlChunk.substring(position)
2476
+ };
2477
+ } else {
2478
+ i += 2;
2479
+ while (i < chunkLength) {
2480
+ if (htmlChunk.charCodeAt(i) === GT_CHAR) {
2481
+ i++;
2482
+ return {
2483
+ complete: true,
2484
+ newPosition: i,
2485
+ remainingText: ""
2486
+ };
2487
+ }
2488
+ i++;
2489
+ }
2490
+ return {
2491
+ complete: false,
2492
+ newPosition: i,
2493
+ remainingText: htmlChunk.substring(position, i)
2494
+ };
2495
+ }
2496
+ }
2497
+ function processCdataSection(content, state, handleEvent) {
2498
+ if (!state.tagOverrideHandlers?.has("#cdata-section")) return;
2499
+ const open = processOpeningTag("#cdata-section", -1, ">", 0, state, handleEvent);
2500
+ if (!open.complete || open.selfClosing || open.skip) return;
2501
+ const node = state.currentNode;
2502
+ if (content.length > 0 && !node.tagHandler?.excludesTextNodes) {
2503
+ const textNode = {
2504
+ type: 2,
2505
+ value: content,
2506
+ parent: node,
2507
+ index: node.currentWalkIndex++,
2508
+ depth: state.depth,
2509
+ containsWhitespace: false
2510
+ };
2511
+ for (const parent of traverseUpToFirstBlockNode(node)) parent.childTextNodeIndex = (parent.childTextNodeIndex || 0) + 1;
2512
+ handleEvent({
2513
+ type: 0,
2514
+ node: textNode
2515
+ });
2516
+ state.lastTextNode = textNode;
2517
+ }
2518
+ closeNode(state.currentNode ?? null, state, handleEvent);
2519
+ }
2520
+ function processOpeningTag(tagName, tagId, htmlChunk, i, state, handleEvent) {
2521
+ tagId = effectiveTagId(tagName, tagId, state);
2522
+ if (state.currentNode?.tagHandler?.isNonNesting) closeNode(state.currentNode, state, handleEvent);
2523
+ const tagHandler = state.tagOverrideHandlers?.get(tagName) ?? (tagId === -1 ? UNKNOWN_TAG_HANDLER : tagHandlers[tagId]);
2524
+ const result = scanTagAttributes(htmlChunk, i, tagHandler);
2525
+ if (result._tag === "incomplete") return {
2526
+ complete: false,
2527
+ newPosition: i,
2528
+ remainingText: `<${tagName}${result.attrBuffer}`,
2529
+ selfClosing: false
2530
+ };
2531
+ if ((state.flattenedOpaqueDepth || 0) > 0) {
2532
+ if (!result.selfClosing && tagName === state.flattenedOpaqueTagName) state.flattenedOpaqueDepth++;
2533
+ if (!result.selfClosing && tagHandler?.isNonNesting) {
2534
+ state.flattenedRawTagName = tagName;
2535
+ state.flattenedRawExcludesText = tagHandler.excludesTextNodes;
2536
+ }
2537
+ return {
2538
+ complete: true,
2539
+ newPosition: result.newPosition,
2540
+ remainingText: "",
2541
+ selfClosing: result.selfClosing,
2542
+ skip: true
2543
+ };
2544
+ }
2545
+ if (!state.flattenedTagName && (state.depthMap[1] || 0) > 0 && (state.depthMap[78] || 0) === 0 && !HEAD_CONTENT_TAGS.has(tagId)) {
2546
+ while (state.currentNode && state.currentNode.tagId !== 1) closeNode(state.currentNode, state, handleEvent);
2547
+ const headNode = state.currentNode;
2548
+ if (headNode && headNode.tagId === 1) closeNode(headNode, state, handleEvent);
2549
+ }
2550
+ if (tagId >= 0 && tagId < 113 && NEEDS_IMPLIED_END_RECOVERY[tagId] === 1) {
2551
+ if (tagId === 65 && parserTagDepth(state, 65) > 0) {
2552
+ if (closeSelectTo(state, 65, handleEvent)) return {
2553
+ complete: true,
2554
+ newPosition: result.newPosition,
2555
+ remainingText: "",
2556
+ selfClosing: false,
2557
+ skip: true
2558
+ };
2559
+ } else if (tagId === 67) {
2560
+ if (parserTagDepth(state, 65) > 0) closeSelectTo(state, 67, handleEvent);
2561
+ else if (parserLastTagId(state) === 67) popParserTop(state, handleEvent);
2562
+ } else if (tagId === 109 && parserTagDepth(state, 65) > 0) {
2563
+ closeSelectTo(state, 67, handleEvent);
2564
+ closeSelectTo(state, 109, handleEvent);
2565
+ } else if (tagId === 26) {
2566
+ if (parserTagDepth(state, 26) > 0) closeImpliedTo(state, SINGLE_A, A_SCOPE_BOUNDARY, handleEvent);
2567
+ } else if (tagId === 32 || tagId === 31 || tagId === 30 || tagId === 29 || tagId === 38 || tagId === 39) {
2568
+ if (parserTagDepth(state, 28) > 0) {
2569
+ if (tagId === 32 || tagId === 31) {
2570
+ if (parserTagDepth(state, 32) > 0 || parserTagDepth(state, 31) > 0) closeImpliedTo(state, TD_TH, CELL_SCOPE_BOUNDARY, handleEvent);
2571
+ } else if (tagId === 30) {
2572
+ if (parserTagDepth(state, 30) > 0) closeTableContext(state, TR_CELLS, handleEvent);
2573
+ } else closeTableContext(state, SECTION_CELLS, handleEvent);
2574
+ }
2575
+ } else {
2576
+ if (parserTagDepth(state, 35) > 0) closeImpliedTo(state, SINGLE_P, P_SCOPE_BOUNDARY, handleEvent);
2577
+ if (HEADINGS.has(tagId)) {
2578
+ const topId = parserLastTagId(state);
2579
+ if (topId !== void 0 && HEADINGS.has(topId)) popParserTop(state, handleEvent);
2580
+ } else if (tagId === 25) {
2581
+ if (parserTagDepth(state, 25) > 0) closeImpliedTo(state, SINGLE_LI, LI_SCOPE_BOUNDARY, handleEvent);
2582
+ } else if (tagId === 99 || tagId === 98) {
2583
+ if (parserTagDepth(state, 99) > 0 || parserTagDepth(state, 98) > 0) closeImpliedTo(state, DT_DD, DL_SCOPE_BOUNDARY, handleEvent);
2584
+ }
2585
+ }
2586
+ }
2587
+ if (state.flattenedTagName && !result.selfClosing) {
2588
+ if (tagName === state.flattenedTagName) state.flattenedTagDepth++;
2589
+ if (startsOpaqueFlattening(state, tagName, tagId, result.attributes, tagHandler)) enterOpaqueFlattening(state, tagName, tagHandler);
2590
+ else if (tagHandler?.isNonNesting) {
2591
+ state.flattenedRawTagName = tagName;
2592
+ state.flattenedRawExcludesText = tagHandler.excludesTextNodes;
2593
+ }
2594
+ return {
2595
+ complete: true,
2596
+ newPosition: result.newPosition,
2597
+ remainingText: "",
2598
+ selfClosing: false,
2599
+ skip: true
2600
+ };
2601
+ }
2602
+ if (!result.selfClosing && state.depth >= MAX_ELEMENT_DEPTH) {
2603
+ state.flattenedTagName = tagName;
2604
+ state.flattenedTagId = tagId;
2605
+ state.flattenedTagDepth = 1;
2606
+ if (startsOpaqueFlattening(state, tagName, tagId, result.attributes, tagHandler)) enterOpaqueFlattening(state, tagName, tagHandler);
2607
+ else if (tagHandler?.isNonNesting) {
2608
+ state.flattenedRawTagName = tagName;
2609
+ state.flattenedRawExcludesText = tagHandler.excludesTextNodes;
2610
+ }
2611
+ return {
2612
+ complete: true,
2613
+ newPosition: result.newPosition,
2614
+ remainingText: "",
2615
+ selfClosing: false,
2616
+ skip: true
2617
+ };
2618
+ }
2619
+ if (tagId >= 0 && tagId < 113) state.depthMap[tagId] = (state.depthMap[tagId] || 0) + 1;
2620
+ state.depth++;
2621
+ i = result.newPosition;
2622
+ if (state.currentNode) state.currentNode.currentWalkIndex = state.currentNode.currentWalkIndex || 0;
2623
+ const currentWalkIndex = state.currentNode ? state.currentNode.currentWalkIndex++ : 0;
2624
+ const tag = new ParsedElementNode(tagName, result.attributes, state.currentNode, state.depth, currentWalkIndex, tagId, tagHandler);
2625
+ if (tagId === 78 || state.currentNode?.excludedFromMarkdown) tag.excludedFromMarkdown = true;
2626
+ state.lastTextNode = tag;
2627
+ handleEvent({
2628
+ type: 0,
2629
+ node: tag
2630
+ });
2631
+ const parentNode = tag;
2632
+ parentNode.currentWalkIndex = 0;
2633
+ state.currentNode = parentNode;
2634
+ state.hasEncodedHtmlEntity = false;
2635
+ if (result.selfClosing) {
2636
+ closeNode(tag, state, handleEvent);
2637
+ state.justClosedTag = true;
2638
+ } else state.justClosedTag = false;
2639
+ return {
2640
+ complete: true,
2641
+ newPosition: i,
2642
+ remainingText: "",
2643
+ selfClosing: result.selfClosing
2644
+ };
2645
+ }
2646
+ function setAttribute(attributes, rawName, rawValue) {
2647
+ if (!rawName) return attributes;
2648
+ const name = rawName.toLowerCase();
2649
+ if (Object.hasOwn(attributes, name)) return attributes;
2650
+ const result = attributes === EMPTY_ATTRIBUTES ? {} : attributes;
2651
+ result[name] = rawValue.includes("&") ? decodeHTMLEntities(rawValue, true) : rawValue;
2652
+ return result;
2653
+ }
2654
+ function scanAttributes(source, position, selfClosing, stopAtTagEnd) {
2655
+ const length = source.length;
2656
+ let attributes = EMPTY_ATTRIBUTES;
2657
+ let state = ATTRIBUTE_GAP;
2658
+ let nameStart = 0;
2659
+ let nameEnd = 0;
2660
+ let valueStart = 0;
2661
+ let quoteChar = 0;
2662
+ let newPosition = -1;
2663
+ let valueEnd = length;
2664
+ let i = position;
2665
+ while (i < length) {
2666
+ const charCode = source.charCodeAt(i);
2667
+ if (stopAtTagEnd && state !== ATTRIBUTE_QUOTED_VALUE) {
2668
+ if (state !== ATTRIBUTE_UNQUOTED_VALUE && charCode === SLASH_CHAR && i + 1 < length && source.charCodeAt(i + 1) === GT_CHAR) {
2669
+ selfClosing = true;
2670
+ valueEnd = i;
2671
+ newPosition = i + 2;
2672
+ break;
2673
+ }
2674
+ if (charCode === GT_CHAR) {
2675
+ valueEnd = i;
2676
+ newPosition = i + 1;
2677
+ break;
2678
+ }
2679
+ }
2680
+ const isSpace = isWhitespace(charCode);
2681
+ switch (state) {
2682
+ case ATTRIBUTE_GAP:
2683
+ if (!isSpace) {
2684
+ state = ATTRIBUTE_NAME;
2685
+ nameStart = i;
2686
+ }
2687
+ break;
2688
+ case ATTRIBUTE_NAME:
2689
+ if (charCode === EQUALS_CHAR || isSpace) {
2690
+ nameEnd = i;
2691
+ state = charCode === EQUALS_CHAR ? ATTRIBUTE_BEFORE_VALUE : ATTRIBUTE_AFTER_NAME;
2692
+ }
2693
+ break;
2694
+ case ATTRIBUTE_AFTER_NAME:
2695
+ if (charCode === EQUALS_CHAR) state = ATTRIBUTE_BEFORE_VALUE;
2696
+ else if (!isSpace) {
2697
+ attributes = setAttribute(attributes, source.substring(nameStart, nameEnd), "");
2698
+ state = ATTRIBUTE_NAME;
2699
+ nameStart = i;
2700
+ }
2701
+ break;
2702
+ case ATTRIBUTE_BEFORE_VALUE:
2703
+ if (charCode === QUOTE_CHAR || charCode === APOS_CHAR) {
2704
+ quoteChar = charCode;
2705
+ state = ATTRIBUTE_QUOTED_VALUE;
2706
+ valueStart = i + 1;
2707
+ } else if (!isSpace) {
2708
+ state = ATTRIBUTE_UNQUOTED_VALUE;
2709
+ valueStart = i;
2710
+ }
2711
+ break;
2712
+ case ATTRIBUTE_QUOTED_VALUE:
2713
+ if (charCode === quoteChar) {
2714
+ attributes = setAttribute(attributes, source.substring(nameStart, nameEnd), source.substring(valueStart, i));
2715
+ state = ATTRIBUTE_GAP;
2716
+ }
2717
+ break;
2718
+ case ATTRIBUTE_UNQUOTED_VALUE: if (isSpace || !stopAtTagEnd && charCode === GT_CHAR) {
2719
+ attributes = setAttribute(attributes, source.substring(nameStart, nameEnd), source.substring(valueStart, i));
2720
+ state = ATTRIBUTE_GAP;
2721
+ }
2722
+ }
2723
+ i++;
2724
+ }
2725
+ if (stopAtTagEnd && newPosition === -1) return {
2726
+ _tag: "incomplete",
2727
+ attrBuffer: source.substring(position)
2728
+ };
2729
+ switch (state) {
2730
+ case ATTRIBUTE_NAME:
2731
+ attributes = setAttribute(attributes, source.substring(nameStart, valueEnd), "");
2732
+ break;
2733
+ case ATTRIBUTE_AFTER_NAME:
2734
+ case ATTRIBUTE_BEFORE_VALUE:
2735
+ attributes = setAttribute(attributes, source.substring(nameStart, nameEnd), "");
2736
+ break;
2737
+ case ATTRIBUTE_QUOTED_VALUE:
2738
+ case ATTRIBUTE_UNQUOTED_VALUE: attributes = setAttribute(attributes, source.substring(nameStart, nameEnd), source.substring(valueStart, valueEnd));
2739
+ }
2740
+ return {
2741
+ _tag: "complete",
2742
+ newPosition: stopAtTagEnd ? newPosition : length,
2743
+ attributes,
2744
+ selfClosing
2745
+ };
2746
+ }
2747
+ function scanTagAttributes(htmlChunk, position, tagHandler) {
2748
+ return scanAttributes(htmlChunk, position, tagHandler?.isSelfClosing || false, true);
2749
+ }
2750
+ function parseAttributes(attrStr) {
2751
+ if (!attrStr) return EMPTY_ATTRIBUTES;
2752
+ const result = scanAttributes(attrStr, 0, false, false);
2753
+ if (result._tag === "incomplete") throw new Error("Isolated attribute scans always complete at EOF");
2754
+ return result.attributes === EMPTY_ATTRIBUTES ? {} : result.attributes;
2755
+ }
2756
+ export { blockOpenPrefix, breakHandler, buildTagOverrideHandlers, continuationPrefix, escapeHtml, figcaptionOwnsBlockSpacing, finalizeParse, getLanguageFromClass, isCharacterReferenceTail, isDataUrl, isEmptyLinkHref, isInsideHeading, isInsideTableCell, isSafeHtmlUrl, lastOutputChar, listMarkerLineStart, markRenderedChildContent, orderedItemNumber, parseAttributes, parseHtml, parseHtmlStream, parseUnsignedInteger, renderBreak, resolveUrl, safeAnchorOutput };