nuxt-ai-ready 2.5.3 → 3.0.0

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 (286) hide show
  1. package/README.md +13 -12
  2. package/dist/chunks/agent-skills.mjs +35 -12
  3. package/dist/chunks/prerender.mjs +35 -24
  4. package/dist/cli.mjs +5 -2
  5. package/dist/module.d.mts +4 -0
  6. package/dist/module.json +2 -2
  7. package/dist/module.mjs +8 -4
  8. package/dist/runtime/app/index.d.ts +3 -0
  9. package/dist/runtime/app/index.js +2 -0
  10. package/dist/runtime/cache-control.d.ts +2 -0
  11. package/dist/runtime/cache-control.js +11 -0
  12. package/dist/runtime/llms-txt-utils.js +1 -1
  13. package/dist/runtime/server/db/context.d.ts +13 -0
  14. package/dist/runtime/server/db/drizzle/client.d.ts +6 -7
  15. package/dist/runtime/server/db/drizzle/client.js +13 -2
  16. package/dist/runtime/server/db/drizzle/providers/bun.d.ts +2 -2
  17. package/dist/runtime/server/db/drizzle/providers/bun.js +2 -2
  18. package/dist/runtime/server/db/drizzle/providers/d1.d.ts +2 -2
  19. package/dist/runtime/server/db/drizzle/providers/d1.js +3 -2
  20. package/dist/runtime/server/db/drizzle/providers/libsql.d.ts +2 -2
  21. package/dist/runtime/server/db/drizzle/providers/libsql.js +2 -2
  22. package/dist/runtime/server/db/drizzle/providers/neon.d.ts +2 -2
  23. package/dist/runtime/server/db/drizzle/providers/neon.js +2 -2
  24. package/dist/runtime/server/db/drizzle/providers/node-sqlite.d.ts +2 -2
  25. package/dist/runtime/server/db/drizzle/providers/node-sqlite.js +2 -2
  26. package/dist/runtime/server/db/drizzle/providers/postgres.d.ts +2 -2
  27. package/dist/runtime/server/db/drizzle/providers/postgres.js +2 -2
  28. package/dist/runtime/server/db/drizzle/queries.d.ts +27 -27
  29. package/dist/runtime/server/db/drizzle/queries.js +6 -5
  30. package/dist/runtime/server/db/drizzle/raw.d.ts +2 -6
  31. package/dist/runtime/server/db/index.d.ts +1 -1
  32. package/dist/runtime/server/db/index.js +1 -1
  33. package/dist/runtime/server/db/queries.d.ts +36 -36
  34. package/dist/runtime/server/db/queries.js +8 -9
  35. package/dist/runtime/server/db/seed.d.ts +2 -2
  36. package/dist/runtime/server/db/seed.js +4 -3
  37. package/dist/runtime/server/db/shared.d.ts +8 -0
  38. package/dist/runtime/server/db/shared.js +8 -2
  39. package/dist/runtime/server/index.d.ts +2 -0
  40. package/dist/runtime/server/index.js +17 -0
  41. package/dist/runtime/server/mcp/tools/get-page-markdown.js +1 -1
  42. package/dist/runtime/server/mcp/tools/list-pages.js +1 -1
  43. package/dist/runtime/server/mcp/tools/search-pages.js +1 -1
  44. package/dist/runtime/server/middleware/markdown.prerender.js +1 -1
  45. package/dist/runtime/server/plugins/db-lifecycle-nitro3.d.ts +2 -0
  46. package/dist/runtime/server/plugins/db-lifecycle-nitro3.js +16 -0
  47. package/dist/runtime/server/plugins/html-capture.prerender.js +6 -4
  48. package/dist/runtime/server/plugins/link-header-nitro3.d.ts +2 -0
  49. package/dist/runtime/server/plugins/link-header-nitro3.js +20 -0
  50. package/dist/runtime/server/plugins/link-header.d.ts +6 -0
  51. package/dist/runtime/server/plugins/link-header.js +7 -11
  52. package/dist/runtime/server/plugins/markdown-negotiation.js +8 -1
  53. package/dist/runtime/server/plugins/sitemap-seeder.js +3 -3
  54. package/dist/runtime/server/routes/agent-skills-artifact.d.ts +1 -1
  55. package/dist/runtime/server/routes/agent-skills-artifact.js +10 -10
  56. package/dist/runtime/server/routes/agent-skills-index.d.ts +1 -1
  57. package/dist/runtime/server/routes/agent-skills-index.js +7 -6
  58. package/dist/runtime/server/routes/ai-catalog.d.ts +2 -1
  59. package/dist/runtime/server/routes/ai-catalog.js +7 -8
  60. package/dist/runtime/server/routes/api-catalog.d.ts +3 -1
  61. package/dist/runtime/server/routes/api-catalog.js +12 -12
  62. package/dist/runtime/server/routes/llms-full.txt.get.js +1 -1
  63. package/dist/runtime/server/routes/mcp-server-card.d.ts +1 -1
  64. package/dist/runtime/server/routes/mcp-server-card.js +7 -8
  65. package/dist/runtime/server/utils/checkStale.d.ts +2 -2
  66. package/dist/runtime/server/utils/cloudflare-prerendered.d.ts +3 -0
  67. package/dist/runtime/server/utils/cloudflare-prerendered.js +23 -0
  68. package/dist/runtime/server/utils/cloudflare.d.ts +5 -5
  69. package/dist/runtime/server/utils/cloudflare.js +31 -7
  70. package/dist/runtime/server/utils/content-negotiation.d.ts +5 -3
  71. package/dist/runtime/server/utils/content-negotiation.js +8 -7
  72. package/dist/runtime/server/utils/context.d.ts +3 -3
  73. package/dist/runtime/server/utils/context.js +1 -1
  74. package/dist/runtime/server/utils/discovery-response.d.ts +2 -0
  75. package/dist/runtime/server/utils/link-header.d.ts +5 -3
  76. package/dist/runtime/server/utils/link-header.js +26 -2
  77. package/dist/runtime/server/utils/markdown-request.d.ts +4 -3
  78. package/dist/runtime/server/utils/markdown-request.js +15 -13
  79. package/dist/runtime/server/utils/negotiation-decision.d.ts +4 -0
  80. package/dist/runtime/server/utils/negotiation-decision.js +6 -5
  81. package/dist/runtime/server/utils/negotiation-response.js +47 -22
  82. package/dist/runtime/server/utils/prerender-html.d.ts +2 -1
  83. package/dist/runtime/server/utils/prerender-html.js +3 -1
  84. package/dist/runtime/types.d.ts +15 -7
  85. package/dist/shared/nuxt-ai-ready.B3hAuOLQ.mjs +29 -0
  86. package/dist/shared/{nuxt-ai-ready.CLSWou20.mjs → nuxt-ai-ready.C34F0LJo.mjs} +560 -219
  87. package/package.json +85 -20
  88. package/skills/nuxt-ai-ready/SKILL.md +26 -12
  89. package/skills/nuxt-ai-ready/references/runtime-indexing.md +7 -6
  90. package/dist/runtime/server/db/drizzle/providers/sqlite.d.ts +0 -8
  91. package/dist/runtime/server/db/drizzle/providers/sqlite.js +0 -15
  92. package/node_modules/@mdream/js/LICENSE.md +0 -9
  93. package/node_modules/@mdream/js/README.md +0 -792
  94. package/node_modules/@mdream/js/bin/mdream.mjs +0 -2
  95. package/node_modules/@mdream/js/dist/_chunks/const.mjs +0 -134
  96. package/node_modules/@mdream/js/dist/_chunks/index.d.mts +0 -9
  97. package/node_modules/@mdream/js/dist/_chunks/markdown-processor.mjs +0 -1968
  98. package/node_modules/@mdream/js/dist/_chunks/minimal.d.mts +0 -6
  99. package/node_modules/@mdream/js/dist/_chunks/parse.mjs +0 -2756
  100. package/node_modules/@mdream/js/dist/_chunks/plugins.mjs +0 -725
  101. package/node_modules/@mdream/js/dist/_chunks/resolve-plugins.mjs +0 -44
  102. package/node_modules/@mdream/js/dist/_chunks/stream.mjs +0 -37
  103. package/node_modules/@mdream/js/dist/_chunks/types.d.mts +0 -473
  104. package/node_modules/@mdream/js/dist/cli.d.mts +0 -1
  105. package/node_modules/@mdream/js/dist/cli.mjs +0 -32
  106. package/node_modules/@mdream/js/dist/core.d.mts +0 -15
  107. package/node_modules/@mdream/js/dist/core.mjs +0 -28
  108. package/node_modules/@mdream/js/dist/index.d.mts +0 -4
  109. package/node_modules/@mdream/js/dist/index.mjs +0 -58
  110. package/node_modules/@mdream/js/dist/llms-txt.d.mts +0 -86
  111. package/node_modules/@mdream/js/dist/llms-txt.mjs +0 -308
  112. package/node_modules/@mdream/js/dist/negotiate.d.mts +0 -35
  113. package/node_modules/@mdream/js/dist/negotiate.mjs +0 -121
  114. package/node_modules/@mdream/js/dist/parse.d.mts +0 -90
  115. package/node_modules/@mdream/js/dist/parse.mjs +0 -2
  116. package/node_modules/@mdream/js/dist/plugins.d.mts +0 -85
  117. package/node_modules/@mdream/js/dist/plugins.mjs +0 -2
  118. package/node_modules/@mdream/js/dist/preset/minimal.d.mts +0 -2
  119. package/node_modules/@mdream/js/dist/preset/minimal.mjs +0 -33
  120. package/node_modules/@mdream/js/dist/splitter.d.mts +0 -18
  121. package/node_modules/@mdream/js/dist/splitter.mjs +0 -194
  122. package/node_modules/@mdream/js/package.json +0 -103
  123. package/node_modules/cac/LICENSE +0 -21
  124. package/node_modules/cac/README.md +0 -492
  125. package/node_modules/cac/dist/index.d.ts +0 -196
  126. package/node_modules/cac/dist/index.js +0 -638
  127. package/node_modules/cac/package.json +0 -72
  128. package/node_modules/mdream/LICENSE.md +0 -9
  129. package/node_modules/mdream/README.md +0 -1091
  130. package/node_modules/mdream/bin/mdream.mjs +0 -46
  131. package/node_modules/mdream/dist/browser.d.mts +0 -105
  132. package/node_modules/mdream/dist/browser.mjs +0 -262
  133. package/node_modules/mdream/dist/edge.d.mts +0 -100
  134. package/node_modules/mdream/dist/edge.mjs +0 -250
  135. package/node_modules/mdream/dist/iife.js +0 -605
  136. package/node_modules/mdream/dist/index.d.mts +0 -89
  137. package/node_modules/mdream/dist/index.mjs +0 -184
  138. package/node_modules/mdream/dist/wasm.d.mts +0 -100
  139. package/node_modules/mdream/dist/wasm.mjs +0 -140
  140. package/node_modules/mdream/dist/worker.d.mts +0 -101
  141. package/node_modules/mdream/dist/worker.mjs +0 -217
  142. package/node_modules/mdream/napi/index.d.mts +0 -127
  143. package/node_modules/mdream/napi/index.d.ts +0 -127
  144. package/node_modules/mdream/napi/index.mjs +0 -725
  145. package/node_modules/mdream/napi/rust.android-arm-eabi.node +0 -0
  146. package/node_modules/mdream/napi/rust.android-arm64.node +0 -0
  147. package/node_modules/mdream/napi/rust.darwin-arm64.node +0 -0
  148. package/node_modules/mdream/napi/rust.darwin-x64.node +0 -0
  149. package/node_modules/mdream/napi/rust.freebsd-x64.node +0 -0
  150. package/node_modules/mdream/napi/rust.linux-arm-gnueabihf.node +0 -0
  151. package/node_modules/mdream/napi/rust.linux-arm64-gnu.node +0 -0
  152. package/node_modules/mdream/napi/rust.linux-arm64-musl.node +0 -0
  153. package/node_modules/mdream/napi/rust.linux-x64-gnu.node +0 -0
  154. package/node_modules/mdream/napi/rust.linux-x64-musl.node +0 -0
  155. package/node_modules/mdream/napi/rust.wasi.cjs +0 -2144
  156. package/node_modules/mdream/napi/rust.wasm32-wasi.wasm +0 -0
  157. package/node_modules/mdream/napi/rust.win32-arm64-msvc.node +0 -0
  158. package/node_modules/mdream/napi/rust.win32-x64-msvc.node +0 -0
  159. package/node_modules/mdream/node_modules/@emnapi/core/LICENSE +0 -21
  160. package/node_modules/mdream/node_modules/@emnapi/core/README.md +0 -1
  161. package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.d.ts +0 -392
  162. package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.full.d.ts +0 -392
  163. package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.full.js +0 -8351
  164. package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.js +0 -7268
  165. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/async-work.d.ts +0 -5
  166. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/async-work.js +0 -843
  167. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/index.d.ts +0 -4
  168. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/index.js +0 -3
  169. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/threadsafe-function.d.ts +0 -5
  170. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/threadsafe-function.js +0 -1010
  171. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/v8.d.ts +0 -5
  172. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/v8.js +0 -1446
  173. package/node_modules/mdream/node_modules/@emnapi/core/node_modules/@emnapi/wasi-threads/LICENSE +0 -21
  174. package/node_modules/mdream/node_modules/@emnapi/core/node_modules/@emnapi/wasi-threads/README.md +0 -203
  175. package/node_modules/mdream/node_modules/@emnapi/core/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +0 -236
  176. package/node_modules/mdream/node_modules/@emnapi/core/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +0 -1086
  177. package/node_modules/mdream/node_modules/@emnapi/core/node_modules/@emnapi/wasi-threads/package.json +0 -35
  178. package/node_modules/mdream/node_modules/@emnapi/core/node_modules/@emnapi/wasi-threads/rollup.config.js +0 -6
  179. package/node_modules/mdream/node_modules/@emnapi/core/package.json +0 -39
  180. package/node_modules/mdream/node_modules/@emnapi/core/rollup.config.js +0 -60
  181. package/node_modules/mdream/node_modules/@emnapi/runtime/LICENSE +0 -21
  182. package/node_modules/mdream/node_modules/@emnapi/runtime/README.md +0 -1
  183. package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.d.ts +0 -833
  184. package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.js +0 -2306
  185. package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.js.map +0 -1
  186. package/node_modules/mdream/node_modules/@emnapi/runtime/index.cjs +0 -63
  187. package/node_modules/mdream/node_modules/@emnapi/runtime/package.json +0 -39
  188. package/node_modules/mdream/node_modules/@emnapi/runtime/rollup.config.js +0 -25
  189. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/LICENSE +0 -21
  190. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/README.md +0 -203
  191. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +0 -240
  192. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +0 -1118
  193. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/package.json +0 -35
  194. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/rollup.config.js +0 -6
  195. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.cjs +0 -1472
  196. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.js +0 -1470
  197. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/fs-proxy.cjs +0 -237
  198. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/fs.js +0 -17578
  199. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/fs-proxy.js +0 -317
  200. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/package.json +0 -67
  201. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/runtime.cjs +0 -39
  202. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/runtime.js +0 -36
  203. package/node_modules/mdream/node_modules/@tybys/wasm-util/LICENSE +0 -21
  204. package/node_modules/mdream/node_modules/@tybys/wasm-util/README.md +0 -193
  205. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/tsdoc-metadata.json +0 -11
  206. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.d.ts +0 -423
  207. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm-bundler.js +0 -2932
  208. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm.js +0 -2932
  209. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm.min.js +0 -1
  210. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.js +0 -2954
  211. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.min.js +0 -1
  212. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/asyncify.js +0 -158
  213. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/index.js +0 -13
  214. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/jspi.js +0 -46
  215. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/load.js +0 -97
  216. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/memory.js +0 -35
  217. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/error.js +0 -103
  218. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/fd.js +0 -268
  219. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/fs.js +0 -3
  220. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/index.js +0 -192
  221. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/path.js +0 -316
  222. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/preview1.js +0 -1599
  223. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/rights.js +0 -141
  224. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/types.js +0 -220
  225. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/util.js +0 -128
  226. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/webassembly.js +0 -13
  227. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/asyncify.mjs +0 -153
  228. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/index.mjs +0 -9
  229. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/jspi.mjs +0 -39
  230. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/load.mjs +0 -89
  231. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/memory.mjs +0 -28
  232. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/error.mjs +0 -97
  233. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/fd.mjs +0 -256
  234. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/fs.mjs +0 -1
  235. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/index.mjs +0 -186
  236. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/path.mjs +0 -310
  237. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/preview1.mjs +0 -1593
  238. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/rights.mjs +0 -135
  239. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/types.mjs +0 -216
  240. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/util.mjs +0 -113
  241. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/webassembly.mjs +0 -9
  242. package/node_modules/mdream/node_modules/@tybys/wasm-util/package.json +0 -58
  243. package/node_modules/mdream/node_modules/tslib/CopyrightNotice.txt +0 -15
  244. package/node_modules/mdream/node_modules/tslib/LICENSE.txt +0 -12
  245. package/node_modules/mdream/node_modules/tslib/README.md +0 -164
  246. package/node_modules/mdream/node_modules/tslib/SECURITY.md +0 -41
  247. package/node_modules/mdream/node_modules/tslib/modules/index.d.ts +0 -38
  248. package/node_modules/mdream/node_modules/tslib/modules/index.js +0 -70
  249. package/node_modules/mdream/node_modules/tslib/modules/package.json +0 -3
  250. package/node_modules/mdream/node_modules/tslib/package.json +0 -47
  251. package/node_modules/mdream/node_modules/tslib/tslib.d.ts +0 -460
  252. package/node_modules/mdream/node_modules/tslib/tslib.es6.html +0 -1
  253. package/node_modules/mdream/node_modules/tslib/tslib.es6.js +0 -402
  254. package/node_modules/mdream/node_modules/tslib/tslib.es6.mjs +0 -401
  255. package/node_modules/mdream/node_modules/tslib/tslib.html +0 -1
  256. package/node_modules/mdream/node_modules/tslib/tslib.js +0 -484
  257. package/node_modules/mdream/package.json +0 -110
  258. package/node_modules/mdream/skills/mdream/SKILL.md +0 -124
  259. package/node_modules/mdream/skills/mdream/references/runtimes.md +0 -49
  260. package/node_modules/mdream/wasm/mdream_edge.d.ts +0 -90
  261. package/node_modules/mdream/wasm/mdream_edge.js +0 -517
  262. package/node_modules/mdream/wasm/mdream_edge_bg.wasm +0 -0
  263. package/node_modules/mdream/wasm/mdream_edge_bg.wasm.d.ts +0 -20
  264. package/node_modules/mdream/wasm/package.json +0 -17
  265. package/node_modules/mdream/wasm-bundler/mdream_edge.d.ts +0 -45
  266. package/node_modules/mdream/wasm-bundler/mdream_edge.js +0 -13
  267. package/node_modules/mdream/wasm-bundler/mdream_edge_bg.js +0 -413
  268. package/node_modules/mdream/wasm-bundler/mdream_edge_bg.wasm +0 -0
  269. package/node_modules/mdream/wasm-bundler/mdream_edge_bg.wasm.d.ts +0 -20
  270. package/node_modules/mdream/wasm-bundler/package.json +0 -19
  271. package/node_modules/pathe/LICENSE +0 -70
  272. package/node_modules/pathe/README.md +0 -73
  273. package/node_modules/pathe/dist/index.cjs +0 -39
  274. package/node_modules/pathe/dist/index.d.cts +0 -47
  275. package/node_modules/pathe/dist/index.d.mts +0 -47
  276. package/node_modules/pathe/dist/index.d.ts +0 -47
  277. package/node_modules/pathe/dist/index.mjs +0 -19
  278. package/node_modules/pathe/dist/shared/pathe.BSlhyZSM.cjs +0 -266
  279. package/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs +0 -249
  280. package/node_modules/pathe/dist/utils.cjs +0 -82
  281. package/node_modules/pathe/dist/utils.d.cts +0 -32
  282. package/node_modules/pathe/dist/utils.d.mts +0 -32
  283. package/node_modules/pathe/dist/utils.d.ts +0 -32
  284. package/node_modules/pathe/dist/utils.mjs +0 -77
  285. package/node_modules/pathe/package.json +0 -61
  286. package/node_modules/pathe/utils.d.ts +0 -1
