volute 0.53.0 → 0.55.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 (210) hide show
  1. package/dist/{activity-events-LQII6PZS.js → activity-events-TFAJBNBW.js} +2 -2
  2. package/dist/{ai-service-YW5SWCSB.js → ai-service-KEK2V3AP.js} +2 -2
  3. package/dist/{auth-KRDSM55Q.js → auth-Y27LTNZK.js} +3 -3
  4. package/dist/auto-upgrade-2MZF7NG3.js +46 -0
  5. package/dist/{avatar-image-52WGXLHV.js → avatar-image-SN576P45.js} +2 -2
  6. package/dist/{backup-WWXVIMYQ.js → backup-GDCWH6MC.js} +12 -12
  7. package/dist/channels-AFJWGX7W.js +203 -0
  8. package/dist/{chat-WK2BLM7B.js → chat-HVPOZK3O.js} +9 -9
  9. package/dist/{chunk-QUSMYGNQ.js → chunk-2674KIGI.js} +1 -0
  10. package/dist/chunk-2GATCSZK.js +520 -0
  11. package/dist/{chunk-P2TBUKLW.js → chunk-3SFKY4GI.js} +4 -4
  12. package/dist/{chunk-RMADJFA7.js → chunk-45QTYKQQ.js} +4 -4
  13. package/dist/{chunk-TAWRJ24T.js → chunk-4VAQKLMU.js} +8 -5
  14. package/dist/{chunk-OXWUEU5V.js → chunk-5U5GLZSD.js} +2 -2
  15. package/dist/{chunk-TPX6E6PL.js → chunk-6HBGUPBA.js} +2 -2
  16. package/dist/{chunk-UFTDRTCP.js → chunk-7AA4T2RT.js} +2 -2
  17. package/dist/{chunk-LN7XJ56R.js → chunk-7XKPG66D.js} +9 -9
  18. package/dist/{chunk-VDZ4I4ZP.js → chunk-BP2X5AIK.js} +8 -14
  19. package/dist/{chunk-PIZDPY4G.js → chunk-CKOA4LWV.js} +12 -12
  20. package/dist/{chunk-6NLW72HP.js → chunk-CKPAVQNK.js} +1 -1
  21. package/dist/{chunk-IQ7VNWH6.js → chunk-DUV4EMNW.js} +37 -3
  22. package/dist/{chunk-CV6BNGFK.js → chunk-FSXPPOPM.js} +3 -3
  23. package/dist/{chunk-UTKUO2KY.js → chunk-FZUPIS3T.js} +3 -3
  24. package/dist/{chunk-L7BKTZ5U.js → chunk-G3XAB4DK.js} +1 -1
  25. package/dist/{chunk-23UJGVYP.js → chunk-HLWQ3P3R.js} +50 -46
  26. package/dist/{chunk-AP2KQMMW.js → chunk-HTSWDOJE.js} +11 -14
  27. package/dist/{chunk-EDR47UE2.js → chunk-IR2FW4W7.js} +2 -2
  28. package/dist/{chunk-ICXY54ZC.js → chunk-IT4GEFDH.js} +1 -1
  29. package/dist/{chunk-F6D766VQ.js → chunk-KS62IHE2.js} +1 -1
  30. package/dist/{chunk-LNNI3MS4.js → chunk-MNKPAAQF.js} +9 -2
  31. package/dist/{chunk-HASADR3E.js → chunk-NCRG4SBR.js} +241 -66
  32. package/dist/{chunk-I7U5EEZC.js → chunk-NM5FDH4T.js} +1 -1
  33. package/dist/{chunk-7LT3YZUR.js → chunk-OFU6WJJZ.js} +1 -1
  34. package/dist/{chunk-M77B73VV.js → chunk-OIOW3FPT.js} +7 -2
  35. package/dist/{chunk-BDHKCLWK.js → chunk-OKM67ZWH.js} +1 -1
  36. package/dist/chunk-OUGD5L5U.js +918 -0
  37. package/dist/{chunk-X67BDDZR.js → chunk-P3GXOT2X.js} +48 -2
  38. package/dist/{chunk-U54PJPTB.js → chunk-PRZUBJ4K.js} +1 -1
  39. package/dist/{chunk-UO4MZQNO.js → chunk-QVS3C4DK.js} +15 -7
  40. package/dist/{chunk-RQRO6PC7.js → chunk-TMTAHKYP.js} +324 -48
  41. package/dist/{chunk-5DBGQBQR.js → chunk-UEZC5MNB.js} +29 -18
  42. package/dist/{chunk-7ARONCZW.js → chunk-VTFXZPC3.js} +13 -13
  43. package/dist/{chunk-UDZLPR34.js → chunk-W3OIPJPB.js} +14 -9
  44. package/dist/{chunk-HTB7KDRU.js → chunk-WZZCA23D.js} +5 -4
  45. package/dist/{chunk-5Y54AE3L.js → chunk-XAG53RWY.js} +1 -1
  46. package/dist/{chunk-HTRSSOHY.js → chunk-YU5EYQAE.js} +1 -1
  47. package/dist/{chunk-5N32EN4O.js → chunk-Z4Q6TQWL.js} +1 -1
  48. package/dist/{chunk-EGV6R6UF.js → chunk-Z7TNIIHW.js} +3 -1
  49. package/dist/cli.js +19 -19
  50. package/dist/{clock-SH4NQC2F.js → clock-X7V3C7NL.js} +3 -3
  51. package/dist/{cloud-sync-MJVJ33LD.js → cloud-sync-FM73SVFJ.js} +21 -21
  52. package/dist/{conversations-ZL6PHROD.js → conversations-FH3ODBL7.js} +3 -3
  53. package/dist/{create-G2RIKQYK.js → create-P75ZFTVN.js} +1 -1
  54. package/dist/{daemon-restart-BIGU4OKS.js → daemon-restart-JQMMMITM.js} +4 -4
  55. package/dist/daemon.js +469 -857
  56. package/dist/db-JH3NTERX.js +36 -0
  57. package/dist/delivery-manager-H23Q23N7.js +41 -0
  58. package/dist/{delivery-notices-65TB3CBX.js → delivery-notices-S7TKOACE.js} +5 -5
  59. package/dist/{delivery-router-RHANNTAC.js → delivery-router-KHBVEVVL.js} +4 -2
  60. package/dist/{down-QSNEMTTX.js → down-UN2EDX2Y.js} +3 -3
  61. package/dist/echo-text-ULEIFJJF.js +40 -0
  62. package/dist/{exec-ABD3DYA2.js → exec-Z34TTUO3.js} +1 -1
  63. package/dist/extensions-QD22GXZD.js +74 -0
  64. package/dist/{files-CHPNEQXN.js → files-DUGRXN6V.js} +5 -5
  65. package/dist/{import-DB2KULRO.js → import-RDDUGGFI.js} +3 -3
  66. package/dist/{isolation-GVV2IBAU.js → isolation-UQPDO34R.js} +1 -1
  67. package/dist/message-delivery-LU4EP244.js +46 -0
  68. package/dist/migrate-init-infrastructure-Z72UJ5NT.js +44 -0
  69. package/dist/migrate-name-placeholder-64AEAWPE.js +37 -0
  70. package/dist/{migrate-thread-config-EQSEP2XG.js → migrate-thread-config-SVF2M3D3.js} +1 -1
  71. package/dist/{mind-IX5AWUST.js → mind-BARCLI7O.js} +14 -14
  72. package/dist/{mind-activity-tracker-QF6DCX2X.js → mind-activity-tracker-UT23RGBF.js} +3 -3
  73. package/dist/{mind-contacts-BKUOUJPV.js → mind-contacts-PEXCDRXA.js} +8 -8
  74. package/dist/{mind-list-KNU34SUD.js → mind-list-7KBLPLES.js} +2 -2
  75. package/dist/mind-service-ZJCUBAUL.js +48 -0
  76. package/dist/{mind-sleep-D3DEYAWG.js → mind-sleep-24HV4RCA.js} +5 -5
  77. package/dist/{mind-status-BPTLQ5Z6.js → mind-status-4YW4PHMO.js} +6 -3
  78. package/dist/{package-BN5KMU54.js → package-AUDBDKAO.js} +12 -14
  79. package/dist/{prompts-HNKGCAEY.js → prompts-MOBF3TMO.js} +1 -1
  80. package/dist/{sandbox-NNWCTHRI.js → sandbox-VI7XWBIA.js} +2 -2
  81. package/dist/scheduler-GLINVC2B.js +27 -0
  82. package/dist/{seed-LHZ33UB4.js → seed-5JGR7ZRA.js} +1 -1
  83. package/dist/{seed-cmd-U4RVJ3UA.js → seed-cmd-M6A7N7F3.js} +2 -2
  84. package/dist/{seed-create-OQU4KNCB.js → seed-create-TGFZW4IO.js} +3 -3
  85. package/dist/{seed-readiness-WJYYRRCK.js → seed-readiness-XBH2MUNA.js} +2 -2
  86. package/dist/{seed-sprout-SFUYH2RG.js → seed-sprout-3IC5ZVTI.js} +11 -11
  87. package/dist/{send-FWZAMDBN.js → send-DHYBAYK4.js} +11 -11
  88. package/dist/{service-XQPMZAGI.js → service-T4P5W6RS.js} +2 -2
  89. package/dist/{service-install-2EWD7KXD.js → service-install-R4SNYUVO.js} +3 -3
  90. package/dist/{setup-RVSGCIF3.js → setup-6KAH3GRW.js} +4 -4
  91. package/dist/skills/dreaming/SKILL.md +2 -2
  92. package/dist/skills/dreaming/references/INSTALL.md +1 -1
  93. package/dist/skills/tending/SKILL.md +2 -0
  94. package/dist/skills/volute-mind/SKILL.md +8 -0
  95. package/dist/skills/volute-mind/references/integrations.md +3 -2
  96. package/dist/skills/volute-mind/references/routing.md +18 -5
  97. package/dist/{skills-QRPU6BWY.js → skills-LKQCYFVP.js} +3 -3
  98. package/dist/sleep-manager-Q3ITFNOJ.js +42 -0
  99. package/dist/{spirit-I5ECLGRI.js → spirit-FKXMGO3N.js} +8 -6
  100. package/dist/spirit-availability-5R2WYSWF.js +43 -0
  101. package/dist/{sprout-A2PMEF7Z.js → sprout-VEW3CUNX.js} +1 -1
  102. package/dist/src-246GSX7A.js +519 -0
  103. package/dist/src-LOUB3WPR.js +4189 -0
  104. package/dist/{status-EYG4A3OK.js → status-LCKTTIWS.js} +5 -5
  105. package/dist/{system-events-YTOU66QI.js → system-events-ZYOCYAO2.js} +5 -3
  106. package/dist/{systems-2DIJY4RF.js → systems-HL7SGSW7.js} +6 -6
  107. package/dist/{tailscale-KHNZFC7L.js → tailscale-F2IMBILZ.js} +1 -1
  108. package/dist/{template-hash-YKWMVYMM.js → template-hash-RJRMF6DT.js} +2 -2
  109. package/dist/{template-staleness-PY2CULH6.js → template-staleness-IBD722PN.js} +4 -4
  110. package/dist/{turn-tracker-NNHS6MAR.js → turn-tracker-BE34OI6O.js} +7 -7
  111. package/dist/{up-UGBHH743.js → up-J47J5JRB.js} +3 -3
  112. package/dist/{update-CIWI2JYA.js → update-ILCPVNDD.js} +2 -2
  113. package/dist/{upgrade-LIE46UBB.js → upgrade-XY2J7NWZ.js} +9 -1
  114. package/dist/variant-cleanup-JGJZ5KB4.js +24 -0
  115. package/dist/{version-notify-SJVAQLZI.js → version-notify-KIXYNHJC.js} +28 -13
  116. package/dist/web-assets/assets/{index-b7G7ZsVk.js → index-CoU1eUKE.js} +25 -25
  117. package/dist/web-assets/assets/index-hPn_fkz3.css +1 -0
  118. package/dist/web-assets/index.html +2 -2
  119. package/package.json +12 -14
  120. package/packages/extensions/intentions/dist/ui/assets/index-3FneLCKR.css +1 -0
  121. package/packages/extensions/intentions/dist/ui/assets/index-Bl5KEcli.js +67 -0
  122. package/packages/extensions/{notes → intentions}/dist/ui/index.html +3 -3
  123. package/packages/extensions/intentions/skills/intention-review/SKILL.md +38 -0
  124. package/packages/extensions/intentions/skills/intentions/SKILL.md +49 -0
  125. package/packages/extensions/intentions/skills/intentions/scripts/intentions-hook.sh +45 -0
  126. package/packages/extensions/pages/dist/ui/assets/index-BKxVQkA9.css +1 -0
  127. package/packages/extensions/pages/dist/ui/assets/index-BMt6sStP.js +68 -0
  128. package/packages/extensions/pages/dist/ui/index.html +2 -2
  129. package/packages/extensions/pages/skills/commons-gardening/SKILL.md +50 -0
  130. package/packages/extensions/pages/skills/pages/SKILL.md +140 -16
  131. package/templates/_base/.init/.config/prompts.json +2 -3
  132. package/templates/{pi → _base}/.init/.config/routes.json +1 -0
  133. package/templates/_base/.init/.local/hooks/pre-prompt/turn-context.ts +30 -0
  134. package/templates/_base/.init/memory/dreams/.gitkeep +0 -0
  135. package/templates/_base/home/.config/routes.json +1 -1
  136. package/templates/_base/home/VOLUTE.md +1 -1
  137. package/templates/_base/src/lib/codex-session-seed.ts +6 -55
  138. package/templates/_base/src/lib/context-breakdown.ts +11 -3
  139. package/templates/_base/src/lib/pi-session-seed.ts +8 -57
  140. package/templates/_base/src/lib/routing.ts +2 -2
  141. package/templates/_base/src/lib/seed-note.ts +4 -4
  142. package/templates/_base/src/lib/session-seed.ts +8 -53
  143. package/templates/_base/src/lib/startup.ts +4 -22
  144. package/templates/claude/.init/CLAUDE.md +4 -0
  145. package/templates/claude/package.json +2 -2
  146. package/templates/claude/src/agent.ts +60 -112
  147. package/templates/claude/src/lib/hooks/pre-compact.ts +6 -6
  148. package/templates/claude/src/lib/message-channel.ts +43 -15
  149. package/templates/claude/src/lib/recover.ts +69 -0
  150. package/templates/claude/src/lib/stream-consumer.ts +23 -5
  151. package/templates/claude/src/server.ts +0 -1
  152. package/templates/claude/volute-template.json +1 -1
  153. package/templates/codex/.init/AGENTS.md +4 -0
  154. package/templates/codex/package.json +2 -2
  155. package/templates/codex/src/agent.ts +23 -89
  156. package/templates/codex/volute-template.json +1 -1
  157. package/templates/pi/.init/MINDS.md +4 -0
  158. package/templates/pi/package.json +1 -1
  159. package/templates/pi/src/agent.ts +26 -93
  160. package/templates/pi/src/lib/mechanics-doc.ts +30 -0
  161. package/templates/pi/src/server.ts +3 -2
  162. package/templates/pi/volute-template.json +1 -1
  163. package/dist/channels-LW5ZLMSQ.js +0 -90
  164. package/dist/chunk-R772ET2M.js +0 -164
  165. package/dist/db-IPXRJUI7.js +0 -20
  166. package/dist/delivery-manager-FDHCZ7PU.js +0 -37
  167. package/dist/echo-text-KU6G4Z7V.js +0 -40
  168. package/dist/extensions-VACUKFA5.js +0 -60
  169. package/dist/message-delivery-TUXM3AAE.js +0 -46
  170. package/dist/mind-service-WHFBUKZE.js +0 -48
  171. package/dist/scheduler-5X5UIQOQ.js +0 -27
  172. package/dist/skills/plan-coordinator/SKILL.md +0 -60
  173. package/dist/sleep-manager-NWUCRBZB.js +0 -42
  174. package/dist/spirit-availability-NIUUYKU2.js +0 -43
  175. package/dist/src-HGNE2XG4.js +0 -832
  176. package/dist/src-LCSOQY6Z.js +0 -2222
  177. package/dist/src-UDMJZ6MH.js +0 -426
  178. package/dist/variant-cleanup-CZDLIY3F.js +0 -24
  179. package/dist/web-assets/assets/index-BHSU9r-4.css +0 -1
  180. package/packages/extensions/notes/dist/ui/assets/index-BBs8pyel.js +0 -67
  181. package/packages/extensions/notes/dist/ui/assets/index-D3cdui42.css +0 -1
  182. package/packages/extensions/notes/skills/notes/SKILL.md +0 -90
  183. package/packages/extensions/pages/dist/ui/assets/index-B589e8Xe.js +0 -2
  184. package/packages/extensions/pages/dist/ui/assets/index-BuXnE-rb.css +0 -1
  185. package/packages/extensions/plan/dist/ui/assets/index-B8s8wxyt.js +0 -67
  186. package/packages/extensions/plan/dist/ui/assets/index-jIkrt-vI.css +0 -1
  187. package/packages/extensions/plan/dist/ui/index.html +0 -14
  188. package/packages/extensions/plan/skills/plan/SKILL.md +0 -43
  189. package/packages/extensions/plan/skills/plan/scripts/plan-hook.sh +0 -37
  190. package/templates/claude/.init/.config/routes.json +0 -11
  191. package/templates/codex/.init/.config/routes.json +0 -11
  192. package/dist/{accept-I4GVGWA3.js → accept-RSDIVJL6.js} +3 -3
  193. package/dist/{bridge-KU2IKSH3.js → bridge-YK7NTRU5.js} +3 -3
  194. package/dist/{create-C3XZACTV.js → create-M727VUDF.js} +3 -3
  195. package/dist/{env-BJGM6FBA.js → env-7AZFBPWX.js} +7 -7
  196. package/dist/{extension-B2W52WZY.js → extension-MRYJWSMV.js} +3 -3
  197. package/dist/{list-R2GDWOEE.js → list-UQGIW7OF.js} +3 -3
  198. package/dist/{login-EZ4RRDQX.js → login-4NUS72Z5.js} +3 -3
  199. package/dist/{login-JDOAK465.js → login-57MMYILL.js} +4 -4
  200. package/dist/{logout-MWSIUOQU.js → logout-BYV433X6.js} +3 -3
  201. package/dist/{logout-K6ZGAJY5.js → logout-YFZAJRPY.js} +3 -3
  202. package/dist/{mind-history-RVF6KJ7K.js → mind-history-RZMMCHMX.js} +9 -9
  203. package/dist/{mind-wake-DCDFFQKX.js → mind-wake-LDGPRA42.js} +3 -3
  204. package/dist/{read-J5RM674N.js → read-RJ5NAW5J.js} +3 -3
  205. package/dist/{register-53LBGSDC.js → register-WNCSOTAU.js} +3 -3
  206. package/dist/{reject-K2A4UK2Y.js → reject-4NFLXKRN.js} +3 -3
  207. package/dist/{restart-R2WFNF5K.js → restart-B4GNMVF2.js} +7 -7
  208. package/dist/{skill-DXLLSUHB.js → skill-QYTBUDNQ.js} +7 -7
  209. package/dist/{start-XDOUAWN3.js → start-BDHJVOVX.js} +6 -6
  210. package/dist/{stop-O62RTEMD.js → stop-45QYSGYS.js} +7 -7