@@ -1,1968 +0,0 @@
1
- import { DEFAULT_BLOCK_SPACING, NO_SPACING, TagIdMap, isInsideRawHtmlBlock } from "./const.mjs";
2
- import { blockOpenPrefix, breakHandler, continuationPrefix, escapeHtml, figcaptionOwnsBlockSpacing, finalizeParse, getLanguageFromClass, isCharacterReferenceTail, isDataUrl, isEmptyLinkHref, isInsideHeading, isInsideTableCell, isSafeHtmlUrl, lastOutputChar, listMarkerLineStart, markRenderedChildContent, orderedItemNumber, parseHtmlStream, parseUnsignedInteger, renderBreak, resolveUrl, safeAnchorOutput } from "./parse.mjs";
3
- function resolveClean(clean) {
4
- if (clean === true) return {
5
- urls: true,
6
- fragments: true,
7
- emptyLinks: true,
8
- redundantLinks: true,
9
- selfLinkHeadings: true,
10
- emptyImages: true,
11
- emptyLinkText: true
12
- };
13
- if (clean === false) return {};
14
- return clean;
15
- }
16
- function parseLink(md, start) {
17
- const len = md.length;
18
- let j = start + 1;
19
- let depth = 1;
20
- while (j < len && depth > 0) {
21
- const c = md.charCodeAt(j);
22
- if (c === 91) depth++;
23
- else if (c === 93) depth--;
24
- j++;
25
- }
26
- if (depth !== 0) return null;
27
- const textEnd = j - 1;
28
- if (j >= len || md.charCodeAt(j) !== 40) return null;
29
- j++;
30
- const urlStart = j;
31
- let parenDepth = 1;
32
- while (j < len && parenDepth > 0) {
33
- const c = md.charCodeAt(j);
34
- if (c === 40) parenDepth++;
35
- else if (c === 41) parenDepth--;
36
- j++;
37
- }
38
- if (parenDepth !== 0) return null;
39
- const urlEnd = j - 1;
40
- return {
41
- text: md.slice(start + 1, textEnd),
42
- url: md.slice(urlStart, urlEnd),
43
- end: j
44
- };
45
- }
46
- function isEscaped(md, index) {
47
- const end = index;
48
- while (index > 0 && md.charCodeAt(index - 1) === 92) index--;
49
- return (end - index) % 2 !== 0;
50
- }
51
- function htmlTagEnd(md, start, lastGt) {
52
- if (start >= lastGt || isEscaped(md, start)) return -1;
53
- let i = start + 1;
54
- if (md.charCodeAt(i) === 47) i++;
55
- let code = md.charCodeAt(i);
56
- if (!(code >= 65 && code <= 90 || code >= 97 && code <= 122)) return -1;
57
- do {
58
- i++;
59
- code = md.charCodeAt(i);
60
- } while (code >= 65 && code <= 90 || code >= 97 && code <= 122 || code >= 48 && code <= 57 || code === 45);
61
- if (code !== 32 && code !== 9 && code !== 10 && code !== 13 && code !== 47 && code !== 62) return -1;
62
- let quote = 0;
63
- while (i < md.length) {
64
- code = md.charCodeAt(i);
65
- if (quote) {
66
- if (code === quote) quote = 0;
67
- } else if (code === 34 || code === 39) quote = code;
68
- else if (code === 62) return i + 1;
69
- else if (code === 60) return -1;
70
- i++;
71
- }
72
- return -1;
73
- }
74
- function slugify(text) {
75
- let slug = "";
76
- let lastWasDash = false;
77
- for (let i = 0; i < text.length; i++) {
78
- const c = text.charCodeAt(i);
79
- if (c >= 97 && c <= 122) {
80
- slug += text[i];
81
- lastWasDash = false;
82
- } else if (c >= 65 && c <= 90) {
83
- slug += String.fromCharCode(c + 32);
84
- lastWasDash = false;
85
- } else if (c >= 48 && c <= 57) {
86
- slug += text[i];
87
- lastWasDash = false;
88
- } else if (c === 95) {
89
- slug += "_";
90
- lastWasDash = false;
91
- } else if (c === 32 || c === 9 || c === 45) {
92
- if (!lastWasDash && slug.length > 0) {
93
- slug += "-";
94
- lastWasDash = true;
95
- }
96
- }
97
- }
98
- if (lastWasDash) slug = slug.slice(0, -1);
99
- return slug;
100
- }
101
- function stripHeadingFormatting(text) {
102
- let result = "";
103
- const len = text.length;
104
- const lastGt = text.lastIndexOf(">");
105
- let firstTickLength = 0;
106
- let firstTickLast = 0;
107
- let otherTickLasts;
108
- if (text.includes("`")) {
109
- let scan = 0;
110
- while (scan < len) {
111
- let code = text.charCodeAt(scan);
112
- if (code === 96) {
113
- const start = scan;
114
- do {
115
- scan++;
116
- code = text.charCodeAt(scan);
117
- } while (code === 96);
118
- const ticks = scan - start;
119
- if (firstTickLength === 0) {
120
- firstTickLength = ticks;
121
- firstTickLast = start;
122
- } else if (ticks === firstTickLength) firstTickLast = start;
123
- else {
124
- otherTickLasts ||= /* @__PURE__ */ new Map();
125
- otherTickLasts.set(ticks, start);
126
- }
127
- } else if (code === 60) {
128
- const tagEnd = htmlTagEnd(text, scan, lastGt);
129
- scan = tagEnd === -1 ? scan + 1 : tagEnd;
130
- } else scan++;
131
- }
132
- }
133
- let i = 0;
134
- let codeTicks = 0;
135
- while (i < len) {
136
- const c = text.charCodeAt(i);
137
- if (c === 96) {
138
- let end = i + 1;
139
- while (text.charCodeAt(end) === 96) end++;
140
- const ticks = end - i;
141
- if (codeTicks === 0) {
142
- if ((ticks === firstTickLength ? firstTickLast : otherTickLasts?.get(ticks) ?? i) > i) codeTicks = ticks;
143
- } else if (codeTicks === ticks) codeTicks = 0;
144
- i = end;
145
- continue;
146
- }
147
- if (codeTicks !== 0) {
148
- result += text[i];
149
- i++;
150
- continue;
151
- }
152
- if (c === 92 && i + 1 < len) {
153
- result += text[i + 1];
154
- i += 2;
155
- continue;
156
- }
157
- const tagEnd = c === 60 ? htmlTagEnd(text, i, lastGt) : -1;
158
- if (tagEnd !== -1) {
159
- i = tagEnd;
160
- continue;
161
- }
162
- if (c === 91) {
163
- const link = parseLink(text, i);
164
- if (link) {
165
- result += link.text;
166
- i = link.end;
167
- continue;
168
- }
169
- }
170
- if (c === 42 || c === 95 || c === 126) {
171
- i++;
172
- continue;
173
- }
174
- result += text[i];
175
- i++;
176
- }
177
- return result.trim();
178
- }
179
- function collectHeadingSlugs(md) {
180
- const slugs = /* @__PURE__ */ new Set();
181
- const len = md.length;
182
- let i = 0;
183
- while (i < len) {
184
- if (i === 0 || md.charCodeAt(i - 1) === 10) {
185
- let hashes = 0;
186
- let j = i;
187
- while (j < len && md.charCodeAt(j) === 35) {
188
- hashes++;
189
- j++;
190
- }
191
- if (hashes >= 1 && hashes <= 6 && j < len && md.charCodeAt(j) === 32) {
192
- j++;
193
- const lineEnd = md.indexOf("\n", j);
194
- const cleaned = stripHeadingFormatting(lineEnd === -1 ? md.slice(j) : md.slice(j, lineEnd));
195
- if (cleaned) slugs.add(slugify(cleaned));
196
- }
197
- }
198
- const nl = md.indexOf("\n", i);
199
- if (nl === -1) break;
200
- i = nl + 1;
201
- }
202
- return slugs;
203
- }
204
- function cleanFragments(md) {
205
- const slugs = collectHeadingSlugs(md);
206
- const len = md.length;
207
- const lastGt = md.lastIndexOf(">");
208
- let result = "";
209
- let i = 0;
210
- while (i < len) {
211
- const tagEnd = md.charCodeAt(i) === 60 ? htmlTagEnd(md, i, lastGt) : -1;
212
- if (tagEnd !== -1) {
213
- result += md.slice(i, tagEnd);
214
- i = tagEnd;
215
- continue;
216
- }
217
- if (md.charCodeAt(i) === 91) {
218
- const link = parseLink(md, i);
219
- if (link && link.url.charCodeAt(0) === 35 && link.url.length > 1) {
220
- const fragment = link.url.slice(1).split(" ")[0];
221
- if (slugs.size > 0 ? !slugs.has(fragment) : true) {
222
- result += link.text;
223
- i = link.end;
224
- continue;
225
- }
226
- }
227
- }
228
- result += md[i];
229
- i++;
230
- }
231
- return result;
232
- }
233
- function cleanEmptyLinks(md) {
234
- const len = md.length;
235
- const lastGt = md.lastIndexOf(">");
236
- let result = "";
237
- let i = 0;
238
- while (i < len) {
239
- const tagEnd = md.charCodeAt(i) === 60 ? htmlTagEnd(md, i, lastGt) : -1;
240
- if (tagEnd !== -1) {
241
- result += md.slice(i, tagEnd);
242
- i = tagEnd;
243
- continue;
244
- }
245
- if (md.charCodeAt(i) === 91) {
246
- const link = parseLink(md, i);
247
- if (link) {
248
- const url = link.url;
249
- if (isEmptyLinkHref(url)) {
250
- result += link.text;
251
- i = link.end;
252
- continue;
253
- }
254
- }
255
- }
256
- result += md[i];
257
- i++;
258
- }
259
- return result;
260
- }
261
- function isAutolinkUri(s) {
262
- if (!(s.startsWith("http://") || s.startsWith("https://") || s.startsWith("ftp://") || s.startsWith("mailto:"))) return false;
263
- for (let i = 0; i < s.length; i++) {
264
- const c = s.charCodeAt(i);
265
- if (c === 32 || c === 60 || c === 62 || c === 10 || c === 13 || c === 9) return false;
266
- }
267
- return true;
268
- }
269
- function cleanRedundantLinks(md) {
270
- const len = md.length;
271
- const lastGt = md.lastIndexOf(">");
272
- let result = "";
273
- let i = 0;
274
- while (i < len) {
275
- const code = md.charCodeAt(i);
276
- const tagEnd = code === 60 ? htmlTagEnd(md, i, lastGt) : -1;
277
- if (tagEnd !== -1) {
278
- result += md.slice(i, tagEnd);
279
- i = tagEnd;
280
- continue;
281
- }
282
- if (code === 91) {
283
- const link = parseLink(md, i);
284
- if (link && link.text === link.url) {
285
- result += link.text;
286
- i = link.end;
287
- continue;
288
- }
289
- } else if (code === 60 && !isEscaped(md, i)) {
290
- const close = md.indexOf(">", i + 1);
291
- if (close !== -1) {
292
- const inner = md.slice(i + 1, close);
293
- if (isAutolinkUri(inner)) {
294
- result += inner;
295
- i = close + 1;
296
- continue;
297
- }
298
- }
299
- }
300
- result += md[i];
301
- i++;
302
- }
303
- return result;
304
- }
305
- function cleanSelfLinkHeadings(md) {
306
- const len = md.length;
307
- const lastGt = md.lastIndexOf(">");
308
- let result = "";
309
- let i = 0;
310
- while (i < len) {
311
- const tagEnd = md.charCodeAt(i) === 60 ? htmlTagEnd(md, i, lastGt) : -1;
312
- if (tagEnd !== -1) {
313
- result += md.slice(i, tagEnd);
314
- i = tagEnd;
315
- continue;
316
- }
317
- if (i === 0 || md.charCodeAt(i - 1) === 10) {
318
- let hashes = 0;
319
- let j = i;
320
- while (j < len && md.charCodeAt(j) === 35) {
321
- hashes++;
322
- j++;
323
- }
324
- if (hashes >= 1 && hashes <= 6 && j < len && md.charCodeAt(j) === 32) {
325
- j++;
326
- if (j < len && md.charCodeAt(j) === 91) {
327
- const link = parseLink(md, j);
328
- if (link && link.url.charCodeAt(0) === 35) {
329
- result += md.slice(i, j);
330
- result += link.text;
331
- i = link.end;
332
- continue;
333
- }
334
- }
335
- }
336
- }
337
- result += md[i];
338
- i++;
339
- }
340
- return result;
341
- }
342
- function cleanEmptyImages(md) {
343
- const len = md.length;
344
- const lastGt = md.lastIndexOf(">");
345
- let result = "";
346
- let i = 0;
347
- while (i < len) {
348
- const tagEnd = md.charCodeAt(i) === 60 ? htmlTagEnd(md, i, lastGt) : -1;
349
- if (tagEnd !== -1) {
350
- result += md.slice(i, tagEnd);
351
- i = tagEnd;
352
- continue;
353
- }
354
- if (md.charCodeAt(i) === 33 && i + 1 < len && md.charCodeAt(i + 1) === 91) {
355
- let j = i + 2;
356
- const altStart = j;
357
- while (j < len && md.charCodeAt(j) !== 93) j++;
358
- if (j < len) {
359
- if (md.slice(altStart, j).trim().length === 0) {
360
- j++;
361
- if (j < len && md.charCodeAt(j) === 40) {
362
- let parenDepth = 1;
363
- j++;
364
- while (j < len && parenDepth > 0) {
365
- if (md.charCodeAt(j) === 40) parenDepth++;
366
- else if (md.charCodeAt(j) === 41) parenDepth--;
367
- j++;
368
- }
369
- i = j;
370
- continue;
371
- }
372
- }
373
- }
374
- }
375
- result += md[i];
376
- i++;
377
- }
378
- return result;
379
- }
380
- function cleanEmptyLinkText(md) {
381
- const len = md.length;
382
- const lastGt = md.lastIndexOf(">");
383
- let result = "";
384
- let i = 0;
385
- while (i < len) {
386
- const tagEnd = md.charCodeAt(i) === 60 ? htmlTagEnd(md, i, lastGt) : -1;
387
- if (tagEnd !== -1) {
388
- result += md.slice(i, tagEnd);
389
- i = tagEnd;
390
- continue;
391
- }
392
- if (md.charCodeAt(i) === 91) {
393
- const link = parseLink(md, i);
394
- if (link && link.text.trim().length === 0) {
395
- i = link.end;
396
- continue;
397
- }
398
- }
399
- result += md[i];
400
- i++;
401
- }
402
- return result;
403
- }
404
- function applyClean(md, opts) {
405
- if (opts.emptyImages) md = cleanEmptyImages(md);
406
- if (opts.emptyLinks) md = cleanEmptyLinks(md);
407
- if (opts.emptyLinkText) md = cleanEmptyLinkText(md);
408
- if (opts.redundantLinks) md = cleanRedundantLinks(md);
409
- if (opts.selfLinkHeadings) md = cleanSelfLinkHeadings(md);
410
- if (opts.fragments) md = cleanFragments(md);
411
- return md;
412
- }
413
- function createHtmlOutputState() {
414
- return { frames: [] };
415
- }
416
- function slugifyHeading(text) {
417
- return slugify(stripHeadingFormatting(text));
418
- }
419
- function tagName(node, tagId) {
420
- switch (tagId) {
421
- case 14:
422
- case 15: return "strong";
423
- case 16:
424
- case 17: return "em";
425
- case 18:
426
- case 110:
427
- case 111: return "del";
428
- }
429
- if (!(tagId === 2 || tagId === 3 || tagId >= 14 && tagId <= 26 || tagId >= 28 && tagId <= 33 || tagId >= 35 && tagId <= 39 || tagId === 41 || tagId >= 46 && tagId <= 47 || tagId >= 50 && tagId <= 51 || tagId >= 79 && tagId <= 83 || tagId >= 88 && tagId <= 93 || tagId >= 95 && tagId <= 102 || tagId >= 104 && tagId <= 107)) return;
430
- if (node.tagHandler?.aliasTagId === void 0) return node.name;
431
- for (const name in TagIdMap) if (TagIdMap[name] === tagId) return name;
432
- }
433
- function resolveTagId(node) {
434
- return node.tagHandler?.aliasTagId ?? node.tagId;
435
- }
436
- function resolveSafeUrl(url, options, image = false) {
437
- if (!isSafeHtmlUrl(url, image)) return;
438
- const resolved = resolveUrl(url, options.origin, options.clean);
439
- return isSafeHtmlUrl(resolved, image) ? resolved : void 0;
440
- }
441
- function safeAttributes(node, tagId) {
442
- const attributes = node.attributes;
443
- if (tagId === 33) {
444
- const start = parseUnsignedInteger(attributes.start);
445
- return start === void 0 ? "" : ` start="${start}"`;
446
- }
447
- if (tagId === 23) {
448
- const language = getLanguageFromClass(attributes.class);
449
- return language ? ` class="language-${escapeHtml(language, true)}"` : "";
450
- }
451
- if (tagId === 31 || tagId === 32) {
452
- let output = "";
453
- const colspan = parseUnsignedInteger(attributes.colspan);
454
- if (colspan !== void 0 && colspan > 0) output += ` colspan="${colspan}"`;
455
- if (tagId === 31) {
456
- const align = attributes.align?.toLowerCase();
457
- if (align === "left" || align === "center" || align === "right") output += ` align="${align}"`;
458
- }
459
- return output;
460
- }
461
- return "";
462
- }
463
- function append(state, output, value) {
464
- const frame = state.frames.at(-1);
465
- if (frame) frame.output += value;
466
- else output.push(value);
467
- }
468
- function processText(node, state, output) {
469
- if (node.excludedFromMarkdown || !node.value) return;
470
- for (let index = state.frames.length - 1; index >= 0; index--) {
471
- const frame = state.frames[index];
472
- if (frame._tag === 0) {
473
- frame.text += node.value;
474
- break;
475
- }
476
- }
477
- append(state, output, escapeHtml(node.value));
478
- }
479
- function closeFrame(state, output, frame) {
480
- state.frames.pop();
481
- if (frame._tag === 0) {
482
- const slug = slugifyHeading(frame.text);
483
- const id = slug ? ` id="${slug}"` : "";
484
- append(state, output, `<h${frame.level}${id}>${frame.output}</h${frame.level}>`);
485
- return;
486
- }
487
- append(state, output, `<pre tabindex="0"><code${frame.language ? ` class="language-${escapeHtml(frame.language, true)}"` : ""}>${frame.output}</code></pre>`);
488
- }
489
- function processHtmlOutputEvent(event, state, output, options) {
490
- const { node, type } = event;
491
- if (node.type === 2) {
492
- if (type === 0) processText(node, state, output);
493
- return;
494
- }
495
- if (node.type !== 1) return;
496
- const element = node;
497
- const tagId = resolveTagId(element);
498
- const frame = state.frames.at(-1);
499
- if (frame?._tag === 1) {
500
- if (type === 0 && tagId === 23 && !frame.language) frame.language = getLanguageFromClass(element.attributes.class);
501
- else if (type === 0 && tagId === 6) frame.output += "\n";
502
- else if (type !== 0 && tagId === 34 && element.depth === frame.depth) closeFrame(state, output, frame);
503
- return;
504
- }
505
- if (type === 0 && tagId !== void 0 && tagId >= 7 && tagId <= 12) {
506
- state.frames.push({
507
- _tag: 0,
508
- level: tagId - 7 + 1,
509
- output: "",
510
- text: ""
511
- });
512
- return;
513
- }
514
- if (type !== 0 && frame?._tag === 0 && tagId !== void 0 && tagId >= 7 && tagId <= 12) {
515
- closeFrame(state, output, frame);
516
- return;
517
- }
518
- if (type === 0 && tagId === 34) {
519
- state.frames.push({
520
- _tag: 1,
521
- depth: element.depth,
522
- language: getLanguageFromClass(element.attributes.class),
523
- output: ""
524
- });
525
- return;
526
- }
527
- if (tagId === 6) {
528
- if (type === 0) append(state, output, "<br>");
529
- return;
530
- }
531
- if (tagId === 13) {
532
- if (type === 0) append(state, output, "<hr>");
533
- return;
534
- }
535
- if (tagId === 27) {
536
- if (type === 0) {
537
- const src = element.attributes.src && resolveSafeUrl(element.attributes.src, options, true);
538
- if (src) {
539
- append(state, output, `<img src="${escapeHtml(src, true)}" alt="${escapeHtml(element.attributes.alt || "", true)}"${element.attributes.title === void 0 ? "" : ` title="${escapeHtml(element.attributes.title, true)}"`}>`);
540
- markRenderedChildContent(element);
541
- }
542
- }
543
- return;
544
- }
545
- if (tagId === 26) {
546
- const rendered = safeAnchorOutput(element, options, type === 0);
547
- if (rendered) append(state, output, rendered);
548
- return;
549
- }
550
- if (tagId === void 0) return;
551
- const name = tagName(element, tagId);
552
- if (!name) return;
553
- const attributes = safeAttributes(element, tagId);
554
- if (attributes === void 0) return;
555
- append(state, output, type === 0 ? `<${name}${attributes}>` : `</${name}>`);
556
- }
557
- function processPluginsForEvent(event, plugins, state, processEvent) {
558
- if (plugins?.length) {
559
- if (event.node.type === 1 && event.type === 0) {
560
- const element = event.node;
561
- for (const plugin of plugins) if (plugin.processAttributes) plugin.processAttributes(element, state);
562
- }
563
- let shouldSkip = false;
564
- for (const plugin of plugins) {
565
- const res = plugin.beforeNodeProcess?.(event, state);
566
- if (typeof res === "object") shouldSkip = res.skip;
567
- }
568
- if (shouldSkip) return true;
569
- if (event.node.type === 1) {
570
- const element = event.node;
571
- const fn = event.type === 0 ? "onNodeEnter" : "onNodeExit";
572
- const pluginOutputs = [];
573
- for (const plugin of plugins) if (plugin[fn]) {
574
- const result = plugin[fn](element, state);
575
- if (result) pluginOutputs.push(result);
576
- }
577
- if (pluginOutputs.length > 0) element.pluginOutput = [...element.pluginOutput || [], ...pluginOutputs];
578
- } else if (event.node.type === 2 && event.type === 0) {
579
- const textNode = event.node;
580
- for (const plugin of plugins) if (plugin.processTextNode) {
581
- const result = plugin.processTextNode(textNode, state);
582
- if (result) {
583
- if (result.skip) return true;
584
- textNode.value = result.content;
585
- }
586
- }
587
- }
588
- }
589
- processEvent(event);
590
- return false;
591
- }
592
- const INLINE_MARKER_TYPE = /* @__PURE__ */ new Uint8Array(113);
593
- const MARKER_TYPE_MASK = 7;
594
- const CAPTION_FRAME_SIZE = 4;
595
- const CAPTION_OPEN = 1;
596
- const CAPTION_INTERNAL_BREAK = 2;
597
- const CAPTION_DEFAULT_SPACING = -1;
598
- const CAPTION_NO_ANCHOR = -1;
599
- INLINE_MARKER_TYPE[14] = 1;
600
- INLINE_MARKER_TYPE[15] = 1;
601
- INLINE_MARKER_TYPE[91] = 1;
602
- INLINE_MARKER_TYPE[16] = 2;
603
- INLINE_MARKER_TYPE[17] = 2;
604
- INLINE_MARKER_TYPE[18] = 3;
605
- INLINE_MARKER_TYPE[110] = 3;
606
- INLINE_MARKER_TYPE[111] = 3;
607
- INLINE_MARKER_TYPE[90] = 4;
608
- INLINE_MARKER_TYPE[46] = 5;
609
- INLINE_MARKER_TYPE[23] = 5;
610
- INLINE_MARKER_TYPE[82] = 5;
611
- INLINE_MARKER_TYPE[92] = 5;
612
- INLINE_MARKER_TYPE[81] = 6;
613
- function suppressesFormattingInPre(tagId) {
614
- return tagId === 26 || tagId === 46 || tagId === 110 || tagId === 111 || tagId === 106 || tagId >= 14 && tagId <= 21 || tagId >= 79 && tagId <= 83 || tagId >= 89 && tagId <= 94;
615
- }
616
- function newlineRunBefore(buffer, index) {
617
- let run = 0;
618
- for (let i = index - 1; i >= 0; i--) {
619
- const fragment = buffer[i];
620
- for (let j = fragment.length - 1; j >= 0; j--) {
621
- if (fragment.charCodeAt(j) !== 10) return run;
622
- run++;
623
- }
624
- }
625
- return run;
626
- }
627
- function newlineRunBeforePrefix(buffer, index, prefix) {
628
- let fragment = index - 1;
629
- let offset = fragment >= 0 ? buffer[fragment].length : 0;
630
- for (let prefixIndex = prefix.length - 1; prefixIndex >= 0; prefixIndex--) {
631
- while (offset === 0) {
632
- if (--fragment < 0) return newlineRunBefore(buffer, index);
633
- offset = buffer[fragment].length;
634
- }
635
- if (buffer[fragment].charCodeAt(--offset) !== prefix.charCodeAt(prefixIndex)) return newlineRunBefore(buffer, index);
636
- }
637
- let run = 0;
638
- for (;;) {
639
- while (offset === 0) {
640
- if (--fragment < 0) return run;
641
- offset = buffer[fragment].length;
642
- }
643
- if (buffer[fragment].charCodeAt(--offset) !== 10) return run;
644
- run++;
645
- }
646
- }
647
- function recordItemMarker(state, index) {
648
- if (index !== 0 || newlineRunBefore(state.buffer, state.buffer.length - 1) !== 1) {
649
- state.emptyItemFragment = void 0;
650
- return;
651
- }
652
- state.emptyItemFragment = state.buffer.length - 1;
653
- }
654
- function resolveItemMarker(state, atExit, unresolvedCaptionFragment = -1) {
655
- const fragment = state.emptyItemFragment;
656
- if (fragment === void 0) return;
657
- const buffer = state.buffer;
658
- let first = -1;
659
- for (let i = fragment + 1; i < buffer.length && first === -1; i++) {
660
- const fragment = buffer[i];
661
- for (let j = 0; j < fragment.length; j++) {
662
- const code = fragment.charCodeAt(j);
663
- if (code !== 32) {
664
- first = code;
665
- break;
666
- }
667
- }
668
- }
669
- if (first === -1 && !atExit) return;
670
- if (!atExit && unresolvedCaptionFragment !== -1) {
671
- let captionOpensItem = true;
672
- for (let index = fragment + 1; index < unresolvedCaptionFragment; index++) if (hasNonWhitespace(buffer[index])) {
673
- captionOpensItem = false;
674
- break;
675
- }
676
- if (captionOpensItem) return;
677
- }
678
- state.emptyItemFragment = void 0;
679
- if (first !== -1 && first !== 10) return;
680
- buffer[fragment] = `\n${buffer[fragment]}`;
681
- }
682
- function updateListIndent(state, element, eventType) {
683
- if (element.tagId !== 25) return;
684
- if (isInsideTableCell(state)) return;
685
- if (eventType === 0) {
686
- const isOrdered = element.parent?.tagId === 33;
687
- const width = state.plainText ? 0 : isOrdered ? String(orderedItemNumber(element.parent, element.index)).length + 2 : 2;
688
- state.listIndentWidths.push(width);
689
- state.listIndent += " ".repeat(width);
690
- } else if (eventType === 1) {
691
- const width = state.listIndentWidths.pop() ?? 0;
692
- state.listIndent = state.listIndent.slice(0, state.listIndent.length - width);
693
- }
694
- }
695
- function needsSpacing(lastChar, firstChar, state) {
696
- if (" \n ".includes(lastChar) || " \n ".includes(firstChar)) return false;
697
- if (lastChar === "|" && firstChar === "<" && state && (state.depthMap[28] || 0) > 0) return true;
698
- return !"[(>*_`".includes(lastChar) && !"])<.,!?:;*_`".includes(firstChar);
699
- }
700
- function shouldAddSpacingBeforeText(lastChar, lastNode, textNode) {
701
- if (!lastChar || "\n [>".includes(lastChar)) return false;
702
- if (lastNode?.tagHandler?.isInline) return false;
703
- const firstChar = textNode.value[0];
704
- if (firstChar === " ") return false;
705
- if (firstChar && ".,!?:;_*`)]".includes(firstChar)) return false;
706
- return true;
707
- }
708
- function canWrapHere(depthMap) {
709
- if (depthMap[34] || depthMap[23] || depthMap[32] || depthMap[31]) return false;
710
- return !isInsideHeading(depthMap);
711
- }
712
- function foldPreLinesToBr(value) {
713
- let start = 0;
714
- while (start < value.length) {
715
- const c = value.charCodeAt(start);
716
- if (c !== 10 && c !== 13) break;
717
- start++;
718
- }
719
- let end = value.length;
720
- while (end > start) {
721
- const c = value.charCodeAt(end - 1);
722
- if (c !== 10 && c !== 13) break;
723
- end--;
724
- }
725
- let out = "";
726
- for (let i = start; i < end; i++) {
727
- const c = value.charCodeAt(i);
728
- if (c === 13) {
729
- out += "<br>";
730
- if (i + 1 < end && value.charCodeAt(i + 1) === 10) i++;
731
- } else if (c === 10) out += "<br>";
732
- else if (c === 38) out += "&amp;";
733
- else if (c === 60) out += "&lt;";
734
- else if (c === 62) out += "&gt;";
735
- else if (c === 124) out += "&#124;";
736
- else out += value[i];
737
- }
738
- return out;
739
- }
740
- function escapeRawHtmlText(value, depthMap, protectLinkText) {
741
- const inTable = Boolean(depthMap[28]);
742
- let escaped = "";
743
- let copiedUntil = 0;
744
- let index = 0;
745
- while (index < value.length) {
746
- const code = value.charCodeAt(index);
747
- let replacement;
748
- if (code === 38) replacement = "&amp;";
749
- else if (code === 60) replacement = "&lt;";
750
- else if (code === 62) replacement = "&gt;";
751
- else if (code === 10) replacement = "&#10;";
752
- else if (code === 13) replacement = "&#13;";
753
- else if (inTable && code === 124) replacement = "&#124;";
754
- else if (protectLinkText && code === 91) replacement = "&#91;";
755
- else if (protectLinkText && code === 93) replacement = "&#93;";
756
- if (replacement) {
757
- escaped += value.slice(copiedUntil, index) + replacement;
758
- copiedUntil = index + 1;
759
- }
760
- index++;
761
- }
762
- return copiedUntil === 0 ? value : escaped + value.slice(copiedUntil);
763
- }
764
- function resetBufferScanCursors(scan) {
765
- scan[1] = 0;
766
- scan[2] = 0;
767
- scan[3] = 0;
768
- scan[4] = 0;
769
- }
770
- function trackRawHtmlMarkdownContext(buffer, scan) {
771
- if (scan[0]) return true;
772
- let index = scan[1];
773
- if (index > buffer.length) index = 0;
774
- let previous = index > 0 ? buffer[index - 1].charCodeAt(buffer[index - 1].length - 1) : -1;
775
- for (; index < buffer.length; index++) {
776
- const fragment = buffer[index];
777
- if (!fragment) continue;
778
- if (fragment.includes("\n\n") || previous === 10 && fragment.charCodeAt(0) === 10) {
779
- scan[0] = true;
780
- break;
781
- }
782
- previous = fragment.charCodeAt(fragment.length - 1);
783
- }
784
- scan[1] = buffer.length;
785
- return scan[0];
786
- }
787
- function lineOpensRawHtmlBlock(buffer, scan) {
788
- let scanned = scan[2];
789
- if (scanned > buffer.length) {
790
- scanned = 0;
791
- scan[3] = 0;
792
- scan[4] = 0;
793
- }
794
- for (let index = scanned; index < buffer.length; index++) {
795
- const newline = buffer[index].lastIndexOf("\n");
796
- if (newline !== -1) {
797
- scan[3] = index;
798
- scan[4] = newline + 1;
799
- }
800
- }
801
- scan[2] = buffer.length;
802
- let spaces = 0;
803
- let offset = scan[4];
804
- for (let index = scan[3]; index < buffer.length; index++) {
805
- const fragment = buffer[index];
806
- while (offset < fragment.length) {
807
- const code = fragment.charCodeAt(offset);
808
- if (code !== 32) return code === 60;
809
- if (++spaces > 3) return false;
810
- offset++;
811
- }
812
- offset = 0;
813
- }
814
- return false;
815
- }
816
- function markdownLineIndent(buffer) {
817
- let spaces = 0;
818
- for (let fragmentIndex = buffer.length - 1; fragmentIndex >= 0; fragmentIndex--) {
819
- const fragment = buffer[fragmentIndex];
820
- for (let index = fragment.length - 1; index >= 0; index--) {
821
- const code = fragment.charCodeAt(index);
822
- if (code === 10) return spaces;
823
- if (code !== 32 || spaces === 3) return listMarkerLineStart(buffer, fragmentIndex, index) ? 0 : -1;
824
- spaces++;
825
- }
826
- }
827
- return spaces;
828
- }
829
- function isMarkdownMarkerWhitespace(code) {
830
- return code === 0 || code === 9 || code === 10 || code === 13 || code === 32;
831
- }
832
- function canStartGfmAngleConstruct(code) {
833
- return code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 33 || code === 47 || code === 63;
834
- }
835
- function isThematicBreak(value, start, marker) {
836
- let count = 0;
837
- for (let index = start; index < value.length; index++) {
838
- const code = value.charCodeAt(index);
839
- if (code === marker) count++;
840
- else if (code === 10 || code === 13) break;
841
- else if (code !== 32 && code !== 9) return false;
842
- }
843
- return count >= 3;
844
- }
845
- const GFM_TEXT_NATIVE_TRIGGER = /[\\*_~`[<\r\n]/;
846
- function mayNeedGfmTextEscape(value, buffer, depthMap) {
847
- if (value.search(GFM_TEXT_NATIVE_TRIGGER) !== -1) return true;
848
- if (depthMap[28] && value.includes("|") || depthMap[26] && value.includes("]") || depthMap[22] && value.includes(">")) return true;
849
- const first = value.charCodeAt(0);
850
- if (!" #+->".includes(value[0]) && !(first >= 48 && first <= 57)) return false;
851
- let lineIndent = markdownLineIndent(buffer);
852
- if (lineIndent < 0) return false;
853
- let index = 0;
854
- while (index < value.length && lineIndent < 3 && value.charCodeAt(index) === 32) {
855
- index++;
856
- lineIndent++;
857
- }
858
- if (index >= value.length) return false;
859
- const code = value.charCodeAt(index);
860
- return "#+->".includes(value[index]) || code >= 48 && code <= 57;
861
- }
862
- function escapeGfmText(value, buffer, depthMap) {
863
- const inTable = Boolean(depthMap[28]);
864
- const inLink = Boolean(depthMap[26]);
865
- const inBlockquote = Boolean(depthMap[22]);
866
- let lineIndent = markdownLineIndent(buffer);
867
- let orderedDigits = 0;
868
- let copiedUntil = 0;
869
- let escaped = "";
870
- for (let index = 0; index < value.length; index++) {
871
- const code = value.charCodeAt(index);
872
- const character = value[index];
873
- const next = index + 1 < value.length ? value.charCodeAt(index + 1) : 0;
874
- if (code === 92 && next === 38 && isCharacterReferenceTail(value, index + 2)) {
875
- lineIndent = -1;
876
- orderedDigits = 0;
877
- index++;
878
- continue;
879
- }
880
- if (inTable && (code === 10 || code === 13)) {
881
- escaped += value.slice(copiedUntil, index);
882
- escaped += code === 10 ? "&#10;" : "&#13;";
883
- copiedUntil = index + 1;
884
- continue;
885
- }
886
- let shouldEscape = "\\*_~`[".includes(character) || code === 93 && inLink || code === 124 && inTable || code === 62 && inBlockquote || code === 60 && canStartGfmAngleConstruct(value.charCodeAt(index + 1));
887
- if (!shouldEscape && lineIndent >= 0) {
888
- if (code === 35) {
889
- let end = index + 1;
890
- while (end < value.length && value.charCodeAt(end) === 35) end++;
891
- shouldEscape = end - index <= 6 && (end === value.length || isMarkdownMarkerWhitespace(value.charCodeAt(end)));
892
- } else if (code === 45 || code === 43) shouldEscape = index + 1 === value.length || isMarkdownMarkerWhitespace(value.charCodeAt(index + 1)) || code === 45 && isThematicBreak(value, index, code);
893
- else if (code === 62) shouldEscape = true;
894
- } else if (!shouldEscape && orderedDigits > 0 && (code === 46 || code === 41)) shouldEscape = index + 1 === value.length || isMarkdownMarkerWhitespace(value.charCodeAt(index + 1));
895
- if (shouldEscape) {
896
- escaped += value.slice(copiedUntil, index);
897
- escaped += `\\${character}`;
898
- copiedUntil = index + 1;
899
- }
900
- if (code === 10) {
901
- lineIndent = 0;
902
- orderedDigits = 0;
903
- } else if (lineIndent >= 0) {
904
- if (code === 32 && lineIndent < 3) lineIndent++;
905
- else {
906
- orderedDigits = code >= 48 && code <= 57 ? 1 : 0;
907
- lineIndent = -1;
908
- }
909
- } else if (orderedDigits > 0) {
910
- if (code >= 48 && code <= 57 && orderedDigits < 9) orderedDigits++;
911
- else orderedDigits = 0;
912
- }
913
- }
914
- return copiedUntil === 0 ? value : escaped + value.slice(copiedUntil);
915
- }
916
- function currentColumn(buffer) {
917
- let col = 0;
918
- for (let i = buffer.length - 1; i >= 0; i--) {
919
- const s = buffer[i];
920
- const nl = s.lastIndexOf("\n");
921
- if (nl >= 0) return col + [...s.slice(nl + 1)].length;
922
- col += [...s].length;
923
- }
924
- return col;
925
- }
926
- function wrapText(value, col, width, prefix) {
927
- const leading = value.charCodeAt(0) === 32;
928
- const trailing = value.charCodeAt(value.length - 1) === 32;
929
- const prefixLen = [...prefix].length;
930
- let out = "";
931
- let first = true;
932
- let i = 0;
933
- const len = value.length;
934
- while (i < len) {
935
- let next = value.indexOf(" ", i);
936
- if (next === -1) next = len;
937
- if (next > i) {
938
- const word = value.slice(i, next);
939
- const wordLen = [...word].length;
940
- const needSpace = first ? leading : true;
941
- if (needSpace && col > prefixLen && col + 1 + wordLen > width) {
942
- out += `\n${prefix}`;
943
- col = prefixLen;
944
- } else if (needSpace) {
945
- out += " ";
946
- col += 1;
947
- }
948
- out += word;
949
- col += wordLen;
950
- first = false;
951
- }
952
- i = next + 1;
953
- }
954
- if (trailing && out !== "" && !out.endsWith(" ") && !out.endsWith("\n")) out += " ";
955
- if (out === "" && (leading || trailing)) out = " ";
956
- return out;
957
- }
958
- function calculateNewLineConfig(node, depthMap, plainText) {
959
- const tagId = node.tagId;
960
- if (plainText && tagId === 106) return NO_SPACING;
961
- if (tagId !== 25 && (depthMap[25] || 0) > 0 || plainText && tagId !== 22 && (depthMap[22] || 0) > 0) {
962
- if (plainText && tagId === 34) return [1, 1];
963
- return NO_SPACING;
964
- }
965
- const isBlockElement = tagId !== void 0 && (tagId >= 7 && tagId <= 12 || tagId === 35 || tagId === 36 || tagId === 25 || tagId === 106);
966
- let currParent = node.parent;
967
- while (currParent) {
968
- if (currParent.tagHandler?.collapsesInnerWhiteSpace) {
969
- if (isBlockElement && currParent.tagId === 37) {
970
- currParent = currParent.parent;
971
- continue;
972
- }
973
- return NO_SPACING;
974
- }
975
- currParent = currParent.parent;
976
- }
977
- if (node.tagHandler?.spacing) return node.tagHandler?.spacing;
978
- if (tagId === -1) return NO_SPACING;
979
- return DEFAULT_BLOCK_SPACING;
980
- }
981
- function hasNonWhitespace(value) {
982
- for (let i = 0; i < value.length; i++) {
983
- const c = value.charCodeAt(i);
984
- if (c !== 32 && c !== 9 && c !== 10 && c !== 12 && c !== 13) return true;
985
- }
986
- return false;
987
- }
988
- function isAsciiWhitespace(code) {
989
- return code === 32 || code >= 9 && code <= 13;
990
- }
991
- function trimAsciiWhitespaceEnd(value) {
992
- let end = value.length;
993
- while (end > 0 && isAsciiWhitespace(value.charCodeAt(end - 1))) end--;
994
- return end === value.length ? value : value.slice(0, end);
995
- }
996
- function fragmentPosition(buffer, fragment) {
997
- let position = 0;
998
- for (let index = 0; index < fragment; index++) position += buffer[index].length;
999
- return position;
1000
- }
1001
- function trimBufferedWhitespacePosition(content, position) {
1002
- let end = Math.max(0, position);
1003
- while (end > 0) {
1004
- const code = content.charCodeAt(end - 1);
1005
- if (code !== 32 && code !== 10) break;
1006
- end--;
1007
- }
1008
- return end;
1009
- }
1010
- function dropEmptyMarker(buffer, packed, markerType) {
1011
- const idx = packed >> 3;
1012
- if ((packed & MARKER_TYPE_MASK) === markerType && idx < buffer.length) return dropEmptyLinkText(buffer, idx) ? idx : -1;
1013
- return -1;
1014
- }
1015
- function resetRetractedCaptionFrames(frames, count, fragment) {
1016
- if (!frames) return;
1017
- for (let index = 0; index < count; index++) {
1018
- const offset = index * CAPTION_FRAME_SIZE;
1019
- if (frames[offset + 3] >= fragment) {
1020
- frames[offset + 2] = frames[offset + 2] & -2;
1021
- frames[offset + 3] = CAPTION_NO_ANCHOR;
1022
- }
1023
- }
1024
- }
1025
- function dropEmptyLinkText(buffer, openFragment) {
1026
- for (let index = openFragment + 1; index < buffer.length; index++) if (hasNonWhitespace(buffer[index])) return false;
1027
- buffer.length = openFragment;
1028
- return true;
1029
- }
1030
- function restoreCaptionBreakFlags(frames, snapshot, count) {
1031
- if (!frames || !snapshot) return;
1032
- const end = Math.min(count, snapshot.length);
1033
- for (let index = 0; index < end; index++) {
1034
- const offset = index * CAPTION_FRAME_SIZE + 2;
1035
- frames[offset] = frames[offset] & -3 | snapshot[index];
1036
- }
1037
- }
1038
- function maxBacktickRun(value) {
1039
- let max = 0;
1040
- let run = 0;
1041
- for (let index = 0; index < value.length; index++) if (value.charCodeAt(index) === 96) {
1042
- run++;
1043
- if (run > max) max = run;
1044
- } else run = 0;
1045
- return max;
1046
- }
1047
- function maxLineLeadingRun(value, marker, indent) {
1048
- let max = 0;
1049
- let lineStart = 0;
1050
- while (lineStart <= value.length) {
1051
- let index = lineStart;
1052
- if (indent && value.startsWith(indent, index)) index += indent.length;
1053
- let spaces = 0;
1054
- while (spaces < 3 && value.charCodeAt(index) === 32) {
1055
- spaces++;
1056
- index++;
1057
- }
1058
- let run = 0;
1059
- while (value.charCodeAt(index + run) === marker) run++;
1060
- if (run > max) max = run;
1061
- const newline = value.indexOf("\n", lineStart);
1062
- if (newline === -1) break;
1063
- lineStart = newline + 1;
1064
- }
1065
- return max;
1066
- }
1067
- function finalizeCodeSpan(state, span) {
1068
- let content = state.buffer.slice(span.fragment + 1).join("");
1069
- if ((state.depthMap[28] || 0) > 0 && content.includes("|")) {
1070
- content = content.replaceAll("|", "\\|");
1071
- state.buffer.length = span.fragment + 1;
1072
- state.buffer.push(content);
1073
- }
1074
- const delimiter = "`".repeat(Math.max(1, maxBacktickRun(content) + 1));
1075
- const padded = content.startsWith("`") || content.endsWith("`");
1076
- state.buffer[span.fragment] = `${span.prefix}${delimiter}${padded ? " " : ""}`;
1077
- return `${padded ? " " : ""}${delimiter}`;
1078
- }
1079
- function startCodeFence(state, fragment, language, indent) {
1080
- state.codeFence = {
1081
- fragment,
1082
- markerOffset: state.buffer[fragment].lastIndexOf("```"),
1083
- indent,
1084
- language
1085
- };
1086
- state.onCodeFenceOpen?.(language);
1087
- }
1088
- function finalizeCodeFence(state) {
1089
- const fence = state.codeFence;
1090
- if (!fence) return;
1091
- state.codeFence = void 0;
1092
- const marker = fence.language.includes("`") ? "~" : "`";
1093
- const markerCode = marker.charCodeAt(0);
1094
- const content = state.buffer.slice(fence.fragment + 1).join("");
1095
- const delimiter = marker.repeat(Math.max(3, maxLineLeadingRun(content, markerCode, fence.indent) + 1));
1096
- const opening = state.buffer[fence.fragment];
1097
- state.buffer[fence.fragment] = `${opening.slice(0, fence.markerOffset)}${delimiter}${opening.slice(fence.markerOffset + 3)}`;
1098
- return delimiter;
1099
- }
1100
- function stripBlockquoteListIndent(line, listIndent) {
1101
- return listIndent && line.startsWith(listIndent) ? line.slice(listIndent.length) : line;
1102
- }
1103
- function finalizeBlockquote(state) {
1104
- const frame = state.blockquotes.pop();
1105
- if (!frame) return;
1106
- state.bufferedBlockquoteDepth = state.blockquotes.length;
1107
- const content = state.buffer.slice(frame.fragment).join("").replace(/[ \t\r\n]+$/, "");
1108
- const prefix = `${frame.listIndent}>`;
1109
- const quoted = content.split("\n").map((line) => {
1110
- const unindented = stripBlockquoteListIndent(line, frame.listIndent);
1111
- return unindented ? `${prefix} ${unindented}` : prefix;
1112
- }).join("\n");
1113
- state.buffer.splice(frame.fragment, state.buffer.length - frame.fragment, quoted);
1114
- state.lastContentCache = quoted;
1115
- }
1116
- function collapseNestedBlockquoteSeparator(buffer) {
1117
- if (newlineRunBefore(buffer, buffer.length) < 2) return;
1118
- const last = buffer.at(-1);
1119
- if (last.length === 1) buffer.pop();
1120
- else buffer[buffer.length - 1] = last.slice(0, -1);
1121
- }
1122
- function flushPreFence(state) {
1123
- if (state.plainText) {
1124
- state.preFencePending = false;
1125
- return;
1126
- }
1127
- state.preFencePending = false;
1128
- state.preFenceOpen = true;
1129
- const lang = state.preFenceLang || "";
1130
- const fence = (state.depthMap[25] || 0) > 0 ? `${blockOpenPrefix(state.buffer, state.listIndent) ?? ""}\`\`\`${lang}\n${state.listIndent}` : `\`\`\`${lang}\n`;
1131
- state.buffer.push(fence);
1132
- startCodeFence(state, state.buffer.length - 1, lang, state.listIndent);
1133
- state.lastContentCache = fence;
1134
- }
1135
- function consumePendingPreChild(state, node, eventType, beforeFlush) {
1136
- if (eventType !== 0) return false;
1137
- if (node.type === 1) {
1138
- const element = node;
1139
- if (element.tagId === 23 && element.parent?.tagId === 34) state.preFencePending = false;
1140
- else if (element.tagId !== 34 && element.tagId !== 106 && !suppressesFormattingInPre(element.tagId)) {
1141
- beforeFlush();
1142
- flushPreFence(state);
1143
- }
1144
- return false;
1145
- }
1146
- if (hasNonWhitespace(node.value)) {
1147
- beforeFlush();
1148
- flushPreFence(state);
1149
- return false;
1150
- }
1151
- return true;
1152
- }
1153
- function consumeGfmAction(action, state, lifecycle) {
1154
- switch (action._tag) {
1155
- case "BlockquoteEnter": return action.output;
1156
- case "BlockquoteExit":
1157
- finalizeBlockquote(state);
1158
- return;
1159
- case "PreEnter":
1160
- state.preFencePending = true;
1161
- state.preFenceOpen = false;
1162
- state.preFenceLang = action.language;
1163
- return;
1164
- case "PreExit": {
1165
- const fenceOpen = state.preFenceOpen;
1166
- state.preFencePending = false;
1167
- state.preFenceOpen = false;
1168
- if (!fenceOpen) return void 0;
1169
- const indent = state.listIndent;
1170
- const output = (state.depthMap[25] || 0) > 0 ? `\n${indent}\`\`\`\n\n${indent}` : `\n\`\`\``;
1171
- const delimiter = finalizeCodeFence(state);
1172
- return delimiter ? output.replace("```", delimiter) : output;
1173
- }
1174
- case "CodeSpanEnter": return action.output;
1175
- case "CodeSpanExit": {
1176
- const span = lifecycle.openCodeSpans.pop();
1177
- return span ? finalizeCodeSpan(state, span) : "`";
1178
- }
1179
- case "CodeFenceEnter":
1180
- state.preFencePending = false;
1181
- state.preFenceOpen = true;
1182
- return action.output;
1183
- }
1184
- }
1185
- function commitGfmAction(action, state, lifecycle, outputStart) {
1186
- switch (action._tag) {
1187
- case "BlockquoteEnter":
1188
- if (state.blockquotes.length > 0) collapseNestedBlockquoteSeparator(state.buffer);
1189
- state.blockquotes.push({
1190
- fragment: state.buffer.length,
1191
- listIndent: state.listIndent
1192
- });
1193
- state.bufferedBlockquoteDepth = state.blockquotes.length;
1194
- break;
1195
- case "CodeSpanEnter":
1196
- lifecycle.openCodeSpans.push({
1197
- fragment: outputStart,
1198
- prefix: action.output.slice(0, -1)
1199
- });
1200
- break;
1201
- case "CodeFenceEnter": {
1202
- const fenceFragment = state.buffer.findIndex((fragment, index) => index >= outputStart && fragment.includes("```"));
1203
- if (fenceFragment < 0) throw new Error("code fence opener missing from output");
1204
- startCodeFence(state, fenceFragment, action.language, state.listIndent);
1205
- break;
1206
- }
1207
- }
1208
- }
1209
- function getPlainTextOutput(node, eventType, state) {
1210
- const override = state.options?.plugins?.tagOverrides?.[node.name];
1211
- if (override && typeof override !== "string") {
1212
- const explicitOutput = eventType === 0 ? override.enter : override.exit;
1213
- if (explicitOutput !== void 0) return explicitOutput;
1214
- }
1215
- const tagId = node.tagId;
1216
- const depthMap = state.depthMap;
1217
- if (eventType === 0) {
1218
- if (tagId === 6) return "\n";
1219
- if (tagId === 35 && ((depthMap[22] || 0) > 0 || (depthMap[25] || 0) > 0 && !isInsideTableCell(state))) {
1220
- const lastEntry = state.buffer.at(-1);
1221
- const lastChar = lastEntry?.charAt(lastEntry.length - 1) || "";
1222
- if (lastChar && lastChar !== " " && lastChar !== "\n") return "\n\n";
1223
- }
1224
- if (tagId === 32 || tagId === 31) return (depthMap[28] || 0) > 1 || node.index === 0 ? "" : " ";
1225
- if (tagId === 27) {
1226
- const alt = node.attributes?.alt;
1227
- const clean = state.options?.clean;
1228
- if ((clean === true || clean != null && clean !== false && clean.emptyImages === true) && !(alt !== void 0 && alt.trim().length > 0)) return void 0;
1229
- const src = node.attributes?.src || "";
1230
- const output = alt !== void 0 ? alt || void 0 : node.attributes?.title || resolveUrl(isDataUrl(src) ? "" : src, state.options?.origin, state.options?.clean) || void 0;
1231
- if (output && hasNonWhitespace(output)) markRenderedChildContent(node);
1232
- return output;
1233
- }
1234
- if (tagId === 81) return "\"";
1235
- return;
1236
- }
1237
- if (tagId === 81) return "\"";
1238
- }
1239
- function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverrideHandlers) {
1240
- const outputFormat = options.format === "html" || options.format === "text" ? options.format : "markdown";
1241
- const plainText = outputFormat === "text";
1242
- const htmlState = outputFormat === "html" ? createHtmlOutputState() : void 0;
1243
- const state = {
1244
- options,
1245
- buffer: [],
1246
- depthMap: /* @__PURE__ */ new Uint16Array(113),
1247
- listIndent: "",
1248
- listIndentWidths: [],
1249
- blockquotes: [],
1250
- bufferedBlockquoteDepth: 0,
1251
- plainText,
1252
- emptyItemFragment: void 0
1253
- };
1254
- const bufferScan = [
1255
- false,
1256
- 0,
1257
- 0,
1258
- 0,
1259
- 0
1260
- ];
1261
- let inRawHtmlRegion = false;
1262
- const openMarkers = [];
1263
- let openMarkerCount = 0;
1264
- let captionFrames;
1265
- let captionFrameCount = 0;
1266
- let captionBoundary = 0;
1267
- let captionBoundarySpacing = 0;
1268
- let captionBreakRun = 0;
1269
- const gfmLifecycle = { openCodeSpans: [] };
1270
- let openLinkFragment = -1;
1271
- let openLinkCaptionBreakRun = 0;
1272
- let openLinkCaptionFlags;
1273
- const clean = options.clean;
1274
- const cleanEmptyLinkText = clean === true || clean !== null && typeof clean === "object" && clean.emptyLinkText === true;
1275
- let rawHtmlLink;
1276
- let lastYieldedLength = 0;
1277
- let hasYieldedContent = false;
1278
- let preserveLeadingWhitespace = false;
1279
- function captionNeedsPreparation() {
1280
- return captionBoundary !== 0 || captionFrameCount !== 0 && (captionFrames[(captionFrameCount - 1) * CAPTION_FRAME_SIZE + 2] & CAPTION_OPEN) === 0;
1281
- }
1282
- function pushCaptionFrame(element, handler) {
1283
- let enterSpacing = 0;
1284
- let exitSpacing = 0;
1285
- if (!state.depthMap[34] && figcaptionOwnsBlockSpacing(element, plainText)) {
1286
- const spacing = handler?.spacing;
1287
- if (spacing) {
1288
- enterSpacing = spacing[0];
1289
- exitSpacing = spacing[1];
1290
- } else {
1291
- enterSpacing = CAPTION_DEFAULT_SPACING;
1292
- exitSpacing = CAPTION_DEFAULT_SPACING;
1293
- }
1294
- }
1295
- const frames = captionFrames || (captionFrames = []);
1296
- const offset = captionFrameCount * CAPTION_FRAME_SIZE;
1297
- frames[offset] = enterSpacing;
1298
- frames[offset + 1] = exitSpacing;
1299
- frames[offset + 2] = 0;
1300
- frames[offset + 3] = CAPTION_NO_ANCHOR;
1301
- captionFrameCount++;
1302
- }
1303
- function captionSpacingPrefix(spacing, includeListIndent, beforeFragment) {
1304
- if (spacing === 0) return "";
1305
- if (spacing === CAPTION_DEFAULT_SPACING) spacing = DEFAULT_BLOCK_SPACING[0];
1306
- const indent = includeListIndent ? state.listIndent : "";
1307
- const blockPrefix = blockOpenPrefix(state.buffer, indent, beforeFragment);
1308
- const trailingNewLines = newlineRunBeforePrefix(state.buffer, beforeFragment, indent);
1309
- if (blockPrefix === void 0 && trailingNewLines === 0) return "";
1310
- const missingNewLines = Math.max(0, spacing - trailingNewLines);
1311
- const prefix = missingNewLines === 0 ? blockPrefix || "" : `${"\n".repeat(missingNewLines)}${indent}`;
1312
- if (!prefix) return "";
1313
- const lastIndex = beforeFragment - 1;
1314
- const last = state.buffer[lastIndex];
1315
- if (prefix.charCodeAt(0) === 10 && last?.endsWith(" ")) {
1316
- const trimmed = last.slice(0, -1);
1317
- state.buffer[lastIndex] = trimmed;
1318
- if (state.lastContentCache === last) state.lastContentCache = trimmed;
1319
- state.lastTextNode = void 0;
1320
- }
1321
- return prefix;
1322
- }
1323
- function appendCaptionSpacing(spacing, includeListIndent) {
1324
- const prefix = captionSpacingPrefix(spacing, includeListIndent, state.buffer.length);
1325
- if (!prefix) return false;
1326
- state.buffer.push(prefix);
1327
- state.lastContentCache = prefix;
1328
- state.pendingInlineWhitespace = false;
1329
- return true;
1330
- }
1331
- function prepareCaptionOutput(explicitTop, includeBoundaryListIndent = true) {
1332
- let changed = false;
1333
- if (captionBoundary === 1) changed = appendCaptionSpacing(captionBoundarySpacing, includeBoundaryListIndent);
1334
- const frames = captionFrames;
1335
- if (frames) for (let index = 0; index < captionFrameCount; index++) {
1336
- const offset = index * CAPTION_FRAME_SIZE;
1337
- let flags = frames[offset + 2];
1338
- if (flags & CAPTION_OPEN) continue;
1339
- const anchor = frames[offset + 3];
1340
- const beforeFragment = anchor === CAPTION_NO_ANCHOR ? state.buffer.length : anchor;
1341
- let opening = flags & CAPTION_INTERNAL_BREAK ? "" : captionSpacingPrefix(frames[offset], true, beforeFragment);
1342
- flags |= CAPTION_OPEN;
1343
- if (!plainText && (!explicitTop || index !== captionFrameCount - 1)) opening += "*";
1344
- if (opening) {
1345
- if (beforeFragment === state.buffer.length) {
1346
- state.buffer.push(opening);
1347
- state.lastContentCache = opening;
1348
- } else {
1349
- const anchored = state.buffer[beforeFragment];
1350
- const replacement = opening + anchored;
1351
- state.buffer[beforeFragment] = replacement;
1352
- const codeSpan = gfmLifecycle.openCodeSpans.at(-1);
1353
- if (codeSpan?.fragment === beforeFragment) codeSpan.prefix = opening + codeSpan.prefix;
1354
- if (state.lastContentCache === anchored) state.lastContentCache = replacement;
1355
- }
1356
- changed = true;
1357
- }
1358
- frames[offset + 2] = flags;
1359
- }
1360
- return changed;
1361
- }
1362
- function consumeCaptionTransition(isInlineElement, tagId) {
1363
- captionBoundary = isInlineElement && tagId !== 27 && tagId !== 6 ? 2 : 0;
1364
- }
1365
- function anchorPendingCaptions(fragment) {
1366
- const frames = captionFrames;
1367
- if (!frames) return;
1368
- for (let index = 0; index < captionFrameCount; index++) {
1369
- const offset = index * CAPTION_FRAME_SIZE;
1370
- if ((frames[offset + 2] & CAPTION_OPEN) === 0 && frames[offset + 3] === CAPTION_NO_ANCHOR) frames[offset + 3] = fragment;
1371
- }
1372
- }
1373
- function commitCaptionFrames() {
1374
- const frames = captionFrames;
1375
- if (!frames) return;
1376
- for (let index = 0; index < captionFrameCount; index++) {
1377
- const offset = index * CAPTION_FRAME_SIZE;
1378
- if (frames[offset + 2] & CAPTION_OPEN) frames[offset + 3] = CAPTION_NO_ANCHOR;
1379
- }
1380
- }
1381
- function flushCaptionBreakRun() {
1382
- if (captionBreakRun === 0) return false;
1383
- let index = state.buffer.length;
1384
- while (index !== 0) {
1385
- const value = state.buffer[--index];
1386
- let end = value.length;
1387
- while (end !== 0 && value.charCodeAt(end - 1) === 32) end--;
1388
- if (end === value.length) break;
1389
- if (end !== 0) {
1390
- state.buffer[index] = value.slice(0, end);
1391
- state.buffer.length = index + 1;
1392
- break;
1393
- }
1394
- state.buffer.length = index;
1395
- }
1396
- const output = plainText ? "\n".repeat(captionBreakRun) : ` \n${state.listIndent}`.repeat(captionBreakRun);
1397
- captionBreakRun = 0;
1398
- state.buffer.push(output);
1399
- state.lastContentCache = output;
1400
- return true;
1401
- }
1402
- function finishCaptionFrame() {
1403
- if (captionFrameCount === 0) return;
1404
- const offset = (captionFrameCount - 1) * CAPTION_FRAME_SIZE;
1405
- const frames = captionFrames;
1406
- const exitSpacing = frames[offset + 1];
1407
- const opened = (frames[offset + 2] & CAPTION_OPEN) !== 0;
1408
- const anchor = frames[offset + 3];
1409
- frames.length = offset;
1410
- captionFrameCount--;
1411
- if (opened) {
1412
- captionBoundary = exitSpacing === 0 ? 0 : 1;
1413
- captionBoundarySpacing = exitSpacing;
1414
- } else if (anchor !== CAPTION_NO_ANCHOR) {
1415
- state.buffer.length = anchor;
1416
- state.lastContentCache = state.buffer.at(-1);
1417
- state.lastTextNode = void 0;
1418
- } else if (captionBreakRun !== 0 && captionFrameCount === 0) captionBoundary = 2;
1419
- }
1420
- function processTextNode(textNode, lastNode, lastChar) {
1421
- if (textNode.value) {
1422
- if (textNode.excludedFromMarkdown) return;
1423
- const ownsCaptionSpace = captionNeedsPreparation();
1424
- if (ownsCaptionSpace) {
1425
- if (textNode.value.charCodeAt(0) === 32) textNode.value = textNode.value.slice(1);
1426
- if (!hasNonWhitespace(textNode.value)) return;
1427
- flushCaptionBreakRun();
1428
- prepareCaptionOutput(false);
1429
- commitCaptionFrames();
1430
- captionBoundary = 0;
1431
- }
1432
- if (state.pendingInlineWhitespace) {
1433
- if (!textNode.value.trim()) return;
1434
- if (lastChar && !" \n \r".includes(lastChar) && !" \n \r".includes(textNode.value[0] || "")) textNode.value = ` ${textNode.value}`;
1435
- state.pendingInlineWhitespace = false;
1436
- }
1437
- if (plainText && state.depthMap[34] && state.buffer.length === 0) preserveLeadingWhitespace = true;
1438
- if (textNode.value === " " && (lastChar === " " || lastChar === "\n" || lastChar === " " || lastChar === "\r")) return;
1439
- if (!ownsCaptionSpace && !(plainText && state.depthMap[34]) && shouldAddSpacingBeforeText(lastChar, lastNode, textNode)) textNode.value = ` ${textNode.value}`;
1440
- if ((state.depthMap[34] || 0) > 0 && (state.depthMap[25] || 0) > 0) {
1441
- const indent = state.listIndent;
1442
- let value = textNode.value.replace(/\n(?!\n|$)/g, `\n${indent}`);
1443
- if (lastChar === "\n" && value[0] && value[0] !== "\n") value = indent + value;
1444
- textNode.value = value;
1445
- }
1446
- if (state.depthMap[34] > 0 && isInsideTableCell(state)) textNode.value = foldPreLinesToBr(textNode.value);
1447
- const insideRawHtmlBlock = isInsideRawHtmlBlock(state.depthMap);
1448
- let rawHtmlMarkdown = false;
1449
- if (insideRawHtmlBlock) rawHtmlMarkdown = trackRawHtmlMarkdownContext(state.buffer, bufferScan);
1450
- if (!plainText && !state.depthMap[34] && insideRawHtmlBlock) {
1451
- let parent = rawHtmlLink ? textNode.parent : void 0;
1452
- while (parent && parent !== rawHtmlLink) parent = parent.parent;
1453
- textNode.value = escapeRawHtmlText(textNode.value, state.depthMap, rawHtmlLink !== void 0 && parent === rawHtmlLink);
1454
- }
1455
- if (!plainText && !state.depthMap[34] && !state.depthMap[23] && (!insideRawHtmlBlock || rawHtmlMarkdown) && mayNeedGfmTextEscape(textNode.value, state.buffer, state.depthMap) && (!insideRawHtmlBlock || !lineOpensRawHtmlBlock(state.buffer, bufferScan))) textNode.value = escapeGfmText(textNode.value, state.buffer, state.depthMap);
1456
- if (textNode.generatedMarkdown && textNode.value) textNode.value = `${textNode.generatedMarkdown.prefix}${textNode.value}${textNode.generatedMarkdown.suffix}`;
1457
- const wrapWidth = state.options?.wrapWidth;
1458
- if (wrapWidth && canWrapHere(state.depthMap)) {
1459
- const wrapped = wrapText(textNode.value, currentColumn(state.buffer), wrapWidth, continuationPrefix(textNode, state.listIndentWidths, state.blockquotes.length === 0));
1460
- state.buffer.push(wrapped);
1461
- state.lastContentCache = wrapped;
1462
- } else {
1463
- state.buffer.push(textNode.value);
1464
- state.lastContentCache = textNode.value;
1465
- }
1466
- if (openMarkerCount || openLinkFragment >= 0) {
1467
- const hasVisibleText = textNode.containsWhitespace === false || hasNonWhitespace(textNode.value);
1468
- if (openLinkFragment >= 0 && hasVisibleText) openLinkFragment = -openLinkFragment - 2;
1469
- if (openMarkerCount && hasVisibleText) {
1470
- openMarkerCount = 0;
1471
- commitCaptionFrames();
1472
- }
1473
- }
1474
- }
1475
- state.lastTextNode = textNode;
1476
- }
1477
- function processEvent(event) {
1478
- const { type: eventType, node } = event;
1479
- state.depth = node.depth;
1480
- if (node.type === 1 ? node.excludedFromMarkdown : node.parent?.excludedFromMarkdown) return;
1481
- if (htmlState) {
1482
- processHtmlOutputEvent(event, htmlState, state.buffer, options);
1483
- return;
1484
- }
1485
- if (state.listRulePending !== void 0) {
1486
- const isVisibleText = node.type === 2 && eventType === 0 && hasNonWhitespace(node.value);
1487
- const opensVisibleElement = node.type === 1 && eventType === 0 && !node.tagHandler?.excludesTextNodes;
1488
- if (isVisibleText || opensVisibleElement) {
1489
- const separator = blockOpenPrefix(state.buffer, state.listRulePending);
1490
- state.buffer.push(separator);
1491
- state.lastContentCache = separator;
1492
- state.listRulePending = void 0;
1493
- } else if (node.type === 1 && eventType === 1 && node.tagId === 25) state.listRulePending = void 0;
1494
- else if (node.type === 2) return;
1495
- }
1496
- const lastNode = state.lastNode;
1497
- state.lastNode = event.node;
1498
- const buff = state.buffer;
1499
- if (!plainText && state.preFencePending) {
1500
- const preparePendingPreFence = () => {
1501
- if (captionNeedsPreparation()) {
1502
- flushCaptionBreakRun();
1503
- prepareCaptionOutput(false);
1504
- captionBoundary = 0;
1505
- }
1506
- };
1507
- if (node.type === 1) {
1508
- const pendingElement = node;
1509
- const pendingHandler = pendingElement.tagHandler;
1510
- const literalOverride = eventType === 0 ? pendingHandler?.literalEnter : pendingHandler?.literalExit;
1511
- if (literalOverride && pendingElement.tagId === 23 && pendingElement.parent?.tagId === 34) state.preFenceLang = getLanguageFromClass(pendingElement.attributes?.class);
1512
- if (pendingElement.pluginOutput?.length || literalOverride) {
1513
- preparePendingPreFence();
1514
- flushPreFence(state);
1515
- } else if (consumePendingPreChild(state, node, eventType, preparePendingPreFence)) return;
1516
- } else if (consumePendingPreChild(state, node, eventType, preparePendingPreFence)) return;
1517
- }
1518
- let lastBuffEntry = buff.at(-1);
1519
- let lastChar = lastBuffEntry?.charAt(lastBuffEntry.length - 1) || "";
1520
- if (!lastChar && state.pendingInlineWhitespace && eventType === 0) {
1521
- const code = lastOutputChar(buff);
1522
- if (code !== -1) lastChar = String.fromCharCode(code);
1523
- }
1524
- if (node.type === 2 && eventType === 0) {
1525
- processTextNode(node, lastNode, lastChar);
1526
- return;
1527
- }
1528
- if (node.type !== 1) return;
1529
- const element = node;
1530
- const handler = node.tagHandler;
1531
- const tagId = element.tagId;
1532
- const insideRawHtmlRegion = isInsideRawHtmlBlock(state.depthMap);
1533
- if (insideRawHtmlRegion && !inRawHtmlRegion) {
1534
- bufferScan[0] = false;
1535
- bufferScan[1] = state.buffer.length;
1536
- inRawHtmlRegion = true;
1537
- }
1538
- if (eventType === 0 && handler === breakHandler && !element.pluginOutput?.length) {
1539
- const inPre = state.depthMap[34] !== 0;
1540
- let breakOutput = plainText ? "\n" : renderBreak(element, state);
1541
- if (captionBoundary !== 0 || captionFrameCount !== 0) {
1542
- const pendingCaption = captionFrameCount !== 0 && (captionFrames[(captionFrameCount - 1) * CAPTION_FRAME_SIZE + 2] & CAPTION_OPEN) === 0;
1543
- if (!inPre && breakOutput && !hasNonWhitespace(breakOutput) && buff.length === 0 && !hasYieldedContent && state.blockquotes.length === 0 && pendingCaption) breakOutput = void 0;
1544
- if (breakOutput && hasNonWhitespace(breakOutput) && captionNeedsPreparation()) {
1545
- flushCaptionBreakRun();
1546
- prepareCaptionOutput(false);
1547
- commitCaptionFrames();
1548
- consumeCaptionTransition(false, 6);
1549
- lastBuffEntry = buff.at(-1);
1550
- lastChar = lastBuffEntry?.charAt(lastBuffEntry.length - 1) || "";
1551
- }
1552
- }
1553
- if (plainText && !inPre) {
1554
- let trailingNewLines = captionBreakRun;
1555
- if (lastChar === "\n") {
1556
- trailingNewLines++;
1557
- if ((lastBuffEntry.length > 1 ? lastBuffEntry.charAt(lastBuffEntry.length - 2) : buff.length > 1 ? buff[buff.length - 2]?.at(-1) : void 0) === "\n") trailingNewLines++;
1558
- }
1559
- if (trailingNewLines >= 2) breakOutput = void 0;
1560
- }
1561
- if (state.pendingInlineWhitespace) state.pendingInlineWhitespace = false;
1562
- const lastFragment = state.lastContentCache;
1563
- const lastTextNode = state.lastTextNode;
1564
- if (lastFragment && lastTextNode?.containsWhitespace && typeof lastTextNode.value === "string") {
1565
- let parent = element.parent;
1566
- let parentInPre = false;
1567
- while (parent) {
1568
- if (parent.tagId === 34) {
1569
- parentInPre = true;
1570
- break;
1571
- }
1572
- parent = parent.parent;
1573
- }
1574
- if (!parentInPre || element.parent?.tagId === 34) {
1575
- if (breakOutput?.endsWith("\n") && !parentInPre) {
1576
- const trimmed = trimAsciiWhitespaceEnd(lastFragment);
1577
- if (trimmed.length !== lastFragment.length && buff.at(-1) === lastFragment) buff[buff.length - 1] = trimmed;
1578
- }
1579
- state.lastTextNode = void 0;
1580
- }
1581
- }
1582
- const pendingCaption = captionFrameCount !== 0 && (captionFrames[(captionFrameCount - 1) * CAPTION_FRAME_SIZE + 2] & CAPTION_OPEN) === 0;
1583
- if (breakOutput && pendingCaption && !hasNonWhitespace(breakOutput)) {
1584
- for (let index = 0; index < captionFrameCount; index++) {
1585
- const offset = index * CAPTION_FRAME_SIZE + 2;
1586
- if ((captionFrames[offset] & CAPTION_OPEN) === 0) captionFrames[offset] = captionFrames[offset] | CAPTION_INTERNAL_BREAK;
1587
- }
1588
- captionBreakRun++;
1589
- } else if (breakOutput) {
1590
- buff.push(breakOutput);
1591
- state.lastContentCache = breakOutput;
1592
- if (openMarkerCount && hasNonWhitespace(breakOutput)) openMarkerCount = 0;
1593
- }
1594
- return;
1595
- }
1596
- let output;
1597
- if (element.pluginOutput?.length) {
1598
- output = element.pluginOutput;
1599
- element.pluginOutput = void 0;
1600
- }
1601
- let captionBufferChanged = false;
1602
- const eventFn = eventType === 0 ? "enter" : "exit";
1603
- const isInlineElement = handler?.isInline === true;
1604
- let gfmAction;
1605
- let handlerOutput;
1606
- const suppressedInPre = !plainText && (state.depthMap[34] || 0) > 0 && suppressesFormattingInPre(tagId) && !(eventType === 0 ? handler?.literalEnter : handler?.literalExit);
1607
- if (!output && !suppressedInPre && handler?.[eventFn]) {
1608
- if (openLinkFragment >= 0 && eventType === 1 && tagId === 26) {
1609
- if (dropEmptyLinkText(buff, openLinkFragment)) {
1610
- if (captionFrameCount !== 0) {
1611
- captionBreakRun = openLinkCaptionBreakRun;
1612
- restoreCaptionBreakFlags(captionFrames, openLinkCaptionFlags, captionFrameCount);
1613
- resetRetractedCaptionFrames(captionFrames, captionFrameCount, openLinkFragment);
1614
- }
1615
- state.lastContentCache = buff.at(-1);
1616
- state.lastTextNode = void 0;
1617
- openLinkFragment = -1;
1618
- return;
1619
- }
1620
- }
1621
- const res = plainText ? getPlainTextOutput(element, eventType, state) : handler[eventFn]({
1622
- node: element,
1623
- state
1624
- });
1625
- if (typeof res === "string") {
1626
- if (res) {
1627
- output = [res];
1628
- handlerOutput = res;
1629
- }
1630
- } else if (res) {
1631
- gfmAction = res;
1632
- handlerOutput = consumeGfmAction(res, state, gfmLifecycle);
1633
- if (handlerOutput) output = [handlerOutput];
1634
- if (res._tag === "BlockquoteExit") captionBufferChanged = true;
1635
- }
1636
- }
1637
- if (captionBreakRun && !(tagId === 106 && eventType === 1) && output) {
1638
- flushCaptionBreakRun();
1639
- if (gfmAction?._tag !== "BlockquoteEnter") anchorPendingCaptions(state.buffer.length);
1640
- captionBufferChanged = true;
1641
- }
1642
- const captionEvent = tagId === 106;
1643
- let captionTransition = false;
1644
- if (captionEvent || captionBoundary !== 0 || captionFrameCount !== 0) {
1645
- const captionEnter = captionEvent && eventType === 0 && !state.depthMap[34];
1646
- const captionExit = captionEvent && eventType === 1 && !state.depthMap[34];
1647
- if (captionEnter) pushCaptionFrame(element, handler);
1648
- let dropBlockquoteOutput = false;
1649
- if (captionBoundary === 1 && eventType === 0 && tagId === 22) {
1650
- captionBufferChanged = appendCaptionSpacing(captionBoundarySpacing, false) || captionBufferChanged;
1651
- captionTransition = true;
1652
- captionBoundary = 0;
1653
- dropBlockquoteOutput = true;
1654
- output = void 0;
1655
- handlerOutput = void 0;
1656
- }
1657
- let meaningfulOutput = !dropBlockquoteOutput && output?.some(hasNonWhitespace) === true;
1658
- if (meaningfulOutput && handlerOutput !== void 0) {
1659
- const markerType = INLINE_MARKER_TYPE[tagId];
1660
- const literal = eventType === 0 ? handler?.literalEnter : handler?.literalExit;
1661
- if ((markerType || tagId === 26 && eventType === 0) && !literal) {
1662
- if (captionBoundary === 1) {
1663
- captionBufferChanged = appendCaptionSpacing(captionBoundarySpacing, true) || captionBufferChanged;
1664
- captionTransition = true;
1665
- captionBoundary = 2;
1666
- }
1667
- if (eventType === 0) {
1668
- anchorPendingCaptions(state.buffer.length);
1669
- captionTransition = true;
1670
- }
1671
- meaningfulOutput = false;
1672
- }
1673
- }
1674
- const defaultCaptionExit = captionExit && handlerOutput !== void 0 && !handler?.literalExit;
1675
- if (defaultCaptionExit) meaningfulOutput = false;
1676
- if (captionExit && captionFrameCount !== 0) {
1677
- const offset = (captionFrameCount - 1) * CAPTION_FRAME_SIZE;
1678
- const opened = (captionFrames[offset + 2] & CAPTION_OPEN) !== 0;
1679
- if (!opened && defaultCaptionExit) {
1680
- output = void 0;
1681
- handlerOutput = void 0;
1682
- } else if (meaningfulOutput && captionNeedsPreparation()) {
1683
- if (flushCaptionBreakRun()) captionBufferChanged = true;
1684
- captionBufferChanged = prepareCaptionOutput(false) || captionBufferChanged;
1685
- captionTransition = true;
1686
- consumeCaptionTransition(isInlineElement, tagId);
1687
- }
1688
- finishCaptionFrame();
1689
- if (!opened && flushCaptionBreakRun()) captionBufferChanged = true;
1690
- } else if (meaningfulOutput && captionNeedsPreparation()) {
1691
- captionBufferChanged = prepareCaptionOutput(captionEnter, tagId !== 25) || captionBufferChanged;
1692
- captionTransition = true;
1693
- consumeCaptionTransition(isInlineElement, tagId);
1694
- }
1695
- if (meaningfulOutput) commitCaptionFrames();
1696
- }
1697
- const lastFragment = state.lastContentCache;
1698
- if (captionBufferChanged) {
1699
- lastBuffEntry = buff.at(-1);
1700
- lastChar = lastBuffEntry?.charAt(lastBuffEntry.length - 1) || "";
1701
- }
1702
- const secondLastChar = lastBuffEntry && lastBuffEntry.length > 1 ? lastBuffEntry.charAt(lastBuffEntry.length - 2) : buff.length > 1 ? buff[buff.length - 2]?.at(-1) : void 0;
1703
- if (element.tagId === 26) {
1704
- if (eventType === 0) rawHtmlLink = insideRawHtmlRegion && handlerOutput !== void 0 && !handler?.literalExit ? element : void 0;
1705
- else rawHtmlLink = void 0;
1706
- }
1707
- let lastNewLines = 0;
1708
- if (lastChar === "\n") lastNewLines++;
1709
- if (secondLastChar === "\n") lastNewLines++;
1710
- if (eventType === 1 && openMarkerCount) {
1711
- const markerType = handlerOutput === void 0 ? 0 : INLINE_MARKER_TYPE[tagId];
1712
- if (markerType && (tagId !== 23 || !state.depthMap[34] && !isInsideRawHtmlBlock(state.depthMap)) && !handler?.literalExit) {
1713
- const idx = dropEmptyMarker(buff, openMarkers[--openMarkerCount], markerType);
1714
- if (idx >= 0) {
1715
- resetRetractedCaptionFrames(captionFrames, captionFrameCount, idx);
1716
- state.lastContentCache = idx > 0 ? buff[idx - 1] : void 0;
1717
- return;
1718
- }
1719
- openMarkerCount = 0;
1720
- }
1721
- }
1722
- if (tagId === 6 && !state.depthMap[34] && output?.length === 1 && output[0] === "\n" && lastChar === "\n" && secondLastChar === "\n") output = void 0;
1723
- const newLineConfig = suppressedInPre ? NO_SPACING : calculateNewLineConfig(node, state.depthMap, plainText);
1724
- const quoteAtStart = eventType === 0 && state.blockquotes.at(-1)?.fragment === state.buffer.length;
1725
- const configuredNewLines = quoteAtStart || captionEvent || captionTransition ? 0 : eventType === 1 && tagId === 13 && state.blockquotes.length > 0 ? Math.min(1, newLineConfig[eventType] || 0) : newLineConfig[eventType] || 0;
1726
- let effectiveLastNewLines = lastNewLines;
1727
- if (eventType === 1 && output) for (let i = output.length - 1; i >= 0; i--) {
1728
- const frag = output[i];
1729
- if (frag) {
1730
- if (frag.endsWith("```") || frag.endsWith("~~~")) effectiveLastNewLines = 0;
1731
- break;
1732
- }
1733
- }
1734
- let newLines = Math.max(0, configuredNewLines - effectiveLastNewLines);
1735
- if (newLines > 0 && buff.length === 0 && !hasYieldedContent) newLines = 0;
1736
- if (state.pendingInlineWhitespace) {
1737
- const firstOutput = output?.[0]?.[0] || "";
1738
- if (eventType === 0) {
1739
- if (!isInlineElement || tagId === 6 || newLines > 0 || firstOutput === "\n" || firstOutput === "\r") state.pendingInlineWhitespace = false;
1740
- else if (firstOutput) {
1741
- if (lastChar && !" \n \r".includes(lastChar) && !" \n \r".includes(firstOutput)) {
1742
- state.buffer.push(" ");
1743
- state.lastContentCache = " ";
1744
- lastChar = " ";
1745
- }
1746
- state.pendingInlineWhitespace = false;
1747
- }
1748
- } else if (!isInlineElement || newLines > 0) state.pendingInlineWhitespace = false;
1749
- }
1750
- if (newLines > 0) {
1751
- if (!buff.length && !captionEvent && !captionTransition) {
1752
- if (output) {
1753
- for (const fragment of output) if (fragment) {
1754
- state.buffer.push(fragment);
1755
- state.lastContentCache = fragment;
1756
- }
1757
- }
1758
- if (gfmAction) commitGfmAction(gfmAction, state, gfmLifecycle, state.buffer.length);
1759
- updateListIndent(state, element, eventType);
1760
- return;
1761
- }
1762
- const newlinesStr = "\n".repeat(newLines);
1763
- if (lastChar === " " && buff?.length) {
1764
- buff[buff.length - 1] = buff.at(-1).substring(0, buff.at(-1).length - 1);
1765
- state.lastTextNode = void 0;
1766
- }
1767
- if (eventType === 0) {
1768
- if (output) output.unshift(newlinesStr);
1769
- else output = [newlinesStr];
1770
- } else if (output) output.push(newlinesStr);
1771
- else output = [newlinesStr];
1772
- } else if (lastFragment && state.lastTextNode?.containsWhitespace && (!!node.parent || isInlineElement) && "value" in state.lastTextNode && typeof state.lastTextNode.value === "string") {
1773
- let parent = node.parent;
1774
- let parentInPre = false;
1775
- while (parent) {
1776
- if (parent.tagId === 34) {
1777
- parentInPre = true;
1778
- break;
1779
- }
1780
- parent = parent.parent;
1781
- }
1782
- if (!parentInPre || node.parent?.tagId === 34) {
1783
- const collapsesWhiteSpace = node.tagHandler?.collapsesInnerWhiteSpace;
1784
- const hasSpacing = node.tagHandler?.spacing && Array.isArray(node.tagHandler.spacing);
1785
- const isBlockElement = !isInlineElement && !collapsesWhiteSpace && configuredNewLines > 0;
1786
- if (!quoteAtStart && (tagId === 6 && output?.[0]?.endsWith("\n") && !parentInPre || (!isInlineElement || eventType === 1) && !isBlockElement && !(collapsesWhiteSpace && eventType === 0) && !(hasSpacing && eventType === 0))) {
1787
- const originalLength = lastFragment.length;
1788
- const trimmed = trimAsciiWhitespaceEnd(lastFragment);
1789
- if (originalLength - trimmed.length > 0) {
1790
- if (buff?.length && buff.at(-1) === lastFragment) buff[buff.length - 1] = trimmed;
1791
- if (eventType === 1 && isInlineElement) state.pendingInlineWhitespace = true;
1792
- }
1793
- }
1794
- state.lastTextNode = void 0;
1795
- }
1796
- }
1797
- if (!captionTransition && tagId !== 6 && output?.[0]?.[0] && eventType === 0 && !handler?.literalEnter && lastChar && needsSpacing(lastChar, output[0][0], state)) {
1798
- state.buffer.push(" ");
1799
- state.lastContentCache = " ";
1800
- }
1801
- let outputStart = state.buffer.length;
1802
- if (output) {
1803
- outputStart = state.buffer.length;
1804
- for (const fragment of output) if (fragment) {
1805
- state.buffer.push(fragment);
1806
- state.lastContentCache = fragment;
1807
- }
1808
- }
1809
- if (gfmAction) commitGfmAction(gfmAction, state, gfmLifecycle, outputStart);
1810
- if (tagId === 25 && !plainText && !isInsideTableCell(state)) {
1811
- if (eventType === 0) recordItemMarker(state, element.index);
1812
- else resolveItemMarker(state, true);
1813
- }
1814
- if (eventType === 0 && tagId === 26 && outputStart < buff.length && buff.at(-1) === "[") {
1815
- const fragment = buff.length - 1;
1816
- const cleanCaptionLink = captionFrameCount !== 0 && cleanEmptyLinkText;
1817
- openLinkFragment = cleanCaptionLink ? fragment : -fragment - 2;
1818
- if (cleanCaptionLink) {
1819
- openLinkCaptionBreakRun = captionBreakRun;
1820
- const snapshot = openLinkCaptionFlags?.length === captionFrameCount ? openLinkCaptionFlags : new Uint8Array(captionFrameCount);
1821
- for (let index = 0; index < captionFrameCount; index++) snapshot[index] = captionFrames[index * CAPTION_FRAME_SIZE + 2] & CAPTION_INTERNAL_BREAK;
1822
- openLinkCaptionFlags = snapshot;
1823
- }
1824
- }
1825
- if (eventType === 0 && handlerOutput !== void 0 && isInlineElement && !handler?.literalEnter) {
1826
- const markerType = INLINE_MARKER_TYPE[tagId];
1827
- if (markerType && (tagId !== 23 || !state.depthMap[34] && !isInsideRawHtmlBlock(state.depthMap)) && buff[buff.length - 1] === handlerOutput) openMarkers[openMarkerCount++] = buff.length - 1 << 3 | markerType;
1828
- else if (openMarkerCount && !(tagId === 26 && cleanEmptyLinkText) && hasNonWhitespace(handlerOutput)) {
1829
- openMarkerCount = 0;
1830
- commitCaptionFrames();
1831
- }
1832
- } else if (openMarkerCount && (eventType === 1 && handler?.literalExit || tagId !== -1 && !isInlineElement || output?.some(hasNonWhitespace))) openMarkerCount = 0;
1833
- if (eventType === 1 && tagId === 26) openLinkFragment = -1;
1834
- updateListIndent(state, element, eventType);
1835
- if (!insideRawHtmlRegion && inRawHtmlRegion) {
1836
- bufferScan[0] = false;
1837
- bufferScan[1] = state.buffer.length;
1838
- inRawHtmlRegion = false;
1839
- }
1840
- }
1841
- function processHtml(html) {
1842
- const parseState = {
1843
- depthMap: state.depthMap,
1844
- depth: 0,
1845
- resolvedPlugins,
1846
- tagOverrideHandlers,
1847
- plainText: outputFormat !== "markdown"
1848
- };
1849
- const handleEvent = resolvedPlugins.length ? (event) => processPluginsForEvent(event, resolvedPlugins, state, processEvent) : processEvent;
1850
- const leftover = parseHtmlStream(html, parseState, handleEvent);
1851
- finalizeParse(leftover, parseState, handleEvent);
1852
- }
1853
- function getMarkdown() {
1854
- const content = state.buffer.join("");
1855
- if (htmlState) {
1856
- state.buffer.length = 0;
1857
- return content;
1858
- }
1859
- const result = plainText && preserveLeadingWhitespace ? content : content.trimStart();
1860
- state.buffer.length = 0;
1861
- preserveLeadingWhitespace = false;
1862
- return result.trimEnd();
1863
- }
1864
- function getMarkdownChunk() {
1865
- if (htmlState) {
1866
- const chunk = state.buffer.join("");
1867
- state.buffer.length = 0;
1868
- return chunk;
1869
- }
1870
- let unresolvedCaptionFragment = -1;
1871
- if (state.emptyItemFragment !== void 0 && captionFrames) for (let index = 0; index < captionFrameCount; index++) {
1872
- const offset = index * CAPTION_FRAME_SIZE;
1873
- const anchor = captionFrames[offset + 3];
1874
- if (anchor !== CAPTION_NO_ANCHOR) {
1875
- unresolvedCaptionFragment = anchor;
1876
- break;
1877
- }
1878
- }
1879
- resolveItemMarker(state, false, unresolvedCaptionFragment);
1880
- const content = state.buffer.join("");
1881
- const currentContent = hasYieldedContent || plainText && preserveLeadingWhitespace ? content : content.trimStart();
1882
- const inPre = state.depthMap[34] !== 0;
1883
- let stableLength = currentContent.length;
1884
- let retainMutableFragments = false;
1885
- if (inPre) {
1886
- const trailingCode = currentContent.charCodeAt(stableLength - 1);
1887
- while (stableLength > 0 && currentContent.charCodeAt(stableLength - 1) === 32) stableLength--;
1888
- retainMutableFragments = stableLength < currentContent.length;
1889
- if (state.lastTextNode?.containsWhitespace && isAsciiWhitespace(trailingCode)) {
1890
- stableLength = trimAsciiWhitespaceEnd(currentContent).length;
1891
- retainMutableFragments = stableLength < currentContent.length;
1892
- } else if (stableLength < currentContent.length) {
1893
- if (!(stableLength === 0 || currentContent.charCodeAt(stableLength - 1) === 10)) {
1894
- stableLength = currentContent.length;
1895
- retainMutableFragments = false;
1896
- }
1897
- }
1898
- } else {
1899
- while (stableLength > 0) {
1900
- const code = currentContent.charCodeAt(stableLength - 1);
1901
- if (code !== 32 && code !== 10) break;
1902
- stableLength--;
1903
- }
1904
- retainMutableFragments = stableLength < currentContent.length;
1905
- }
1906
- const leadingTrimmed = content.length - currentContent.length;
1907
- let heldFragment = Math.min(openMarkerCount ? openMarkers[0] >> 3 : Infinity, gfmLifecycle.openCodeSpans[0]?.fragment ?? Infinity, state.emptyItemFragment ?? Infinity, state.codeFence?.fragment ?? Infinity, state.blockquotes[0]?.fragment ?? Infinity, openLinkFragment === -1 ? Infinity : openLinkFragment < -1 ? -openLinkFragment - 2 : openLinkFragment);
1908
- for (let index = 0; index < captionFrameCount; index++) {
1909
- const offset = index * CAPTION_FRAME_SIZE;
1910
- const anchor = captionFrames[offset + 3];
1911
- if ((captionFrames[offset + 2] & CAPTION_OPEN) === 0 && anchor !== CAPTION_NO_ANCHOR) {
1912
- heldFragment = Math.min(heldFragment, anchor);
1913
- break;
1914
- }
1915
- }
1916
- const fragmentHeld = heldFragment !== Infinity;
1917
- if (fragmentHeld) stableLength = Math.min(stableLength, trimBufferedWhitespacePosition(currentContent, fragmentPosition(state.buffer, heldFragment) - leadingTrimmed));
1918
- const headingHeld = isInsideHeading(state.depthMap);
1919
- if (headingHeld) {
1920
- let headingPos = currentContent.length;
1921
- while (headingPos > 0) {
1922
- const code = currentContent.charCodeAt(headingPos - 1);
1923
- if (code !== 35 && code !== 32 && code !== 9) break;
1924
- headingPos--;
1925
- }
1926
- if (headingPos < stableLength) stableLength = headingPos;
1927
- }
1928
- if (stableLength < lastYieldedLength) stableLength = lastYieldedLength;
1929
- const newContent = currentContent.slice(lastYieldedLength, stableLength);
1930
- lastYieldedLength = stableLength;
1931
- if (newContent) hasYieldedContent = true;
1932
- if (!fragmentHeld && !headingHeld && (!retainMutableFragments || !inPre)) {
1933
- if (!resolvedPlugins.length && !options.wrapWidth) {
1934
- if (retainMutableFragments && leadingTrimmed === 0) {
1935
- const lastFragment = state.buffer.at(-1);
1936
- const fragmentStart = currentContent.length - lastFragment.length;
1937
- const tailStart = Math.max(0, Math.min(stableLength - 2, fragmentStart));
1938
- const emittedTail = currentContent.slice(tailStart, fragmentStart);
1939
- state.buffer.length = 0;
1940
- resetBufferScanCursors(bufferScan);
1941
- if (emittedTail) state.buffer.push(emittedTail);
1942
- state.buffer.push(lastFragment);
1943
- lastYieldedLength = stableLength - tailStart;
1944
- } else if (!retainMutableFragments) {
1945
- const tailStart = Math.max(0, stableLength - 2);
1946
- const emittedTail = currentContent.slice(tailStart, stableLength);
1947
- state.buffer.length = 0;
1948
- resetBufferScanCursors(bufferScan);
1949
- if (emittedTail) state.buffer.push(emittedTail);
1950
- lastYieldedLength = emittedTail.length;
1951
- }
1952
- } else if (!retainMutableFragments && state.buffer.length > 1) {
1953
- state.buffer.length = 0;
1954
- resetBufferScanCursors(bufferScan);
1955
- state.buffer.push(currentContent);
1956
- }
1957
- }
1958
- return newContent;
1959
- }
1960
- return {
1961
- processEvent,
1962
- processHtml,
1963
- getMarkdown,
1964
- getMarkdownChunk,
1965
- state
1966
- };
1967
- }
1968
- export { applyClean, createMarkdownProcessor, processPluginsForEvent, resolveClean };