@@ -1,2222 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- createExtension
4
- } from "./chunk-RG5TOL4O.js";
5
- import {
6
- getAllSites,
7
- getPublishedPages,
8
- getRecentPages,
9
- getSystemPages,
10
- initDb,
11
- syncPublishedPages,
12
- syncSystemPages
13
- } from "./chunk-R772ET2M.js";
14
- import "./chunk-K3NQKI34.js";
15
-
16
- // packages/extensions/pages/src/index.ts
17
- import { resolve as resolve5 } from "path";
18
-
19
- // packages/extensions/pages/src/commands.ts
20
- import { cpSync, existsSync as existsSync2, readdirSync as readdirSync2, readFileSync as readFileSync2, rmSync as rmSync2, statSync as statSync2 } from "fs";
21
- import { relative as relative2, resolve as resolve2 } from "path";
22
-
23
- // packages/extensions/pages/src/shared-pages.ts
24
- import { execFile as execFileCb } from "child_process";
25
- import { createHash } from "crypto";
26
- import {
27
- chmodSync,
28
- existsSync,
29
- mkdirSync,
30
- readdirSync,
31
- readFileSync,
32
- rmSync,
33
- statSync,
34
- writeFileSync
35
- } from "fs";
36
- import { relative, resolve } from "path";
37
- function isolationFrom(ctx) {
38
- return { isIsolationEnabled: ctx.isIsolationEnabled, getMindUser: ctx.getMindUser };
39
- }
40
- function execAsync(cmd, args) {
41
- return new Promise((resolve6, reject) => {
42
- execFileCb(cmd, args, (err) => {
43
- if (err) reject(err);
44
- else resolve6();
45
- });
46
- });
47
- }
48
- var IDENTITY_ARGS = ["-c", "user.name=volute", "-c", "user.email=volute@localhost"];
49
- function gitExec(args, opts, isolation) {
50
- const prefix = [];
51
- if (isolation?.isIsolationEnabled()) prefix.push("-c", "safe.directory=*");
52
- if (args[0] === "commit") prefix.push(...IDENTITY_ARGS);
53
- const fullArgs = prefix.length ? [...prefix, ...args] : args;
54
- return new Promise((resolve6, reject) => {
55
- execFileCb("git", fullArgs, { cwd: opts.cwd }, (err, stdout, stderr) => {
56
- if (err) {
57
- const e = err;
58
- e.stderr = stderr;
59
- e.stdout = stdout;
60
- reject(err);
61
- } else {
62
- resolve6(stdout);
63
- }
64
- });
65
- });
66
- }
67
- function readWorktreeGitDir(worktreePath2) {
68
- const dotGit = resolve(worktreePath2, ".git");
69
- if (!existsSync(dotGit)) return null;
70
- try {
71
- const content = readFileSync(dotGit, "utf-8").trim();
72
- const match = content.match(/^gitdir:\s*(.+)$/);
73
- return match ? match[1] : null;
74
- } catch (err) {
75
- console.warn(`[pages] failed to read .git file at ${dotGit}: ${err.message}`);
76
- return null;
77
- }
78
- }
79
- function pagesRepoDir(dataDir) {
80
- return resolve(dataDir, "repo");
81
- }
82
- function worktreePath(mindDir) {
83
- return resolve(mindDir, "home", "pages", "_system");
84
- }
85
- function pagesIsolationChownPaths(mindDir, wtGitDir) {
86
- const paths = [resolve(mindDir, "home", "pages")];
87
- if (wtGitDir) paths.push(wtGitDir);
88
- return paths;
89
- }
90
- async function isRepoValid(dir, isolation) {
91
- try {
92
- await gitExec(["rev-parse", "HEAD"], { cwd: dir }, isolation);
93
- return true;
94
- } catch {
95
- return false;
96
- }
97
- }
98
- async function ensurePagesRepo(dataDir, isolation) {
99
- const dir = pagesRepoDir(dataDir);
100
- mkdirSync(dir, { recursive: true });
101
- if (existsSync(resolve(dir, ".git"))) {
102
- if (await isRepoValid(dir, isolation)) return;
103
- console.warn("[pages] repo invalid or incomplete, re-initializing");
104
- rmSync(resolve(dir, ".git"), { recursive: true, force: true });
105
- }
106
- const isIso = isolation?.isIsolationEnabled() ?? false;
107
- const initArgs = isIso ? ["init", "--shared=group"] : ["init"];
108
- await gitExec(initArgs, { cwd: dir }, isolation);
109
- await gitExec(["checkout", "-b", "main"], { cwd: dir }, isolation);
110
- writeFileSync(resolve(dir, ".gitkeep"), "");
111
- await gitExec(["add", "-A"], { cwd: dir }, isolation);
112
- await gitExec(["commit", "-m", "init pages repo"], { cwd: dir }, isolation);
113
- if (isIso) {
114
- try {
115
- await execAsync("chgrp", ["-R", "volute", dir]);
116
- } catch {
117
- console.warn("[pages] failed to chgrp pages repo to volute group");
118
- }
119
- chmodSync(dir, 1533);
120
- }
121
- }
122
- async function addPagesWorktree(mindName, mindDir, dataDir, isolation) {
123
- const dir = pagesRepoDir(dataDir);
124
- if (!await isRepoValid(dir, isolation)) {
125
- console.warn(`[pages] repo not usable, skipping worktree for ${mindName}`);
126
- return;
127
- }
128
- const wt = worktreePath(mindDir);
129
- if (existsSync(wt)) return;
130
- mkdirSync(resolve(mindDir, "home", "pages"), { recursive: true });
131
- let branchExists = false;
132
- try {
133
- await gitExec(["rev-parse", "--verify", mindName], { cwd: dir }, isolation);
134
- branchExists = true;
135
- } catch {
136
- }
137
- if (branchExists) {
138
- await gitExec(["worktree", "add", wt, mindName], { cwd: dir }, isolation);
139
- } else {
140
- await gitExec(["worktree", "add", "-b", mindName, wt], { cwd: dir }, isolation);
141
- }
142
- if (isolation?.isIsolationEnabled()) {
143
- const user = isolation.getMindUser(mindName);
144
- const wtGitDir = readWorktreeGitDir(wt);
145
- for (const target of pagesIsolationChownPaths(mindDir, wtGitDir)) {
146
- try {
147
- await execAsync("chown", ["-R", `${user}:volute`, target]);
148
- } catch {
149
- console.warn(`[pages] failed to chown ${target} for ${mindName}`);
150
- }
151
- }
152
- }
153
- }
154
- var pagesLock = Promise.resolve();
155
- async function withPagesLock(fn) {
156
- const prev = pagesLock;
157
- let resolve_;
158
- pagesLock = new Promise((r) => {
159
- resolve_ = r;
160
- });
161
- await prev;
162
- try {
163
- return await fn();
164
- } finally {
165
- resolve_();
166
- }
167
- }
168
- async function pagesPull(mindName, mindDir, isolation) {
169
- return withPagesLock(async () => {
170
- const wt = worktreePath(mindDir);
171
- const status = (await gitExec(["status", "--porcelain"], { cwd: wt }, isolation)).trim();
172
- if (status) {
173
- await gitExec(["add", "-A"], { cwd: wt }, isolation);
174
- await gitExec(
175
- ["commit", "--author", `${mindName} <${mindName}@volute>`, "-m", `wip: ${mindName}`],
176
- { cwd: wt },
177
- isolation
178
- );
179
- }
180
- try {
181
- await gitExec(["rebase", "main"], { cwd: wt }, isolation);
182
- } catch (err) {
183
- const errMsg = err instanceof Error ? err.message : String(err);
184
- const isConflict = errMsg.includes("CONFLICT") || errMsg.includes("could not apply") || errMsg.includes("merge conflict");
185
- try {
186
- await gitExec(["rebase", "--abort"], { cwd: wt }, isolation);
187
- } catch (abortErr) {
188
- console.error("[pages] rebase abort failed", abortErr);
189
- }
190
- if (isConflict) {
191
- return {
192
- ok: false,
193
- conflicts: true,
194
- message: "Pull conflicts detected \u2014 your changes conflict with main. Reconcile the conflicting files, commit, and pull again."
195
- };
196
- }
197
- console.error("[pages] pull rebase failed", err);
198
- return { ok: false, message: `Pull failed: ${errMsg}` };
199
- }
200
- if (isolation?.isIsolationEnabled()) {
201
- try {
202
- await execAsync("chown", ["-R", `${isolation.getMindUser(mindName)}:volute`, wt]);
203
- } catch {
204
- }
205
- }
206
- return { ok: true, message: "Pulled latest shared changes." };
207
- });
208
- }
209
- async function pagesPullAndMerge(mindName, mindDir, dataDir, message, isolation) {
210
- return withPagesLock(async () => {
211
- const wt = worktreePath(mindDir);
212
- const dir = pagesRepoDir(dataDir);
213
- const status = (await gitExec(["status", "--porcelain"], { cwd: wt }, isolation)).trim();
214
- if (status) {
215
- await gitExec(["add", "-A"], { cwd: wt }, isolation);
216
- await gitExec(
217
- ["commit", "--author", `${mindName} <${mindName}@volute>`, "-m", `wip: ${mindName}`],
218
- { cwd: wt },
219
- isolation
220
- );
221
- }
222
- try {
223
- await gitExec(["rebase", "main"], { cwd: wt }, isolation);
224
- } catch (err) {
225
- const errMsg = err instanceof Error ? err.message : String(err);
226
- const isConflict = errMsg.includes("CONFLICT") || errMsg.includes("could not apply") || errMsg.includes("merge conflict");
227
- try {
228
- await gitExec(["rebase", "--abort"], { cwd: wt }, isolation);
229
- } catch (abortErr) {
230
- console.error("[pages] rebase abort failed", abortErr);
231
- }
232
- if (isConflict) {
233
- return {
234
- ok: false,
235
- conflicts: true,
236
- message: "Pull conflicts detected \u2014 your changes conflict with main. Reconcile the conflicting files, commit, and try again."
237
- };
238
- }
239
- return { ok: false, message: `Pull failed: ${errMsg}` };
240
- }
241
- const diff = (await gitExec(["diff", `main...${mindName}`, "--stat"], { cwd: dir }, isolation)).trim();
242
- if (!diff) {
243
- return { ok: true, message: "Nothing to publish" };
244
- }
245
- try {
246
- await gitExec(["merge", "--squash", mindName], { cwd: dir }, isolation);
247
- } catch (err) {
248
- const errOutput = [
249
- err.message,
250
- err.stderr ?? "",
251
- err.stdout ?? ""
252
- ].join("\n");
253
- const isConflict = errOutput.includes("CONFLICT") || errOutput.includes("could not apply");
254
- try {
255
- await gitExec(["reset", "--hard", "HEAD"], { cwd: dir }, isolation);
256
- } catch (resetErr) {
257
- console.error("[pages] reset after squash conflict failed", resetErr);
258
- }
259
- if (isConflict) {
260
- return { ok: false, conflicts: true, message: "Merge conflicts detected" };
261
- }
262
- return { ok: false, message: `Merge failed: ${err.message}` };
263
- }
264
- await gitExec(
265
- ["commit", "--author", `${mindName} <${mindName}@volute>`, "-m", message],
266
- { cwd: dir },
267
- isolation
268
- );
269
- try {
270
- await gitExec(["reset", "--hard", "main"], { cwd: wt }, isolation);
271
- } catch (err) {
272
- console.error(`[pages] branch reset failed for ${mindName}`, err);
273
- return {
274
- ok: true,
275
- message: "Published to main, but branch reset failed \u2014 run 'volute pages pull' to sync"
276
- };
277
- }
278
- if (isolation?.isIsolationEnabled()) {
279
- try {
280
- await execAsync("chown", ["-R", `${isolation.getMindUser(mindName)}:volute`, wt]);
281
- } catch {
282
- }
283
- }
284
- return { ok: true };
285
- });
286
- }
287
- function collectHtmlFiles(dir) {
288
- const files = [];
289
- function walk(d2) {
290
- let items;
291
- try {
292
- items = readdirSync(d2);
293
- } catch (err) {
294
- if (err?.code === "ENOENT") return;
295
- throw err;
296
- }
297
- for (const item of items) {
298
- if (item.startsWith(".")) continue;
299
- const full = resolve(d2, item);
300
- try {
301
- const s = statSync(full);
302
- if (s.isFile() && item.endsWith(".html")) {
303
- files.push(relative(dir, full));
304
- } else if (s.isDirectory()) {
305
- walk(full);
306
- }
307
- } catch (err) {
308
- if (err?.code === "ENOENT" || err?.code === "EACCES") continue;
309
- throw err;
310
- }
311
- }
312
- }
313
- walk(dir);
314
- return files.sort();
315
- }
316
- function hashFiles(baseDir, files) {
317
- return files.map((file) => ({
318
- file,
319
- hash: createHash("sha256").update(readFileSync(resolve(baseDir, file))).digest("hex")
320
- }));
321
- }
322
- async function pagesStatus(mindDir, isolation) {
323
- const wt = worktreePath(mindDir);
324
- const errors = [];
325
- const [mainFiles, branchFiles, uncommitted] = await Promise.all([
326
- gitExec(["ls-tree", "-r", "--name-only", "main"], { cwd: wt }, isolation).then((s) => s.trim().split("\n").filter(Boolean)).catch((err) => {
327
- errors.push(err);
328
- return [];
329
- }),
330
- gitExec(["ls-tree", "-r", "--name-only", "HEAD"], { cwd: wt }, isolation).then((s) => s.trim().split("\n").filter(Boolean)).catch((err) => {
331
- errors.push(err);
332
- return [];
333
- }),
334
- gitExec(["status", "--porcelain"], { cwd: wt }, isolation).then((s) => s.trim()).catch((err) => {
335
- errors.push(err);
336
- return "";
337
- })
338
- ]);
339
- if (errors.length === 3) {
340
- throw new Error(`Shared pages git error: ${errors[0].message}`);
341
- }
342
- const uncommittedFiles = /* @__PURE__ */ new Set();
343
- if (uncommitted) {
344
- for (const line of uncommitted.split("\n")) {
345
- const match = line.match(/^.{2}\s+(.+)$/);
346
- if (match) uncommittedFiles.add(match[1]);
347
- }
348
- }
349
- const mainSet = new Set(mainFiles.filter((f) => f.endsWith(".html")));
350
- const allHtml = /* @__PURE__ */ new Set([
351
- ...mainFiles.filter((f) => f.endsWith(".html")),
352
- ...branchFiles.filter((f) => f.endsWith(".html")),
353
- ...[...uncommittedFiles].filter((f) => f.endsWith(".html"))
354
- ]);
355
- if (allHtml.size === 0) return "No shared pages found.";
356
- const lines = [...allHtml].sort().map((file) => {
357
- const onMain = mainSet.has(file);
358
- const isUncommitted = uncommittedFiles.has(file);
359
- let status;
360
- if (isUncommitted) {
361
- status = "uncommitted";
362
- } else if (onMain) {
363
- status = "published";
364
- } else {
365
- status = "draft";
366
- }
367
- return `${status.padEnd(13)} ${file}`;
368
- });
369
- return lines.join("\n");
370
- }
371
- async function pagesLog(mindDir, limit = 20, isolation) {
372
- const wt = worktreePath(mindDir);
373
- const output = (await gitExec(["log", "--oneline", "main", `-${limit}`], { cwd: wt }, isolation)).trim();
374
- return output || "No history.";
375
- }
376
-
377
- // packages/extensions/pages/src/commands.ts
378
- function createCommands() {
379
- return {
380
- publish: {
381
- description: "Publish all pages (copy to public snapshot)",
382
- args: [{ name: "message", description: "Commit message for shared publish" }],
383
- flags: {
384
- remote: { type: "boolean", description: "Also publish to volute.systems" },
385
- shared: { type: "boolean", description: "Publish to shared pages repository" }
386
- },
387
- handler: async ({ args, flags }, ctx) => {
388
- const mindName = ctx.mindName;
389
- if (!mindName) return { error: "No mind specified (use --mind or VOLUTE_MIND)" };
390
- if (flags.shared) {
391
- const mindDir2 = ctx.getMindDir(mindName);
392
- if (!mindDir2) return { error: `Mind not found: ${mindName}` };
393
- const message = args.message?.trim();
394
- if (!message)
395
- return { error: 'Usage: volute pages publish --shared "description of changes"' };
396
- try {
397
- const result = await pagesPullAndMerge(
398
- mindName,
399
- mindDir2,
400
- ctx.dataDir,
401
- message,
402
- isolationFrom(ctx)
403
- );
404
- if (!result.ok) {
405
- return {
406
- error: result.message || "Merge conflicts detected \u2014 pull, reconcile, and try again."
407
- };
408
- }
409
- let syncWarning = "";
410
- if (result.ok && ctx.db) {
411
- const repoDir = resolve2(ctx.dataDir, "repo");
412
- try {
413
- syncSystemPages(ctx.db, hashFiles(repoDir, collectHtmlFiles(repoDir)), mindName);
414
- } catch (err) {
415
- console.error("[pages] failed to sync system pages to DB:", err);
416
- syncWarning = "\nWarning: failed to sync pages to dashboard \u2014 they may not appear in the UI until the next daemon restart.";
417
- }
418
- }
419
- return { output: (result.message || "Published shared pages.") + syncWarning };
420
- } catch (err) {
421
- return { error: `Shared publish failed: ${err.message}` };
422
- }
423
- }
424
- const remote = flags.remote;
425
- const mindDir = ctx.getMindDir(mindName);
426
- if (!mindDir) return { error: `Mind not found: ${mindName}` };
427
- const sourceDir = resolve2(mindDir, "home", "pages");
428
- if (!existsSync2(sourceDir)) return { error: "No pages directory found (home/pages/)" };
429
- const db = ctx.db;
430
- if (!db) return { error: "Database not available" };
431
- const snapshotDir = resolve2(ctx.dataDir, "sites", mindName);
432
- try {
433
- if (existsSync2(snapshotDir)) rmSync2(snapshotDir, { recursive: true });
434
- cpSync(sourceDir, snapshotDir, {
435
- recursive: true,
436
- filter: (src) => !src.endsWith("/_system") && !src.includes("/_system/")
437
- });
438
- } catch (err) {
439
- return { error: `Failed to publish snapshot: ${err.message}` };
440
- }
441
- const pageFiles = collectFiles(snapshotDir, snapshotDir, [".html", ".md"]);
442
- let diff;
443
- try {
444
- diff = syncPublishedPages(db, mindName, hashFiles(snapshotDir, pageFiles));
445
- } catch (err) {
446
- return { error: `Failed to update page database: ${err.message}` };
447
- }
448
- for (const file of diff.added) {
449
- ctx.publishActivity({
450
- type: "page_published",
451
- mind: mindName,
452
- summary: `${mindName} published ${file}`,
453
- metadata: {
454
- file,
455
- url: `/minds/${mindName}/pages/${file}`,
456
- iframeUrl: `/ext/pages/public/${mindName}/${file}`
457
- }
458
- });
459
- }
460
- for (const file of diff.removed) {
461
- ctx.publishActivity({
462
- type: "page_removed",
463
- mind: mindName,
464
- summary: `${mindName} removed ${file}`,
465
- metadata: { file }
466
- });
467
- }
468
- let output = `Published ${pageFiles.length} files`;
469
- const parts = [];
470
- if (diff.added.length > 0) parts.push(`${diff.added.length} new`);
471
- if (diff.updated.length > 0) parts.push(`${diff.updated.length} updated`);
472
- if (diff.removed.length > 0) parts.push(`${diff.removed.length} removed`);
473
- if (parts.length > 0) output += ` (${parts.join(", ")})`;
474
- if (remote) {
475
- const config = ctx.getSystemsConfig();
476
- if (!config)
477
- return {
478
- error: "Not connected to volute.systems. Run volute systems register or login first."
479
- };
480
- const allFiles = collectFiles(snapshotDir, snapshotDir);
481
- const files = {};
482
- for (const f of allFiles) {
483
- const fp = resolve2(snapshotDir, f);
484
- files[f] = readFileSync2(fp).toString("base64");
485
- }
486
- try {
487
- const res = await fetch(`${config.apiUrl}/api/pages/publish/${mindName}`, {
488
- method: "PUT",
489
- headers: {
490
- "Content-Type": "application/json",
491
- Authorization: `Bearer ${config.apiKey}`
492
- },
493
- body: JSON.stringify({ files })
494
- });
495
- const data = await res.json().catch(() => ({}));
496
- if (!res.ok) {
497
- const errMsg = data.error || `HTTP ${res.status}`;
498
- output += `
499
- Warning: remote publish failed: ${errMsg}`;
500
- } else if (data.url) {
501
- output += `
502
- Remote: ${data.url}`;
503
- }
504
- } catch (err) {
505
- output += `
506
- Warning: remote publish failed: ${err.message}`;
507
- }
508
- }
509
- return { output };
510
- }
511
- },
512
- list: {
513
- description: "List pages with publish status",
514
- flags: {
515
- all: { type: "boolean", description: "Show pages from all minds" },
516
- shared: { type: "boolean", description: "Show shared pages status" }
517
- },
518
- handler: async ({ flags }, ctx) => {
519
- const db = ctx.db;
520
- if (!db) return { error: "Database not available" };
521
- const allFlag = flags.all;
522
- const port = process.env.VOLUTE_DAEMON_PORT || "1618";
523
- if (allFlag) {
524
- const { getAllSites: getAllSites2, getSystemPages: getSystemPages2 } = await import("./db-IPXRJUI7.js");
525
- const sites = getAllSites2(db);
526
- const system = getSystemPages2(db);
527
- const lines2 = [];
528
- if (system) {
529
- for (const f of system.files) {
530
- const url = `http://localhost:${port}/ext/pages/public/_system/${f.file}`;
531
- const author = f.author ? ` (${f.author})` : "";
532
- lines2.push(`_system${author.padStart(10)} ${f.file.padEnd(25)} ${url}`);
533
- }
534
- }
535
- for (const site of sites) {
536
- for (const f of site.files) {
537
- const url = `http://localhost:${port}/ext/pages/public/${site.mind}/${f.file}`;
538
- lines2.push(`${site.mind.padEnd(15)} ${f.file.padEnd(25)} ${url}`);
539
- }
540
- }
541
- return { output: lines2.length > 0 ? lines2.join("\n") : "No published pages found." };
542
- }
543
- const mindName = ctx.mindName;
544
- if (!mindName) return { error: "No mind specified (use --mind or VOLUTE_MIND)" };
545
- if (flags.shared) {
546
- const mindDir2 = ctx.getMindDir(mindName);
547
- if (!mindDir2) return { error: `Mind not found: ${mindName}` };
548
- try {
549
- const status = await pagesStatus(mindDir2, isolationFrom(ctx));
550
- return { output: status };
551
- } catch (err) {
552
- return { error: `Failed to check shared status: ${err.message}` };
553
- }
554
- }
555
- const mindDir = ctx.getMindDir(mindName);
556
- if (!mindDir) return { error: `Mind not found: ${mindName}` };
557
- const sourceDir = resolve2(mindDir, "home", "pages");
558
- const published = new Set(getPublishedPages(db, mindName).map((p) => p.file));
559
- const draftFiles = existsSync2(sourceDir) ? collectFiles(sourceDir, sourceDir, [".html", ".md"]) : [];
560
- const allFiles = /* @__PURE__ */ new Set([...published, ...draftFiles]);
561
- if (allFiles.size === 0) return { output: "No pages found." };
562
- const lines = [...allFiles].sort().map((file) => {
563
- const isPublished = published.has(file);
564
- const status = isPublished ? "published" : "draft";
565
- const url = isPublished ? `http://localhost:${port}/ext/pages/public/${mindName}/${file}` : "";
566
- return `${status.padEnd(11)} ${file.padEnd(25)} ${url}`;
567
- });
568
- return { output: lines.join("\n") };
569
- }
570
- },
571
- pull: {
572
- description: "Pull latest shared page changes from other minds",
573
- handler: async (_parsed, ctx) => {
574
- const mindName = ctx.mindName;
575
- if (!mindName) return { error: "No mind specified (use --mind or VOLUTE_MIND)" };
576
- const mindDir = ctx.getMindDir(mindName);
577
- if (!mindDir) return { error: `Mind not found: ${mindName}` };
578
- try {
579
- const result = await pagesPull(mindName, mindDir, isolationFrom(ctx));
580
- if (!result.ok) {
581
- return { error: result.message || "Pull failed." };
582
- }
583
- return { output: result.message || "Pulled latest shared changes." };
584
- } catch (err) {
585
- return { error: `Pull failed: ${err.message}` };
586
- }
587
- }
588
- },
589
- log: {
590
- description: "View shared pages commit history",
591
- flags: {
592
- limit: { type: "number", description: "Max number of entries to show (default: 20)" }
593
- },
594
- handler: async ({ flags }, ctx) => {
595
- const mindName = ctx.mindName;
596
- if (!mindName) return { error: "No mind specified (use --mind or VOLUTE_MIND)" };
597
- const mindDir = ctx.getMindDir(mindName);
598
- if (!mindDir) return { error: `Mind not found: ${mindName}` };
599
- const limit = flags.limit ?? 20;
600
- try {
601
- const output = await pagesLog(mindDir, limit, isolationFrom(ctx));
602
- return { output };
603
- } catch (err) {
604
- return { error: `Failed to read shared log: ${err.message}` };
605
- }
606
- }
607
- }
608
- };
609
- }
610
- function collectFiles(dir, baseDir, ext) {
611
- const files = [];
612
- let items;
613
- try {
614
- items = readdirSync2(dir);
615
- } catch (err) {
616
- console.error(`[pages] failed to read directory ${dir}: ${err.message}`);
617
- return files;
618
- }
619
- for (const item of items) {
620
- if (item.startsWith(".")) continue;
621
- const fullPath = resolve2(dir, item);
622
- try {
623
- const s = statSync2(fullPath);
624
- const matchesExt = !ext || (Array.isArray(ext) ? ext.some((e) => item.endsWith(e)) : item.endsWith(ext));
625
- if (s.isFile() && matchesExt) {
626
- files.push(relative2(baseDir, fullPath));
627
- } else if (s.isDirectory()) {
628
- files.push(...collectFiles(fullPath, baseDir, ext));
629
- }
630
- } catch (err) {
631
- console.error(`[pages] failed to stat ${fullPath}: ${err.message}`);
632
- }
633
- }
634
- return files.sort();
635
- }
636
-
637
- // packages/extensions/pages/src/routes.ts
638
- import { readFile, stat } from "fs/promises";
639
- import { extname, resolve as resolve4 } from "path";
640
- import { Hono } from "hono";
641
-
642
- // packages/extensions/pages/src/cache.ts
643
- function mapFiles(mind, files) {
644
- return files.map((f) => ({
645
- file: f.file,
646
- modified: f.updated_at,
647
- url: `/ext/pages/public/${mind}/${f.file}`,
648
- author: f.author
649
- }));
650
- }
651
- function getSites(db) {
652
- const sites = getAllSites(db).map((site) => ({
653
- name: site.mind,
654
- label: site.mind,
655
- pages: mapFiles(site.mind, site.files)
656
- }));
657
- const system = getSystemPages(db);
658
- const systemSite = system ? { name: "_system", label: "Shared Pages", pages: mapFiles("_system", system.files) } : null;
659
- return { sites, systemSite };
660
- }
661
- function getRecentPagesList(db, opts) {
662
- const rows = getRecentPages(db, opts);
663
- return rows.map((r) => ({
664
- mind: r.mind,
665
- file: r.file,
666
- modified: r.updated_at,
667
- url: `/ext/pages/public/${r.mind}/${r.file}`,
668
- author: r.author
669
- }));
670
- }
671
-
672
- // packages/extensions/pages/src/markdown.ts
673
- import { existsSync as existsSync3 } from "fs";
674
- import { dirname, relative as relative3, resolve as resolve3 } from "path";
675
- import DOMPurify from "isomorphic-dompurify";
676
-
677
- // node_modules/marked/lib/marked.esm.js
678
- function M() {
679
- return { async: false, breaks: false, extensions: null, gfm: true, hooks: null, pedantic: false, renderer: null, silent: false, tokenizer: null, walkTokens: null };
680
- }
681
- var T = M();
682
- function N(l3) {
683
- T = l3;
684
- }
685
- var _ = { exec: () => null };
686
- function E(l3) {
687
- let e = [];
688
- return (t) => {
689
- let n = Math.max(0, Math.min(3, t - 1)), s = e[n];
690
- return s || (s = l3(n), e[n] = s), s;
691
- };
692
- }
693
- function d(l3, e = "") {
694
- let t = typeof l3 == "string" ? l3 : l3.source, n = { replace: (s, r) => {
695
- let i = typeof r == "string" ? r : r.source;
696
- return i = i.replace(m.caret, "$1"), t = t.replace(s, i), n;
697
- }, getRegex: () => new RegExp(t, e) };
698
- return n;
699
- }
700
- var Te = ((l3 = "") => {
701
- try {
702
- return !!new RegExp("(?<=1)(?<!1)" + l3);
703
- } catch {
704
- return false;
705
- }
706
- })();
707
- var m = { codeRemoveIndent: /^(?: {1,4}| {0,3}\t)/gm, outputLinkReplace: /\\([\[\]])/g, indentCodeCompensation: /^(\s+)(?:```)/, beginningSpace: /^\s+/, endingHash: /#$/, startingSpaceChar: /^ /, endingSpaceChar: / $/, nonSpaceChar: /[^ ]/, newLineCharGlobal: /\n/g, tabCharGlobal: /\t/g, multipleSpaceGlobal: /\s+/g, blankLine: /^[ \t]*$/, doubleBlankLine: /\n[ \t]*\n[ \t]*$/, blockquoteStart: /^ {0,3}>/, blockquoteSetextReplace: /\n {0,3}((?:=+|-+) *)(?=\n|$)/g, blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm, listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g, listIsTask: /^\[[ xX]\] +\S/, listReplaceTask: /^\[[ xX]\] +/, listTaskCheckbox: /\[[ xX]\]/, anyLine: /\n.*\n/, hrefBrackets: /^<(.*)>$/, tableDelimiter: /[:|]/, tableAlignChars: /^\||\| *$/g, tableRowBlankLine: /\n[ \t]*$/, tableAlignRight: /^ *-+: *$/, tableAlignCenter: /^ *:-+: *$/, tableAlignLeft: /^ *:-+ *$/, startATag: /^<a /i, endATag: /^<\/a>/i, startPreScriptTag: /^<(pre|code|kbd|script)(\s|>)/i, endPreScriptTag: /^<\/(pre|code|kbd|script)(\s|>)/i, startAngleBracket: /^</, endAngleBracket: />$/, pedanticHrefTitle: /^([^'"]*[^\s])\s+(['"])(.*)\2/, unicodeAlphaNumeric: /[\p{L}\p{N}]/u, escapeTest: /[&<>"']/, escapeReplace: /[&<>"']/g, escapeTestNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/, escapeReplaceNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g, caret: /(^|[^\[])\^/g, percentDecode: /%25/g, findPipe: /\|/g, splitPipe: / \|/, slashPipe: /\\\|/g, carriageReturn: /\r\n|\r/g, spaceLine: /^ +$/gm, notSpaceStart: /^\S*/, endingNewline: /\n$/, listItemRegex: (l3) => new RegExp(`^( {0,3}${l3})((?:[ ][^\\n]*)?(?:\\n|$))`), nextBulletRegex: E((l3) => new RegExp(`^ {0,${l3}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)), hrRegex: E((l3) => new RegExp(`^ {0,${l3}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`)), fencesBeginRegex: E((l3) => new RegExp(`^ {0,${l3}}(?:\`\`\`|~~~)`)), headingBeginRegex: E((l3) => new RegExp(`^ {0,${l3}}#`)), htmlBeginRegex: E((l3) => new RegExp(`^ {0,${l3}}<(?:[a-z].*>|!--)`, "i")), blockquoteBeginRegex: E((l3) => new RegExp(`^ {0,${l3}}>`)) };
708
- var Oe = /^(?:[ \t]*(?:\n|$))+/;
709
- var we = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/;
710
- var ye = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/;
711
- var B = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
712
- var Pe = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/;
713
- var j = / {0,3}(?:[*+-]|\d{1,9}[.)])/;
714
- var oe = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/;
715
- var ae = d(oe).replace(/bull/g, j).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/\|table/g, "").getRegex();
716
- var Se = d(oe).replace(/bull/g, j).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex();
717
- var F = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/;
718
- var $e = /^[^\n]+/;
719
- var U = /(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/;
720
- var Le = d(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label", U).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex();
721
- var _e = d(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g, j).getRegex();
722
- var H = "address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul";
723
- var K = /<!--(?:-?>|[\s\S]*?(?:-->|$))/;
724
- var ze = d("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n+|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n+|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\n+|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))", "i").replace("comment", K).replace("tag", H).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
725
- var le = (l3) => d(F).replace("hr", B).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("|table", "").replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", l3).replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", H).getRegex();
726
- var Me = le(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/);
727
- var Ee = le(/ {0,3}(?:[*+-]|\d{1,9}[.)])[ \t]+[^ \t\n]/);
728
- var Ie = d(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", Ee).getRegex();
729
- var W = { blockquote: Ie, code: we, def: Le, fences: ye, heading: Pe, hr: B, html: ze, lheading: ae, list: _e, newline: Oe, paragraph: Me, table: _, text: $e };
730
- var se = d("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr", B).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("blockquote", " {0,3}>").replace("code", "(?: {4}| {0,3} )[^\\n]").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", H).getRegex();
731
- var Ae = { ...W, lheading: Se, table: se, paragraph: d(F).replace("hr", B).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("table", se).replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", H).getRegex() };
732
- var Ce = { ...W, html: d(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment", K).replace(/tag/g, "(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(), def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/, heading: /^(#{1,6})(.*)(?:\n+|$)/, fences: _, lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/, paragraph: d(F).replace("hr", B).replace("heading", ` *#{1,6} *[^
733
- ]`).replace("lheading", ae).replace("|table", "").replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").replace("|tag", "").getRegex() };
734
- var Be = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/;
735
- var qe = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/;
736
- var ue = /^( {2,}|\\)\n(?!\s*$)/;
737
- var De = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/;
738
- var I = /[\p{P}\p{S}]/u;
739
- var Z = /[\s\p{P}\p{S}]/u;
740
- var X = /[^\s\p{P}\p{S}]/u;
741
- var ve = d(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, Z).getRegex();
742
- var pe = /(?!~)[\p{P}\p{S}]/u;
743
- var He = /(?!~)[\s\p{P}\p{S}]/u;
744
- var Ze = /(?:[^\s\p{P}\p{S}]|~)/u;
745
- var Ge = d(/link|precode-code|html/, "g").replace("link", /\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-", Te ? "(?<!`)()" : "(^^|[^`])").replace("code", /(?<b>`+)[^`]+\k<b>(?!`)/).replace("html", /<(?! )[^<>]*?>/).getRegex();
746
- var ce = /^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/;
747
- var Ne = d(ce, "u").replace(/punct/g, I).getRegex();
748
- var Qe = d(ce, "u").replace(/punct/g, pe).getRegex();
749
- var he = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)";
750
- var je = d(he, "gu").replace(/notPunctSpace/g, X).replace(/punctSpace/g, Z).replace(/punct/g, I).getRegex();
751
- var Fe = d(he, "gu").replace(/notPunctSpace/g, Ze).replace(/punctSpace/g, He).replace(/punct/g, pe).getRegex();
752
- var Ue = d("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)", "gu").replace(/notPunctSpace/g, X).replace(/punctSpace/g, Z).replace(/punct/g, I).getRegex();
753
- var Ke = d(/^~~?(?:((?!~)punct)|[^\s~])/, "u").replace(/punct/g, I).getRegex();
754
- var We = "^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)";
755
- var Xe = d(We, "gu").replace(/notPunctSpace/g, X).replace(/punctSpace/g, Z).replace(/punct/g, I).getRegex();
756
- var Je = d(/\\(punct)/, "gu").replace(/punct/g, I).getRegex();
757
- var Ve = d(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme", /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email", /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex();
758
- var Ye = d(K).replace("(?:-->|$)", "-->").getRegex();
759
- var et = d("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment", Ye).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex();
760
- var v = /(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/;
761
- var tt = d(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label", v).replace("href", /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex();
762
- var ke = d(/^!?\[(label)\]\[(ref)\]/).replace("label", v).replace("ref", U).getRegex();
763
- var de = d(/^!?\[(ref)\](?:\[\])?/).replace("ref", U).getRegex();
764
- var nt = d("reflink|nolink(?!\\()", "g").replace("reflink", ke).replace("nolink", de).getRegex();
765
- var ie = /[hH][tT][tT][pP][sS]?|[fF][tT][pP]/;
766
- var J = { _backpedal: _, anyPunctuation: Je, autolink: Ve, blockSkip: Ge, br: ue, code: qe, del: _, delLDelim: _, delRDelim: _, emStrongLDelim: Ne, emStrongRDelimAst: je, emStrongRDelimUnd: Ue, escape: Be, link: tt, nolink: de, punctuation: ve, reflink: ke, reflinkSearch: nt, tag: et, text: De, url: _ };
767
- var rt = { ...J, link: d(/^!?\[(label)\]\((.*?)\)/).replace("label", v).getRegex(), reflink: d(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", v).getRegex() };
768
- var Q = { ...J, emStrongRDelimAst: Fe, emStrongLDelim: Qe, delLDelim: Ke, delRDelim: Xe, url: d(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol", ie).replace("email", /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(), _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/, del: /^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/, text: d(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol", ie).getRegex() };
769
- var st = { ...Q, br: d(ue).replace("{2,}", "*").getRegex(), text: d(Q.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex() };
770
- var q = { normal: W, gfm: Ae, pedantic: Ce };
771
- var A = { normal: J, gfm: Q, breaks: st, pedantic: rt };
772
- var it = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" };
773
- var ge = (l3) => it[l3];
774
- function O(l3, e) {
775
- if (e) {
776
- if (m.escapeTest.test(l3)) return l3.replace(m.escapeReplace, ge);
777
- } else if (m.escapeTestNoEncode.test(l3)) return l3.replace(m.escapeReplaceNoEncode, ge);
778
- return l3;
779
- }
780
- function V(l3) {
781
- try {
782
- l3 = encodeURI(l3).replace(m.percentDecode, "%");
783
- } catch {
784
- return null;
785
- }
786
- return l3;
787
- }
788
- function Y(l3, e) {
789
- let t = l3.replace(m.findPipe, (r, i, o) => {
790
- let u = false, a = i;
791
- for (; --a >= 0 && o[a] === "\\"; ) u = !u;
792
- return u ? "|" : " |";
793
- }), n = t.split(m.splitPipe), s = 0;
794
- if (n[0].trim() || n.shift(), n.length > 0 && !n.at(-1)?.trim() && n.pop(), e) if (n.length > e) n.splice(e);
795
- else for (; n.length < e; ) n.push("");
796
- for (; s < n.length; s++) n[s] = n[s].trim().replace(m.slashPipe, "|");
797
- return n;
798
- }
799
- function $(l3, e, t) {
800
- let n = l3.length;
801
- if (n === 0) return "";
802
- let s = 0;
803
- for (; s < n; ) {
804
- let r = l3.charAt(n - s - 1);
805
- if (r === e && !t) s++;
806
- else if (r !== e && t) s++;
807
- else break;
808
- }
809
- return l3.slice(0, n - s);
810
- }
811
- function ee(l3) {
812
- let e = l3.split(`
813
- `), t = e.length - 1;
814
- for (; t >= 0 && m.blankLine.test(e[t]); ) t--;
815
- return e.length - t <= 2 ? l3 : e.slice(0, t + 1).join(`
816
- `);
817
- }
818
- function fe(l3, e) {
819
- if (l3.indexOf(e[1]) === -1) return -1;
820
- let t = 0;
821
- for (let n = 0; n < l3.length; n++) if (l3[n] === "\\") n++;
822
- else if (l3[n] === e[0]) t++;
823
- else if (l3[n] === e[1] && (t--, t < 0)) return n;
824
- return t > 0 ? -2 : -1;
825
- }
826
- function me(l3, e = 0) {
827
- let t = e, n = "";
828
- for (let s of l3) if (s === " ") {
829
- let r = 4 - t % 4;
830
- n += " ".repeat(r), t += r;
831
- } else n += s, t++;
832
- return n;
833
- }
834
- function xe(l3, e, t, n, s) {
835
- let r = e.href, i = e.title || null, o = l3[1].replace(s.other.outputLinkReplace, "$1");
836
- n.state.inLink = true;
837
- let u = { type: l3[0].charAt(0) === "!" ? "image" : "link", raw: t, href: r, title: i, text: o, tokens: n.inlineTokens(o) };
838
- return n.state.inLink = false, u;
839
- }
840
- function ot(l3, e, t) {
841
- let n = l3.match(t.other.indentCodeCompensation);
842
- if (n === null) return e;
843
- let s = n[1];
844
- return e.split(`
845
- `).map((r) => {
846
- let i = r.match(t.other.beginningSpace);
847
- if (i === null) return r;
848
- let [o] = i;
849
- return o.length >= s.length ? r.slice(s.length) : r;
850
- }).join(`
851
- `);
852
- }
853
- var w = class {
854
- options;
855
- rules;
856
- lexer;
857
- constructor(e) {
858
- this.options = e || T;
859
- }
860
- space(e) {
861
- let t = this.rules.block.newline.exec(e);
862
- if (t && t[0].length > 0) return { type: "space", raw: t[0] };
863
- }
864
- code(e) {
865
- let t = this.rules.block.code.exec(e);
866
- if (t) {
867
- let n = this.options.pedantic ? t[0] : ee(t[0]), s = n.replace(this.rules.other.codeRemoveIndent, "");
868
- return { type: "code", raw: n, codeBlockStyle: "indented", text: s };
869
- }
870
- }
871
- fences(e) {
872
- let t = this.rules.block.fences.exec(e);
873
- if (t) {
874
- let n = t[0], s = ot(n, t[3] || "", this.rules);
875
- return { type: "code", raw: n, lang: t[2] ? t[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : t[2], text: s };
876
- }
877
- }
878
- heading(e) {
879
- let t = this.rules.block.heading.exec(e);
880
- if (t) {
881
- let n = t[2].trim();
882
- if (this.rules.other.endingHash.test(n)) {
883
- let s = $(n, "#");
884
- (this.options.pedantic || !s || this.rules.other.endingSpaceChar.test(s)) && (n = s.trim());
885
- }
886
- return { type: "heading", raw: $(t[0], `
887
- `), depth: t[1].length, text: n, tokens: this.lexer.inline(n) };
888
- }
889
- }
890
- hr(e) {
891
- let t = this.rules.block.hr.exec(e);
892
- if (t) return { type: "hr", raw: $(t[0], `
893
- `) };
894
- }
895
- blockquote(e) {
896
- let t = this.rules.block.blockquote.exec(e);
897
- if (t) {
898
- let n = $(t[0], `
899
- `).split(`
900
- `), s = "", r = "", i = [];
901
- for (; n.length > 0; ) {
902
- let o = false, u = [], a;
903
- for (a = 0; a < n.length; a++) if (this.rules.other.blockquoteStart.test(n[a])) u.push(n[a]), o = true;
904
- else if (!o) u.push(n[a]);
905
- else break;
906
- n = n.slice(a);
907
- let c = u.join(`
908
- `), p = c.replace(this.rules.other.blockquoteSetextReplace, `
909
- $1`).replace(this.rules.other.blockquoteSetextReplace2, "");
910
- s = s ? `${s}
911
- ${c}` : c, r = r ? `${r}
912
- ${p}` : p;
913
- let k = this.lexer.state.top;
914
- if (this.lexer.state.top = true, this.lexer.blockTokens(p, i, true), this.lexer.state.top = k, n.length === 0) break;
915
- let h = i.at(-1);
916
- if (h?.type === "code") break;
917
- if (h?.type === "blockquote") {
918
- let R = h, f = R.raw + `
919
- ` + n.join(`
920
- `), S = this.blockquote(f);
921
- i[i.length - 1] = S, s = s.substring(0, s.length - R.raw.length) + S.raw, r = r.substring(0, r.length - R.text.length) + S.text;
922
- break;
923
- } else if (h?.type === "list") {
924
- let R = h, f = R.raw + `
925
- ` + n.join(`
926
- `), S = this.list(f);
927
- i[i.length - 1] = S, s = s.substring(0, s.length - h.raw.length) + S.raw, r = r.substring(0, r.length - R.raw.length) + S.raw, n = f.substring(i.at(-1).raw.length).split(`
928
- `);
929
- continue;
930
- }
931
- }
932
- return { type: "blockquote", raw: s, tokens: i, text: r };
933
- }
934
- }
935
- list(e) {
936
- let t = this.rules.block.list.exec(e);
937
- if (t) {
938
- let n = t[1].trim(), s = n.length > 1, r = { type: "list", raw: "", ordered: s, start: s ? +n.slice(0, -1) : "", loose: false, items: [] };
939
- n = s ? `\\d{1,9}\\${n.slice(-1)}` : `\\${n}`, this.options.pedantic && (n = s ? n : "[*+-]");
940
- let i = this.rules.other.listItemRegex(n), o = false;
941
- for (; e; ) {
942
- let a = false, c = "", p = "";
943
- if (!(t = i.exec(e)) || this.rules.block.hr.test(e)) break;
944
- c = t[0], e = e.substring(c.length);
945
- let k = me(t[2].split(`
946
- `, 1)[0], t[1].length), h = e.split(`
947
- `, 1)[0], R = !k.trim(), f = 0;
948
- if (this.options.pedantic ? (f = 2, p = k.trimStart()) : R ? f = t[1].length + 1 : (f = k.search(this.rules.other.nonSpaceChar), f = f > 4 ? 1 : f, p = k.slice(f), f += t[1].length), R && this.rules.other.blankLine.test(h) && (c += h + `
949
- `, e = e.substring(h.length + 1), a = true), !a) {
950
- let S = this.rules.other.nextBulletRegex(f), te = this.rules.other.hrRegex(f), ne = this.rules.other.fencesBeginRegex(f), re = this.rules.other.headingBeginRegex(f), be = this.rules.other.htmlBeginRegex(f), Re = this.rules.other.blockquoteBeginRegex(f);
951
- for (; e; ) {
952
- let G = e.split(`
953
- `, 1)[0], C;
954
- if (h = G, this.options.pedantic ? (h = h.replace(this.rules.other.listReplaceNesting, " "), C = h) : C = h.replace(this.rules.other.tabCharGlobal, " "), ne.test(h) || re.test(h) || be.test(h) || Re.test(h) || S.test(h) || te.test(h)) break;
955
- if (C.search(this.rules.other.nonSpaceChar) >= f || !h.trim()) p += `
956
- ` + C.slice(f);
957
- else {
958
- if (R || k.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4 || ne.test(k) || re.test(k) || te.test(k)) break;
959
- p += `
960
- ` + h;
961
- }
962
- R = !h.trim(), c += G + `
963
- `, e = e.substring(G.length + 1), k = C.slice(f);
964
- }
965
- }
966
- r.loose || (o ? r.loose = true : this.rules.other.doubleBlankLine.test(c) && (o = true)), r.items.push({ type: "list_item", raw: c, task: !!this.options.gfm && this.rules.other.listIsTask.test(p), loose: false, text: p, tokens: [] }), r.raw += c;
967
- }
968
- let u = r.items.at(-1);
969
- if (u) u.raw = u.raw.trimEnd(), u.text = u.text.trimEnd();
970
- else return;
971
- r.raw = r.raw.trimEnd();
972
- for (let a of r.items) {
973
- this.lexer.state.top = false, a.tokens = this.lexer.blockTokens(a.text, []);
974
- let c = a.tokens[0];
975
- if (a.task && (c?.type === "text" || c?.type === "paragraph")) {
976
- a.text = a.text.replace(this.rules.other.listReplaceTask, ""), c.raw = c.raw.replace(this.rules.other.listReplaceTask, ""), c.text = c.text.replace(this.rules.other.listReplaceTask, "");
977
- for (let k = this.lexer.inlineQueue.length - 1; k >= 0; k--) if (this.rules.other.listIsTask.test(this.lexer.inlineQueue[k].src)) {
978
- this.lexer.inlineQueue[k].src = this.lexer.inlineQueue[k].src.replace(this.rules.other.listReplaceTask, "");
979
- break;
980
- }
981
- let p = this.rules.other.listTaskCheckbox.exec(a.raw);
982
- if (p) {
983
- let k = { type: "checkbox", raw: p[0] + " ", checked: p[0] !== "[ ]" };
984
- a.checked = k.checked, r.loose ? a.tokens[0] && ["paragraph", "text"].includes(a.tokens[0].type) && "tokens" in a.tokens[0] && a.tokens[0].tokens ? (a.tokens[0].raw = k.raw + a.tokens[0].raw, a.tokens[0].text = k.raw + a.tokens[0].text, a.tokens[0].tokens.unshift(k)) : a.tokens.unshift({ type: "paragraph", raw: k.raw, text: k.raw, tokens: [k] }) : a.tokens.unshift(k);
985
- }
986
- } else a.task && (a.task = false);
987
- if (!r.loose) {
988
- let p = a.tokens.filter((h) => h.type === "space"), k = p.length > 0 && p.some((h) => this.rules.other.anyLine.test(h.raw));
989
- r.loose = k;
990
- }
991
- }
992
- if (r.loose) for (let a of r.items) {
993
- a.loose = true;
994
- for (let c of a.tokens) c.type === "text" && (c.type = "paragraph");
995
- }
996
- return r;
997
- }
998
- }
999
- html(e) {
1000
- let t = this.rules.block.html.exec(e);
1001
- if (t) {
1002
- let n = ee(t[0]);
1003
- return { type: "html", block: true, raw: n, pre: t[1] === "pre" || t[1] === "script" || t[1] === "style", text: n };
1004
- }
1005
- }
1006
- def(e) {
1007
- let t = this.rules.block.def.exec(e);
1008
- if (t) {
1009
- let n = t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal, " "), s = t[2] ? t[2].replace(this.rules.other.hrefBrackets, "$1").replace(this.rules.inline.anyPunctuation, "$1") : "", r = t[3] ? t[3].substring(1, t[3].length - 1).replace(this.rules.inline.anyPunctuation, "$1") : t[3];
1010
- return { type: "def", tag: n, raw: $(t[0], `
1011
- `), href: s, title: r };
1012
- }
1013
- }
1014
- table(e) {
1015
- let t = this.rules.block.table.exec(e);
1016
- if (!t || !this.rules.other.tableDelimiter.test(t[2])) return;
1017
- let n = Y(t[1]), s = t[2].replace(this.rules.other.tableAlignChars, "").split("|"), r = t[3]?.trim() ? t[3].replace(this.rules.other.tableRowBlankLine, "").split(`
1018
- `) : [], i = { type: "table", raw: $(t[0], `
1019
- `), header: [], align: [], rows: [] };
1020
- if (n.length === s.length) {
1021
- for (let o of s) this.rules.other.tableAlignRight.test(o) ? i.align.push("right") : this.rules.other.tableAlignCenter.test(o) ? i.align.push("center") : this.rules.other.tableAlignLeft.test(o) ? i.align.push("left") : i.align.push(null);
1022
- for (let o = 0; o < n.length; o++) i.header.push({ text: n[o], tokens: this.lexer.inline(n[o]), header: true, align: i.align[o] });
1023
- for (let o of r) i.rows.push(Y(o, i.header.length).map((u, a) => ({ text: u, tokens: this.lexer.inline(u), header: false, align: i.align[a] })));
1024
- return i;
1025
- }
1026
- }
1027
- lheading(e) {
1028
- let t = this.rules.block.lheading.exec(e);
1029
- if (t) {
1030
- let n = t[1].trim();
1031
- return { type: "heading", raw: $(t[0], `
1032
- `), depth: t[2].charAt(0) === "=" ? 1 : 2, text: n, tokens: this.lexer.inline(n) };
1033
- }
1034
- }
1035
- paragraph(e) {
1036
- let t = this.rules.block.paragraph.exec(e);
1037
- if (t) {
1038
- let n = t[1].charAt(t[1].length - 1) === `
1039
- ` ? t[1].slice(0, -1) : t[1];
1040
- return { type: "paragraph", raw: t[0], text: n, tokens: this.lexer.inline(n) };
1041
- }
1042
- }
1043
- text(e) {
1044
- let t = this.rules.block.text.exec(e);
1045
- if (t) return { type: "text", raw: t[0], text: t[0], tokens: this.lexer.inline(t[0]) };
1046
- }
1047
- escape(e) {
1048
- let t = this.rules.inline.escape.exec(e);
1049
- if (t) return { type: "escape", raw: t[0], text: t[1] };
1050
- }
1051
- tag(e) {
1052
- let t = this.rules.inline.tag.exec(e);
1053
- if (t) return !this.lexer.state.inLink && this.rules.other.startATag.test(t[0]) ? this.lexer.state.inLink = true : this.lexer.state.inLink && this.rules.other.endATag.test(t[0]) && (this.lexer.state.inLink = false), !this.lexer.state.inRawBlock && this.rules.other.startPreScriptTag.test(t[0]) ? this.lexer.state.inRawBlock = true : this.lexer.state.inRawBlock && this.rules.other.endPreScriptTag.test(t[0]) && (this.lexer.state.inRawBlock = false), { type: "html", raw: t[0], inLink: this.lexer.state.inLink, inRawBlock: this.lexer.state.inRawBlock, block: false, text: t[0] };
1054
- }
1055
- link(e) {
1056
- let t = this.rules.inline.link.exec(e);
1057
- if (t) {
1058
- let n = t[2].trim();
1059
- if (!this.options.pedantic && this.rules.other.startAngleBracket.test(n)) {
1060
- if (!this.rules.other.endAngleBracket.test(n)) return;
1061
- let i = $(n.slice(0, -1), "\\");
1062
- if ((n.length - i.length) % 2 === 0) return;
1063
- } else {
1064
- let i = fe(t[2], "()");
1065
- if (i === -2) return;
1066
- if (i > -1) {
1067
- let u = (t[0].indexOf("!") === 0 ? 5 : 4) + t[1].length + i;
1068
- t[2] = t[2].substring(0, i), t[0] = t[0].substring(0, u).trim(), t[3] = "";
1069
- }
1070
- }
1071
- let s = t[2], r = "";
1072
- if (this.options.pedantic) {
1073
- let i = this.rules.other.pedanticHrefTitle.exec(s);
1074
- i && (s = i[1], r = i[3]);
1075
- } else r = t[3] ? t[3].slice(1, -1) : "";
1076
- return s = s.trim(), this.rules.other.startAngleBracket.test(s) && (this.options.pedantic && !this.rules.other.endAngleBracket.test(n) ? s = s.slice(1) : s = s.slice(1, -1)), xe(t, { href: s && s.replace(this.rules.inline.anyPunctuation, "$1"), title: r && r.replace(this.rules.inline.anyPunctuation, "$1") }, t[0], this.lexer, this.rules);
1077
- }
1078
- }
1079
- reflink(e, t) {
1080
- let n;
1081
- if ((n = this.rules.inline.reflink.exec(e)) || (n = this.rules.inline.nolink.exec(e))) {
1082
- let s = (n[2] || n[1]).replace(this.rules.other.multipleSpaceGlobal, " "), r = t[s.toLowerCase()];
1083
- if (!r) {
1084
- let i = n[0].charAt(0);
1085
- return { type: "text", raw: i, text: i };
1086
- }
1087
- return xe(n, r, n[0], this.lexer, this.rules);
1088
- }
1089
- }
1090
- emStrong(e, t, n = "") {
1091
- let s = this.rules.inline.emStrongLDelim.exec(e);
1092
- if (!s || !s[1] && !s[2] && !s[3] && !s[4] || s[4] && n.match(this.rules.other.unicodeAlphaNumeric)) return;
1093
- if (!(s[1] || s[3] || "") || !n || this.rules.inline.punctuation.exec(n)) {
1094
- let i = [...s[0]].length - 1, o, u, a = i, c = 0, p = s[0][0] === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
1095
- for (p.lastIndex = 0, t = t.slice(-1 * e.length + i); (s = p.exec(t)) !== null; ) {
1096
- if (o = s[1] || s[2] || s[3] || s[4] || s[5] || s[6], !o) continue;
1097
- if (u = [...o].length, s[3] || s[4]) {
1098
- a += u;
1099
- continue;
1100
- } else if ((s[5] || s[6]) && i % 3 && !((i + u) % 3)) {
1101
- c += u;
1102
- continue;
1103
- }
1104
- if (a -= u, a > 0) continue;
1105
- u = Math.min(u, u + a + c);
1106
- let k = [...s[0]][0].length, h = e.slice(0, i + s.index + k + u);
1107
- if (Math.min(i, u) % 2) {
1108
- let f = h.slice(1, -1);
1109
- return { type: "em", raw: h, text: f, tokens: this.lexer.inlineTokens(f) };
1110
- }
1111
- let R = h.slice(2, -2);
1112
- return { type: "strong", raw: h, text: R, tokens: this.lexer.inlineTokens(R) };
1113
- }
1114
- }
1115
- }
1116
- codespan(e) {
1117
- let t = this.rules.inline.code.exec(e);
1118
- if (t) {
1119
- let n = t[2].replace(this.rules.other.newLineCharGlobal, " "), s = this.rules.other.nonSpaceChar.test(n), r = this.rules.other.startingSpaceChar.test(n) && this.rules.other.endingSpaceChar.test(n);
1120
- return s && r && (n = n.substring(1, n.length - 1)), { type: "codespan", raw: t[0], text: n };
1121
- }
1122
- }
1123
- br(e) {
1124
- let t = this.rules.inline.br.exec(e);
1125
- if (t) return { type: "br", raw: t[0] };
1126
- }
1127
- del(e, t, n = "") {
1128
- let s = this.rules.inline.delLDelim.exec(e);
1129
- if (!s) return;
1130
- if (!(s[1] || "") || !n || this.rules.inline.punctuation.exec(n)) {
1131
- let i = [...s[0]].length - 1, o, u, a = i, c = this.rules.inline.delRDelim;
1132
- for (c.lastIndex = 0, t = t.slice(-1 * e.length + i); (s = c.exec(t)) !== null; ) {
1133
- if (o = s[1] || s[2] || s[3] || s[4] || s[5] || s[6], !o || (u = [...o].length, u !== i)) continue;
1134
- if (s[3] || s[4]) {
1135
- a += u;
1136
- continue;
1137
- }
1138
- if (a -= u, a > 0) continue;
1139
- u = Math.min(u, u + a);
1140
- let p = [...s[0]][0].length, k = e.slice(0, i + s.index + p + u), h = k.slice(i, -i);
1141
- return { type: "del", raw: k, text: h, tokens: this.lexer.inlineTokens(h) };
1142
- }
1143
- }
1144
- }
1145
- autolink(e) {
1146
- let t = this.rules.inline.autolink.exec(e);
1147
- if (t) {
1148
- let n, s;
1149
- return t[2] === "@" ? (n = t[1], s = "mailto:" + n) : (n = t[1], s = n), { type: "link", raw: t[0], text: n, href: s, tokens: [{ type: "text", raw: n, text: n }] };
1150
- }
1151
- }
1152
- url(e) {
1153
- let t;
1154
- if (t = this.rules.inline.url.exec(e)) {
1155
- let n, s;
1156
- if (t[2] === "@") n = t[0], s = "mailto:" + n;
1157
- else {
1158
- let r;
1159
- do
1160
- r = t[0], t[0] = this.rules.inline._backpedal.exec(t[0])?.[0] ?? "";
1161
- while (r !== t[0]);
1162
- n = t[0], t[1] === "www." ? s = "http://" + t[0] : s = t[0];
1163
- }
1164
- return { type: "link", raw: t[0], text: n, href: s, tokens: [{ type: "text", raw: n, text: n }] };
1165
- }
1166
- }
1167
- inlineText(e) {
1168
- let t = this.rules.inline.text.exec(e);
1169
- if (t) {
1170
- let n = this.lexer.state.inRawBlock;
1171
- return { type: "text", raw: t[0], text: t[0], escaped: n };
1172
- }
1173
- }
1174
- };
1175
- var x = class l {
1176
- tokens;
1177
- options;
1178
- state;
1179
- inlineQueue;
1180
- tokenizer;
1181
- constructor(e) {
1182
- this.tokens = [], this.tokens.links = /* @__PURE__ */ Object.create(null), this.options = e || T, this.options.tokenizer = this.options.tokenizer || new w(), this.tokenizer = this.options.tokenizer, this.tokenizer.options = this.options, this.tokenizer.lexer = this, this.inlineQueue = [], this.state = { inLink: false, inRawBlock: false, top: true };
1183
- let t = { other: m, block: q.normal, inline: A.normal };
1184
- this.options.pedantic ? (t.block = q.pedantic, t.inline = A.pedantic) : this.options.gfm && (t.block = q.gfm, this.options.breaks ? t.inline = A.breaks : t.inline = A.gfm), this.tokenizer.rules = t;
1185
- }
1186
- static get rules() {
1187
- return { block: q, inline: A };
1188
- }
1189
- static lex(e, t) {
1190
- return new l(t).lex(e);
1191
- }
1192
- static lexInline(e, t) {
1193
- return new l(t).inlineTokens(e);
1194
- }
1195
- lex(e) {
1196
- e = e.replace(m.carriageReturn, `
1197
- `), this.blockTokens(e, this.tokens);
1198
- for (let t = 0; t < this.inlineQueue.length; t++) {
1199
- let n = this.inlineQueue[t];
1200
- this.inlineTokens(n.src, n.tokens);
1201
- }
1202
- return this.inlineQueue = [], this.tokens;
1203
- }
1204
- blockTokens(e, t = [], n = false) {
1205
- this.tokenizer.lexer = this, this.options.pedantic && (e = e.replace(m.tabCharGlobal, " ").replace(m.spaceLine, ""));
1206
- let s = 1 / 0;
1207
- for (; e; ) {
1208
- if (e.length < s) s = e.length;
1209
- else {
1210
- this.infiniteLoopError(e.charCodeAt(0));
1211
- break;
1212
- }
1213
- let r;
1214
- if (this.options.extensions?.block?.some((o) => (r = o.call({ lexer: this }, e, t)) ? (e = e.substring(r.raw.length), t.push(r), true) : false)) continue;
1215
- if (r = this.tokenizer.space(e)) {
1216
- e = e.substring(r.raw.length);
1217
- let o = t.at(-1);
1218
- r.raw.length === 1 && o !== void 0 ? o.raw += `
1219
- ` : t.push(r);
1220
- continue;
1221
- }
1222
- if (r = this.tokenizer.code(e)) {
1223
- e = e.substring(r.raw.length);
1224
- let o = t.at(-1);
1225
- o?.type === "paragraph" || o?.type === "text" ? (o.raw += (o.raw.endsWith(`
1226
- `) ? "" : `
1227
- `) + r.raw, o.text += `
1228
- ` + r.text, this.inlineQueue.at(-1).src = o.text) : t.push(r);
1229
- continue;
1230
- }
1231
- if (r = this.tokenizer.fences(e)) {
1232
- e = e.substring(r.raw.length), t.push(r);
1233
- continue;
1234
- }
1235
- if (r = this.tokenizer.heading(e)) {
1236
- e = e.substring(r.raw.length), t.push(r);
1237
- continue;
1238
- }
1239
- if (r = this.tokenizer.hr(e)) {
1240
- e = e.substring(r.raw.length), t.push(r);
1241
- continue;
1242
- }
1243
- if (r = this.tokenizer.blockquote(e)) {
1244
- e = e.substring(r.raw.length), t.push(r);
1245
- continue;
1246
- }
1247
- if (r = this.tokenizer.list(e)) {
1248
- e = e.substring(r.raw.length), t.push(r);
1249
- continue;
1250
- }
1251
- if (r = this.tokenizer.html(e)) {
1252
- e = e.substring(r.raw.length), t.push(r);
1253
- continue;
1254
- }
1255
- if (r = this.tokenizer.def(e)) {
1256
- e = e.substring(r.raw.length);
1257
- let o = t.at(-1);
1258
- o?.type === "paragraph" || o?.type === "text" ? (o.raw += (o.raw.endsWith(`
1259
- `) ? "" : `
1260
- `) + r.raw, o.text += `
1261
- ` + r.raw, this.inlineQueue.at(-1).src = o.text) : this.tokens.links[r.tag] || (this.tokens.links[r.tag] = { href: r.href, title: r.title }, t.push(r));
1262
- continue;
1263
- }
1264
- if (r = this.tokenizer.table(e)) {
1265
- e = e.substring(r.raw.length), t.push(r);
1266
- continue;
1267
- }
1268
- if (r = this.tokenizer.lheading(e)) {
1269
- e = e.substring(r.raw.length), t.push(r);
1270
- continue;
1271
- }
1272
- let i = e;
1273
- if (this.options.extensions?.startBlock) {
1274
- let o = 1 / 0, u = e.slice(1), a;
1275
- this.options.extensions.startBlock.forEach((c) => {
1276
- a = c.call({ lexer: this }, u), typeof a == "number" && a >= 0 && (o = Math.min(o, a));
1277
- }), o < 1 / 0 && o >= 0 && (i = e.substring(0, o + 1));
1278
- }
1279
- if (this.state.top && (r = this.tokenizer.paragraph(i))) {
1280
- let o = t.at(-1);
1281
- n && o?.type === "paragraph" ? (o.raw += (o.raw.endsWith(`
1282
- `) ? "" : `
1283
- `) + r.raw, o.text += `
1284
- ` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = o.text) : t.push(r), n = i.length !== e.length, e = e.substring(r.raw.length);
1285
- continue;
1286
- }
1287
- if (r = this.tokenizer.text(e)) {
1288
- e = e.substring(r.raw.length);
1289
- let o = t.at(-1);
1290
- o?.type === "text" ? (o.raw += (o.raw.endsWith(`
1291
- `) ? "" : `
1292
- `) + r.raw, o.text += `
1293
- ` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = o.text) : t.push(r);
1294
- continue;
1295
- }
1296
- if (e) {
1297
- this.infiniteLoopError(e.charCodeAt(0));
1298
- break;
1299
- }
1300
- }
1301
- return this.state.top = true, t;
1302
- }
1303
- inline(e, t = []) {
1304
- return this.inlineQueue.push({ src: e, tokens: t }), t;
1305
- }
1306
- inlineTokens(e, t = []) {
1307
- this.tokenizer.lexer = this;
1308
- let n = e, s = null;
1309
- if (this.tokens.links) {
1310
- let a = Object.keys(this.tokens.links);
1311
- if (a.length > 0) for (; (s = this.tokenizer.rules.inline.reflinkSearch.exec(n)) !== null; ) a.includes(s[0].slice(s[0].lastIndexOf("[") + 1, -1)) && (n = n.slice(0, s.index) + "[" + "a".repeat(s[0].length - 2) + "]" + n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex));
1312
- }
1313
- for (; (s = this.tokenizer.rules.inline.anyPunctuation.exec(n)) !== null; ) n = n.slice(0, s.index) + "++" + n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
1314
- let r;
1315
- for (; (s = this.tokenizer.rules.inline.blockSkip.exec(n)) !== null; ) r = s[2] ? s[2].length : 0, n = n.slice(0, s.index + r) + "[" + "a".repeat(s[0].length - r - 2) + "]" + n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
1316
- n = this.options.hooks?.emStrongMask?.call({ lexer: this }, n) ?? n;
1317
- let i = false, o = "", u = 1 / 0;
1318
- for (; e; ) {
1319
- if (e.length < u) u = e.length;
1320
- else {
1321
- this.infiniteLoopError(e.charCodeAt(0));
1322
- break;
1323
- }
1324
- i || (o = ""), i = false;
1325
- let a;
1326
- if (this.options.extensions?.inline?.some((p) => (a = p.call({ lexer: this }, e, t)) ? (e = e.substring(a.raw.length), t.push(a), true) : false)) continue;
1327
- if (a = this.tokenizer.escape(e)) {
1328
- e = e.substring(a.raw.length), t.push(a);
1329
- continue;
1330
- }
1331
- if (a = this.tokenizer.tag(e)) {
1332
- e = e.substring(a.raw.length), t.push(a);
1333
- continue;
1334
- }
1335
- if (a = this.tokenizer.link(e)) {
1336
- e = e.substring(a.raw.length), t.push(a);
1337
- continue;
1338
- }
1339
- if (a = this.tokenizer.reflink(e, this.tokens.links)) {
1340
- e = e.substring(a.raw.length);
1341
- let p = t.at(-1);
1342
- a.type === "text" && p?.type === "text" ? (p.raw += a.raw, p.text += a.text) : t.push(a);
1343
- continue;
1344
- }
1345
- if (a = this.tokenizer.emStrong(e, n, o)) {
1346
- e = e.substring(a.raw.length), t.push(a);
1347
- continue;
1348
- }
1349
- if (a = this.tokenizer.codespan(e)) {
1350
- e = e.substring(a.raw.length), t.push(a);
1351
- continue;
1352
- }
1353
- if (a = this.tokenizer.br(e)) {
1354
- e = e.substring(a.raw.length), t.push(a);
1355
- continue;
1356
- }
1357
- if (a = this.tokenizer.del(e, n, o)) {
1358
- e = e.substring(a.raw.length), t.push(a);
1359
- continue;
1360
- }
1361
- if (a = this.tokenizer.autolink(e)) {
1362
- e = e.substring(a.raw.length), t.push(a);
1363
- continue;
1364
- }
1365
- if (!this.state.inLink && (a = this.tokenizer.url(e))) {
1366
- e = e.substring(a.raw.length), t.push(a);
1367
- continue;
1368
- }
1369
- let c = e;
1370
- if (this.options.extensions?.startInline) {
1371
- let p = 1 / 0, k = e.slice(1), h;
1372
- this.options.extensions.startInline.forEach((R) => {
1373
- h = R.call({ lexer: this }, k), typeof h == "number" && h >= 0 && (p = Math.min(p, h));
1374
- }), p < 1 / 0 && p >= 0 && (c = e.substring(0, p + 1));
1375
- }
1376
- if (a = this.tokenizer.inlineText(c)) {
1377
- e = e.substring(a.raw.length), a.raw.slice(-1) !== "_" && (o = a.raw.slice(-1)), i = true;
1378
- let p = t.at(-1);
1379
- p?.type === "text" ? (p.raw += a.raw, p.text += a.text) : t.push(a);
1380
- continue;
1381
- }
1382
- if (e) {
1383
- this.infiniteLoopError(e.charCodeAt(0));
1384
- break;
1385
- }
1386
- }
1387
- return t;
1388
- }
1389
- infiniteLoopError(e) {
1390
- let t = "Infinite loop on byte: " + e;
1391
- if (this.options.silent) console.error(t);
1392
- else throw new Error(t);
1393
- }
1394
- };
1395
- var y = class {
1396
- options;
1397
- parser;
1398
- constructor(e) {
1399
- this.options = e || T;
1400
- }
1401
- space(e) {
1402
- return "";
1403
- }
1404
- code({ text: e, lang: t, escaped: n }) {
1405
- let s = (t || "").match(m.notSpaceStart)?.[0], r = e.replace(m.endingNewline, "") + `
1406
- `;
1407
- return s ? '<pre><code class="language-' + O(s) + '">' + (n ? r : O(r, true)) + `</code></pre>
1408
- ` : "<pre><code>" + (n ? r : O(r, true)) + `</code></pre>
1409
- `;
1410
- }
1411
- blockquote({ tokens: e }) {
1412
- return `<blockquote>
1413
- ${this.parser.parse(e)}</blockquote>
1414
- `;
1415
- }
1416
- html({ text: e }) {
1417
- return e;
1418
- }
1419
- def(e) {
1420
- return "";
1421
- }
1422
- heading({ tokens: e, depth: t }) {
1423
- return `<h${t}>${this.parser.parseInline(e)}</h${t}>
1424
- `;
1425
- }
1426
- hr(e) {
1427
- return `<hr>
1428
- `;
1429
- }
1430
- list(e) {
1431
- let t = e.ordered, n = e.start, s = "";
1432
- for (let o = 0; o < e.items.length; o++) {
1433
- let u = e.items[o];
1434
- s += this.listitem(u);
1435
- }
1436
- let r = t ? "ol" : "ul", i = t && n !== 1 ? ' start="' + n + '"' : "";
1437
- return "<" + r + i + `>
1438
- ` + s + "</" + r + `>
1439
- `;
1440
- }
1441
- listitem(e) {
1442
- return `<li>${this.parser.parse(e.tokens)}</li>
1443
- `;
1444
- }
1445
- checkbox({ checked: e }) {
1446
- return "<input " + (e ? 'checked="" ' : "") + 'disabled="" type="checkbox"> ';
1447
- }
1448
- paragraph({ tokens: e }) {
1449
- return `<p>${this.parser.parseInline(e)}</p>
1450
- `;
1451
- }
1452
- table(e) {
1453
- let t = "", n = "";
1454
- for (let r = 0; r < e.header.length; r++) n += this.tablecell(e.header[r]);
1455
- t += this.tablerow({ text: n });
1456
- let s = "";
1457
- for (let r = 0; r < e.rows.length; r++) {
1458
- let i = e.rows[r];
1459
- n = "";
1460
- for (let o = 0; o < i.length; o++) n += this.tablecell(i[o]);
1461
- s += this.tablerow({ text: n });
1462
- }
1463
- return s && (s = `<tbody>${s}</tbody>`), `<table>
1464
- <thead>
1465
- ` + t + `</thead>
1466
- ` + s + `</table>
1467
- `;
1468
- }
1469
- tablerow({ text: e }) {
1470
- return `<tr>
1471
- ${e}</tr>
1472
- `;
1473
- }
1474
- tablecell(e) {
1475
- let t = this.parser.parseInline(e.tokens), n = e.header ? "th" : "td";
1476
- return (e.align ? `<${n} align="${e.align}">` : `<${n}>`) + t + `</${n}>
1477
- `;
1478
- }
1479
- strong({ tokens: e }) {
1480
- return `<strong>${this.parser.parseInline(e)}</strong>`;
1481
- }
1482
- em({ tokens: e }) {
1483
- return `<em>${this.parser.parseInline(e)}</em>`;
1484
- }
1485
- codespan({ text: e }) {
1486
- return `<code>${O(e, true)}</code>`;
1487
- }
1488
- br(e) {
1489
- return "<br>";
1490
- }
1491
- del({ tokens: e }) {
1492
- return `<del>${this.parser.parseInline(e)}</del>`;
1493
- }
1494
- link({ href: e, title: t, tokens: n }) {
1495
- let s = this.parser.parseInline(n), r = V(e);
1496
- if (r === null) return s;
1497
- e = r;
1498
- let i = '<a href="' + e + '"';
1499
- return t && (i += ' title="' + O(t) + '"'), i += ">" + s + "</a>", i;
1500
- }
1501
- image({ href: e, title: t, text: n, tokens: s }) {
1502
- s && (n = this.parser.parseInline(s, this.parser.textRenderer));
1503
- let r = V(e);
1504
- if (r === null) return O(n);
1505
- e = r;
1506
- let i = `<img src="${e}" alt="${O(n)}"`;
1507
- return t && (i += ` title="${O(t)}"`), i += ">", i;
1508
- }
1509
- text(e) {
1510
- return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : "escaped" in e && e.escaped ? e.text : O(e.text);
1511
- }
1512
- };
1513
- var L = class {
1514
- strong({ text: e }) {
1515
- return e;
1516
- }
1517
- em({ text: e }) {
1518
- return e;
1519
- }
1520
- codespan({ text: e }) {
1521
- return e;
1522
- }
1523
- del({ text: e }) {
1524
- return e;
1525
- }
1526
- html({ text: e }) {
1527
- return e;
1528
- }
1529
- text({ text: e }) {
1530
- return e;
1531
- }
1532
- link({ text: e }) {
1533
- return "" + e;
1534
- }
1535
- image({ text: e }) {
1536
- return "" + e;
1537
- }
1538
- br() {
1539
- return "";
1540
- }
1541
- checkbox({ raw: e }) {
1542
- return e;
1543
- }
1544
- };
1545
- var b = class l2 {
1546
- options;
1547
- renderer;
1548
- textRenderer;
1549
- constructor(e) {
1550
- this.options = e || T, this.options.renderer = this.options.renderer || new y(), this.renderer = this.options.renderer, this.renderer.options = this.options, this.renderer.parser = this, this.textRenderer = new L();
1551
- }
1552
- static parse(e, t) {
1553
- return new l2(t).parse(e);
1554
- }
1555
- static parseInline(e, t) {
1556
- return new l2(t).parseInline(e);
1557
- }
1558
- parse(e) {
1559
- this.renderer.parser = this;
1560
- let t = "";
1561
- for (let n = 0; n < e.length; n++) {
1562
- let s = e[n];
1563
- if (this.options.extensions?.renderers?.[s.type]) {
1564
- let i = s, o = this.options.extensions.renderers[i.type].call({ parser: this }, i);
1565
- if (o !== false || !["space", "hr", "heading", "code", "table", "blockquote", "list", "html", "def", "paragraph", "text"].includes(i.type)) {
1566
- t += o || "";
1567
- continue;
1568
- }
1569
- }
1570
- let r = s;
1571
- switch (r.type) {
1572
- case "space": {
1573
- t += this.renderer.space(r);
1574
- break;
1575
- }
1576
- case "hr": {
1577
- t += this.renderer.hr(r);
1578
- break;
1579
- }
1580
- case "heading": {
1581
- t += this.renderer.heading(r);
1582
- break;
1583
- }
1584
- case "code": {
1585
- t += this.renderer.code(r);
1586
- break;
1587
- }
1588
- case "table": {
1589
- t += this.renderer.table(r);
1590
- break;
1591
- }
1592
- case "blockquote": {
1593
- t += this.renderer.blockquote(r);
1594
- break;
1595
- }
1596
- case "list": {
1597
- t += this.renderer.list(r);
1598
- break;
1599
- }
1600
- case "checkbox": {
1601
- t += this.renderer.checkbox(r);
1602
- break;
1603
- }
1604
- case "html": {
1605
- t += this.renderer.html(r);
1606
- break;
1607
- }
1608
- case "def": {
1609
- t += this.renderer.def(r);
1610
- break;
1611
- }
1612
- case "paragraph": {
1613
- t += this.renderer.paragraph(r);
1614
- break;
1615
- }
1616
- case "text": {
1617
- t += this.renderer.text(r);
1618
- break;
1619
- }
1620
- default: {
1621
- let i = 'Token with "' + r.type + '" type was not found.';
1622
- if (this.options.silent) return console.error(i), "";
1623
- throw new Error(i);
1624
- }
1625
- }
1626
- }
1627
- return t;
1628
- }
1629
- parseInline(e, t = this.renderer) {
1630
- this.renderer.parser = this;
1631
- let n = "";
1632
- for (let s = 0; s < e.length; s++) {
1633
- let r = e[s];
1634
- if (this.options.extensions?.renderers?.[r.type]) {
1635
- let o = this.options.extensions.renderers[r.type].call({ parser: this }, r);
1636
- if (o !== false || !["escape", "html", "link", "image", "strong", "em", "codespan", "br", "del", "text"].includes(r.type)) {
1637
- n += o || "";
1638
- continue;
1639
- }
1640
- }
1641
- let i = r;
1642
- switch (i.type) {
1643
- case "escape": {
1644
- n += t.text(i);
1645
- break;
1646
- }
1647
- case "html": {
1648
- n += t.html(i);
1649
- break;
1650
- }
1651
- case "link": {
1652
- n += t.link(i);
1653
- break;
1654
- }
1655
- case "image": {
1656
- n += t.image(i);
1657
- break;
1658
- }
1659
- case "checkbox": {
1660
- n += t.checkbox(i);
1661
- break;
1662
- }
1663
- case "strong": {
1664
- n += t.strong(i);
1665
- break;
1666
- }
1667
- case "em": {
1668
- n += t.em(i);
1669
- break;
1670
- }
1671
- case "codespan": {
1672
- n += t.codespan(i);
1673
- break;
1674
- }
1675
- case "br": {
1676
- n += t.br(i);
1677
- break;
1678
- }
1679
- case "del": {
1680
- n += t.del(i);
1681
- break;
1682
- }
1683
- case "text": {
1684
- n += t.text(i);
1685
- break;
1686
- }
1687
- default: {
1688
- let o = 'Token with "' + i.type + '" type was not found.';
1689
- if (this.options.silent) return console.error(o), "";
1690
- throw new Error(o);
1691
- }
1692
- }
1693
- }
1694
- return n;
1695
- }
1696
- };
1697
- var P = class {
1698
- options;
1699
- block;
1700
- constructor(e) {
1701
- this.options = e || T;
1702
- }
1703
- static passThroughHooks = /* @__PURE__ */ new Set(["preprocess", "postprocess", "processAllTokens", "emStrongMask"]);
1704
- static passThroughHooksRespectAsync = /* @__PURE__ */ new Set(["preprocess", "postprocess", "processAllTokens"]);
1705
- preprocess(e) {
1706
- return e;
1707
- }
1708
- postprocess(e) {
1709
- return e;
1710
- }
1711
- processAllTokens(e) {
1712
- return e;
1713
- }
1714
- emStrongMask(e) {
1715
- return e;
1716
- }
1717
- provideLexer(e = this.block) {
1718
- return e ? x.lex : x.lexInline;
1719
- }
1720
- provideParser(e = this.block) {
1721
- return e ? b.parse : b.parseInline;
1722
- }
1723
- };
1724
- var D = class {
1725
- defaults = M();
1726
- options = this.setOptions;
1727
- parse = this.parseMarkdown(true);
1728
- parseInline = this.parseMarkdown(false);
1729
- Parser = b;
1730
- Renderer = y;
1731
- TextRenderer = L;
1732
- Lexer = x;
1733
- Tokenizer = w;
1734
- Hooks = P;
1735
- constructor(...e) {
1736
- this.use(...e);
1737
- }
1738
- walkTokens(e, t) {
1739
- let n = [];
1740
- for (let s of e) switch (n = n.concat(t.call(this, s)), s.type) {
1741
- case "table": {
1742
- let r = s;
1743
- for (let i of r.header) n = n.concat(this.walkTokens(i.tokens, t));
1744
- for (let i of r.rows) for (let o of i) n = n.concat(this.walkTokens(o.tokens, t));
1745
- break;
1746
- }
1747
- case "list": {
1748
- let r = s;
1749
- n = n.concat(this.walkTokens(r.items, t));
1750
- break;
1751
- }
1752
- default: {
1753
- let r = s;
1754
- this.defaults.extensions?.childTokens?.[r.type] ? this.defaults.extensions.childTokens[r.type].forEach((i) => {
1755
- let o = r[i].flat(1 / 0);
1756
- n = n.concat(this.walkTokens(o, t));
1757
- }) : r.tokens && (n = n.concat(this.walkTokens(r.tokens, t)));
1758
- }
1759
- }
1760
- return n;
1761
- }
1762
- use(...e) {
1763
- let t = this.defaults.extensions || { renderers: {}, childTokens: {} };
1764
- return e.forEach((n) => {
1765
- let s = { ...n };
1766
- if (s.async = this.defaults.async || s.async || false, n.extensions && (n.extensions.forEach((r) => {
1767
- if (!r.name) throw new Error("extension name required");
1768
- if ("renderer" in r) {
1769
- let i = t.renderers[r.name];
1770
- i ? t.renderers[r.name] = function(...o) {
1771
- let u = r.renderer.apply(this, o);
1772
- return u === false && (u = i.apply(this, o)), u;
1773
- } : t.renderers[r.name] = r.renderer;
1774
- }
1775
- if ("tokenizer" in r) {
1776
- if (!r.level || r.level !== "block" && r.level !== "inline") throw new Error("extension level must be 'block' or 'inline'");
1777
- let i = t[r.level];
1778
- i ? i.unshift(r.tokenizer) : t[r.level] = [r.tokenizer], r.start && (r.level === "block" ? t.startBlock ? t.startBlock.push(r.start) : t.startBlock = [r.start] : r.level === "inline" && (t.startInline ? t.startInline.push(r.start) : t.startInline = [r.start]));
1779
- }
1780
- "childTokens" in r && r.childTokens && (t.childTokens[r.name] = r.childTokens);
1781
- }), s.extensions = t), n.renderer) {
1782
- let r = this.defaults.renderer || new y(this.defaults);
1783
- for (let i in n.renderer) {
1784
- if (!(i in r)) throw new Error(`renderer '${i}' does not exist`);
1785
- if (["options", "parser"].includes(i)) continue;
1786
- let o = i, u = n.renderer[o], a = r[o];
1787
- r[o] = (...c) => {
1788
- let p = u.apply(r, c);
1789
- return p === false && (p = a.apply(r, c)), p || "";
1790
- };
1791
- }
1792
- s.renderer = r;
1793
- }
1794
- if (n.tokenizer) {
1795
- let r = this.defaults.tokenizer || new w(this.defaults);
1796
- for (let i in n.tokenizer) {
1797
- if (!(i in r)) throw new Error(`tokenizer '${i}' does not exist`);
1798
- if (["options", "rules", "lexer"].includes(i)) continue;
1799
- let o = i, u = n.tokenizer[o], a = r[o];
1800
- r[o] = (...c) => {
1801
- let p = u.apply(r, c);
1802
- return p === false && (p = a.apply(r, c)), p;
1803
- };
1804
- }
1805
- s.tokenizer = r;
1806
- }
1807
- if (n.hooks) {
1808
- let r = this.defaults.hooks || new P();
1809
- for (let i in n.hooks) {
1810
- if (!(i in r)) throw new Error(`hook '${i}' does not exist`);
1811
- if (["options", "block"].includes(i)) continue;
1812
- let o = i, u = n.hooks[o], a = r[o];
1813
- P.passThroughHooks.has(i) ? r[o] = (c) => {
1814
- if (this.defaults.async && P.passThroughHooksRespectAsync.has(i)) return (async () => {
1815
- let k = await u.call(r, c);
1816
- return a.call(r, k);
1817
- })();
1818
- let p = u.call(r, c);
1819
- return a.call(r, p);
1820
- } : r[o] = (...c) => {
1821
- if (this.defaults.async) return (async () => {
1822
- let k = await u.apply(r, c);
1823
- return k === false && (k = await a.apply(r, c)), k;
1824
- })();
1825
- let p = u.apply(r, c);
1826
- return p === false && (p = a.apply(r, c)), p;
1827
- };
1828
- }
1829
- s.hooks = r;
1830
- }
1831
- if (n.walkTokens) {
1832
- let r = this.defaults.walkTokens, i = n.walkTokens;
1833
- s.walkTokens = function(o) {
1834
- let u = [];
1835
- return u.push(i.call(this, o)), r && (u = u.concat(r.call(this, o))), u;
1836
- };
1837
- }
1838
- this.defaults = { ...this.defaults, ...s };
1839
- }), this;
1840
- }
1841
- setOptions(e) {
1842
- return this.defaults = { ...this.defaults, ...e }, this;
1843
- }
1844
- lexer(e, t) {
1845
- return x.lex(e, t ?? this.defaults);
1846
- }
1847
- parser(e, t) {
1848
- return b.parse(e, t ?? this.defaults);
1849
- }
1850
- parseMarkdown(e) {
1851
- return (n, s) => {
1852
- let r = { ...s }, i = { ...this.defaults, ...r }, o = this.onError(!!i.silent, !!i.async);
1853
- if (this.defaults.async === true && r.async === false) return o(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));
1854
- if (typeof n > "u" || n === null) return o(new Error("marked(): input parameter is undefined or null"));
1855
- if (typeof n != "string") return o(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(n) + ", string expected"));
1856
- if (i.hooks && (i.hooks.options = i, i.hooks.block = e), i.async) return (async () => {
1857
- let u = i.hooks ? await i.hooks.preprocess(n) : n, c = await (i.hooks ? await i.hooks.provideLexer(e) : e ? x.lex : x.lexInline)(u, i), p = i.hooks ? await i.hooks.processAllTokens(c) : c;
1858
- i.walkTokens && await Promise.all(this.walkTokens(p, i.walkTokens));
1859
- let h = await (i.hooks ? await i.hooks.provideParser(e) : e ? b.parse : b.parseInline)(p, i);
1860
- return i.hooks ? await i.hooks.postprocess(h) : h;
1861
- })().catch(o);
1862
- try {
1863
- i.hooks && (n = i.hooks.preprocess(n));
1864
- let a = (i.hooks ? i.hooks.provideLexer(e) : e ? x.lex : x.lexInline)(n, i);
1865
- i.hooks && (a = i.hooks.processAllTokens(a)), i.walkTokens && this.walkTokens(a, i.walkTokens);
1866
- let p = (i.hooks ? i.hooks.provideParser(e) : e ? b.parse : b.parseInline)(a, i);
1867
- return i.hooks && (p = i.hooks.postprocess(p)), p;
1868
- } catch (u) {
1869
- return o(u);
1870
- }
1871
- };
1872
- }
1873
- onError(e, t) {
1874
- return (n) => {
1875
- if (n.message += `
1876
- Please report this to https://github.com/markedjs/marked.`, e) {
1877
- let s = "<p>An error occurred:</p><pre>" + O(n.message + "", true) + "</pre>";
1878
- return t ? Promise.resolve(s) : s;
1879
- }
1880
- if (t) return Promise.reject(n);
1881
- throw n;
1882
- };
1883
- }
1884
- };
1885
- var z = new D();
1886
- function g(l3, e) {
1887
- return z.parse(l3, e);
1888
- }
1889
- g.options = g.setOptions = function(l3) {
1890
- return z.setOptions(l3), g.defaults = z.defaults, N(g.defaults), g;
1891
- };
1892
- g.getDefaults = M;
1893
- g.defaults = T;
1894
- g.use = function(...l3) {
1895
- return z.use(...l3), g.defaults = z.defaults, N(g.defaults), g;
1896
- };
1897
- g.walkTokens = function(l3, e) {
1898
- return z.walkTokens(l3, e);
1899
- };
1900
- g.parseInline = z.parseInline;
1901
- g.Parser = b;
1902
- g.parser = b.parse;
1903
- g.Renderer = y;
1904
- g.TextRenderer = L;
1905
- g.Lexer = x;
1906
- g.lexer = x.lex;
1907
- g.Tokenizer = w;
1908
- g.Hooks = P;
1909
- g.parse = g;
1910
- var Kt = g.options;
1911
- var Wt = g.setOptions;
1912
- var Xt = g.use;
1913
- var Jt = g.walkTokens;
1914
- var Vt = g.parseInline;
1915
- var en = b.parse;
1916
- var tn = x.lex;
1917
-
1918
- // packages/extensions/pages/src/markdown.ts
1919
- var marked = new D({ gfm: true });
1920
- var BASE_STYLES = `
1921
- *, *::before, *::after { box-sizing: border-box; }
1922
- body {
1923
- max-width: 48rem;
1924
- margin: 2rem auto;
1925
- padding: 0 1rem;
1926
- font-family: system-ui, -apple-system, sans-serif;
1927
- line-height: 1.6;
1928
- color: #1a1a1a;
1929
- }
1930
- h1, h2, h3, h4, h5, h6 { margin-top: 1.5em; margin-bottom: 0.5em; line-height: 1.3; }
1931
- h1 { font-size: 2em; }
1932
- a { color: #2563eb; }
1933
- code {
1934
- font-family: ui-monospace, "SFMono-Regular", monospace;
1935
- font-size: 0.9em;
1936
- background: #f3f4f6;
1937
- padding: 0.15em 0.3em;
1938
- border-radius: 3px;
1939
- }
1940
- pre {
1941
- background: #f3f4f6;
1942
- padding: 1em;
1943
- border-radius: 6px;
1944
- overflow-x: auto;
1945
- }
1946
- pre code { background: none; padding: 0; }
1947
- blockquote {
1948
- border-left: 3px solid #d1d5db;
1949
- margin-left: 0;
1950
- padding-left: 1em;
1951
- color: #4b5563;
1952
- }
1953
- table { border-collapse: collapse; width: 100%; }
1954
- th, td { border: 1px solid #d1d5db; padding: 0.5em 0.75em; text-align: left; }
1955
- th { background: #f9fafb; }
1956
- img { max-width: 100%; height: auto; }
1957
- hr { border: none; border-top: 1px solid #d1d5db; margin: 2em 0; }
1958
- `;
1959
- function escapeHtml(s) {
1960
- return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
1961
- }
1962
- function parseFrontmatter(raw) {
1963
- const match = raw.match(/^---\n([\s\S]*?)\n---\n?/);
1964
- if (!match) return { body: raw };
1965
- const block = match[1];
1966
- const body = raw.slice(match[0].length);
1967
- const titleMatch = block.match(/^title:\s*(.+)$/m);
1968
- const styleMatch = block.match(/^style:\s*(.+)$/m);
1969
- return {
1970
- title: titleMatch?.[1].trim(),
1971
- style: styleMatch?.[1].trim(),
1972
- body
1973
- };
1974
- }
1975
- function resolveStylesheet(mdFilePath, pagesRoot, frontmatterStyle) {
1976
- if (frontmatterStyle) {
1977
- const abs = resolve3(pagesRoot, frontmatterStyle);
1978
- if (abs.startsWith(pagesRoot + "/") && existsSync3(abs)) return frontmatterStyle;
1979
- }
1980
- const dir = dirname(mdFilePath);
1981
- const localCss = resolve3(dir, "style.css");
1982
- if (existsSync3(localCss)) return relative3(pagesRoot, localCss);
1983
- if (dir !== pagesRoot) {
1984
- const rootCss = resolve3(pagesRoot, "style.css");
1985
- if (existsSync3(rootCss)) return "style.css";
1986
- }
1987
- return null;
1988
- }
1989
- async function renderMarkdownPage(body, opts) {
1990
- const html = DOMPurify.sanitize(await marked.parse(body));
1991
- const title = escapeHtml(opts.title || "Untitled");
1992
- const linkTag = opts.stylesheetUrl ? `
1993
- <link rel="stylesheet" href="${escapeHtml(opts.stylesheetUrl)}">` : "";
1994
- return `<!DOCTYPE html>
1995
- <html lang="en">
1996
- <head>
1997
- <meta charset="utf-8">
1998
- <meta name="viewport" content="width=device-width, initial-scale=1">
1999
- <title>${title}</title>
2000
- <style>${BASE_STYLES}</style>${linkTag}
2001
- </head>
2002
- <body>
2003
- <article>${html}</article>
2004
- </body>
2005
- </html>`;
2006
- }
2007
-
2008
- // packages/extensions/pages/src/routes.ts
2009
- var MIME_TYPES = {
2010
- ".html": "text/html",
2011
- ".js": "application/javascript",
2012
- ".css": "text/css",
2013
- ".json": "application/json",
2014
- ".svg": "image/svg+xml",
2015
- ".png": "image/png",
2016
- ".jpg": "image/jpeg",
2017
- ".jpeg": "image/jpeg",
2018
- ".gif": "image/gif",
2019
- ".ico": "image/x-icon",
2020
- ".woff": "font/woff",
2021
- ".woff2": "font/woff2",
2022
- ".txt": "text/plain",
2023
- ".xml": "application/xml"
2024
- };
2025
- function createRoutes(ctx) {
2026
- return new Hono().get("/", async (c) => {
2027
- if (!ctx.db) return c.json({ error: "Pages database not available" }, 503);
2028
- const { sites, systemSite } = getSites(ctx.db);
2029
- const recentPages = getRecentPagesList(ctx.db, { limit: 12 });
2030
- return c.json({ sites, systemSite, recentPages });
2031
- }).get("/feed", async (c) => {
2032
- if (!ctx.db) return c.json({ error: "Pages database not available" }, 503);
2033
- const mind = c.req.query("mind");
2034
- const rawLimit = c.req.query("limit");
2035
- const limit = rawLimit ? parseInt(rawLimit, 10) || 8 : 8;
2036
- const recentPages = getRecentPagesList(ctx.db, { mind: mind || void 0, limit });
2037
- return c.json(
2038
- recentPages.map((p) => ({
2039
- id: `page-${p.mind}-${p.file}`,
2040
- title: `${p.mind}/${p.file}`,
2041
- url: p.url ?? `/minds/${p.mind}/pages/${p.file}`,
2042
- date: p.modified,
2043
- author: p.mind,
2044
- bodyHtml: `<p>Page updated</p>`,
2045
- iframeUrl: `/ext/pages/public/${p.mind}/${p.file}`,
2046
- icon: '<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="8" cy="8" r="6"/><path d="M2 8h12M8 2c-2 2-2 10 0 12M8 2c2 2 2 10 0 12"/></svg>',
2047
- color: "purple"
2048
- }))
2049
- );
2050
- }).put("/publish/:name", ctx.requireSelf("name"), async (c) => {
2051
- const name = c.req.param("name");
2052
- const config = ctx.getSystemsConfig();
2053
- if (!config) return c.json({ error: "Not connected to volute.systems" }, 400);
2054
- const body = await c.req.text();
2055
- try {
2056
- const res = await fetch(`${config.apiUrl}/api/pages/publish/${name}`, {
2057
- method: "PUT",
2058
- headers: {
2059
- "Content-Type": "application/json",
2060
- Authorization: `Bearer ${config.apiKey}`
2061
- },
2062
- body
2063
- });
2064
- const data = await res.json().catch(() => ({ error: `HTTP ${res.status}` }));
2065
- return c.json(data, res.status);
2066
- } catch (err) {
2067
- return c.json({ error: `Connection failed: ${err.message}` }, 502);
2068
- }
2069
- }).get("/status/:name", ctx.requireSelf("name"), async (c) => {
2070
- const name = c.req.param("name");
2071
- const config = ctx.getSystemsConfig();
2072
- if (!config) return c.json({ error: "Not connected to volute.systems" }, 400);
2073
- try {
2074
- const res = await fetch(`${config.apiUrl}/api/pages/status/${name}`, {
2075
- headers: { Authorization: `Bearer ${config.apiKey}` }
2076
- });
2077
- const data = await res.json().catch(() => ({ error: `HTTP ${res.status}` }));
2078
- return c.json(data, res.status);
2079
- } catch (err) {
2080
- return c.json({ error: `Connection failed: ${err.message}` }, 502);
2081
- }
2082
- });
2083
- }
2084
- var PAGES_CSP = "sandbox allow-scripts; default-src 'self' https:; script-src 'self' 'unsafe-inline' https:; style-src 'self' 'unsafe-inline' https:; img-src 'self' data: https:; font-src 'self' data: https:; connect-src 'self' https:; base-uri 'none'";
2085
- var NAV_SHIM = '<script>if(window.parent!==window){window.parent.postMessage({type:"volute-pages-nav",path:location.pathname},"*")}</script>';
2086
- function injectNavShim(html) {
2087
- const idx = html.lastIndexOf("</body>");
2088
- return idx >= 0 ? html.slice(0, idx) + NAV_SHIM + html.slice(idx) : html + NAV_SHIM;
2089
- }
2090
- function createPublicRoutes(ctx) {
2091
- return new Hono().use("*", async (c, next) => {
2092
- await next();
2093
- c.res.headers.set("Content-Security-Policy", PAGES_CSP);
2094
- c.res.headers.set("X-Content-Type-Options", "nosniff");
2095
- }).get("/:name/*", async (c) => {
2096
- const name = c.req.param("name");
2097
- if (name.includes("/") || name.includes("\\") || name === "." || name === "..")
2098
- return c.text("Not found", 404);
2099
- let pagesRoot;
2100
- let blockDotfiles = false;
2101
- if (name === "_system") {
2102
- pagesRoot = resolve4(ctx.dataDir, "repo");
2103
- blockDotfiles = true;
2104
- } else {
2105
- pagesRoot = resolve4(ctx.dataDir, "sites", name);
2106
- }
2107
- const prefix = `/public/${name}`;
2108
- const idx = c.req.path.indexOf(prefix);
2109
- const wildcard = idx >= 0 ? c.req.path.slice(idx + prefix.length) : "/";
2110
- const requestedPath = resolve4(pagesRoot, wildcard.slice(1));
2111
- if (requestedPath !== pagesRoot && !requestedPath.startsWith(`${pagesRoot}/`))
2112
- return c.text("Forbidden", 403);
2113
- if (blockDotfiles) {
2114
- const relativePath = requestedPath.slice(pagesRoot.length + 1);
2115
- if (relativePath.split("/").some((seg) => seg.startsWith(".")))
2116
- return c.text("Not found", 404);
2117
- }
2118
- let fileToServe = requestedPath;
2119
- let fileStat = await stat(requestedPath).catch(() => null);
2120
- if (fileStat?.isDirectory()) {
2121
- const indexPath = resolve4(requestedPath, "index.html");
2122
- fileStat = await stat(indexPath).catch(() => null);
2123
- if (fileStat?.isFile()) {
2124
- fileToServe = indexPath;
2125
- } else {
2126
- const mdIndexPath = resolve4(requestedPath, "index.md");
2127
- fileStat = await stat(mdIndexPath).catch(() => null);
2128
- if (fileStat?.isFile()) {
2129
- fileToServe = mdIndexPath;
2130
- } else {
2131
- return c.text("Not found", 404);
2132
- }
2133
- }
2134
- } else if (!fileStat?.isFile()) {
2135
- return c.text("Not found", 404);
2136
- }
2137
- const ext = extname(fileToServe);
2138
- try {
2139
- if (ext === ".md") {
2140
- const content = await readFile(fileToServe, "utf-8");
2141
- const { title, style, body: body2 } = parseFrontmatter(content);
2142
- const cssRelPath = resolveStylesheet(fileToServe, pagesRoot, style);
2143
- const cssUrl = cssRelPath ? `/ext/pages/public/${name}/${cssRelPath}` : void 0;
2144
- const html = await renderMarkdownPage(body2, { title, stylesheetUrl: cssUrl });
2145
- return c.body(injectNavShim(html), 200, { "Content-Type": "text/html; charset=utf-8" });
2146
- }
2147
- if (ext === ".html") {
2148
- const html = await readFile(fileToServe, "utf-8");
2149
- return c.body(injectNavShim(html), 200, { "Content-Type": "text/html; charset=utf-8" });
2150
- }
2151
- const mime = MIME_TYPES[ext] || "application/octet-stream";
2152
- const body = await readFile(fileToServe);
2153
- return c.body(body, 200, { "Content-Type": mime });
2154
- } catch (err) {
2155
- const code = err.code;
2156
- if (code === "EACCES") return c.text("Forbidden", 403);
2157
- if (code === "ENOENT") return c.text("Not found", 404);
2158
- console.error(`[pages] error serving ${fileToServe}:`, err.message);
2159
- return c.text("Internal server error", 500);
2160
- }
2161
- });
2162
- }
2163
-
2164
- // packages/extensions/pages/src/index.ts
2165
- var assetsDir = resolve5(import.meta.dirname, "../dist/ui");
2166
- var skillsDir = resolve5(import.meta.dirname, "../skills");
2167
- var repoReady = null;
2168
- var src_default = createExtension({
2169
- id: "pages",
2170
- name: "Pages",
2171
- version: "0.1.0",
2172
- description: "Publish and serve web pages from mind directories",
2173
- mindDoc: "Publish web pages others can visit \u2014 finished creative work, essays, experiments, anything you want to give a lasting home on the web.",
2174
- initDb,
2175
- routes: (ctx) => createRoutes(ctx),
2176
- publicRoutes: (ctx) => createPublicRoutes(ctx),
2177
- commands: createCommands(),
2178
- skillsDir,
2179
- standardSkill: true,
2180
- icon: '<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="1" y="2" width="14" height="12" rx="1.5"/><path d="M1 5h14"/><circle cx="3" cy="3.5" r="0.5" fill="currentColor" stroke="none"/><circle cx="5" cy="3.5" r="0.5" fill="currentColor" stroke="none"/></svg>',
2181
- color: "purple",
2182
- ui: {
2183
- assetsDir,
2184
- systemSection: {
2185
- id: "pages",
2186
- label: "Pages",
2187
- urlPatterns: ["/pages", "/pages/:site", "/pages/:site/:path"]
2188
- },
2189
- mindSections: [{ id: "pages", label: "Pages" }],
2190
- feedSource: {
2191
- endpoint: "/api/ext/pages/feed"
2192
- }
2193
- },
2194
- onDaemonStart(ctx) {
2195
- repoReady = ensurePagesRepo(ctx.dataDir, isolationFrom(ctx));
2196
- repoReady.then(() => {
2197
- if (ctx.db) {
2198
- const repoDir = resolve5(ctx.dataDir, "repo");
2199
- try {
2200
- syncSystemPages(ctx.db, hashFiles(repoDir, collectHtmlFiles(repoDir)));
2201
- } catch (err) {
2202
- console.error("[pages] failed to sync system pages to DB:", err);
2203
- }
2204
- }
2205
- }).catch((err) => {
2206
- console.error("[pages] failed to initialize pages repo:", err);
2207
- });
2208
- },
2209
- onMindStart(mindName, ctx) {
2210
- const mindDir = ctx.getMindDir(mindName);
2211
- if (!mindDir) return;
2212
- (repoReady ?? Promise.resolve()).catch(() => {
2213
- }).then(() => addPagesWorktree(mindName, mindDir, ctx.dataDir, isolationFrom(ctx))).catch((err) => {
2214
- console.warn(
2215
- `[pages] failed to add pages worktree for ${mindName}: ${err.message}`
2216
- );
2217
- });
2218
- }
2219
- });
2220
- export {
2221
- src_default as default
2222
- };