@shgroup/dsh-serenity-hooks 1.25.8 → 1.25.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -647,7 +647,8 @@ function readSkiffRoles(root, paths = DEFAULT_SERENITY_CONFIG_PATHS) {
647
647
  keeper: role.trajectory.keeper === true,
648
648
  rebuild: role.trajectory.rebuild === true
649
649
  } : void 0,
650
- systemPrompt: typeof role.systemPrompt === "string" ? role.systemPrompt : void 0
650
+ systemPrompt: typeof role.systemPrompt === "string" ? role.systemPrompt : void 0,
651
+ systemPromptFile: typeof role.systemPromptFile === "string" ? role.systemPromptFile : void 0
651
652
  });
652
653
  }
653
654
  } catch {}
@@ -672,6 +673,32 @@ function roleMsmWhitelist(role) {
672
673
  return new Set(role?.msms ?? []);
673
674
  }
674
675
  /**
676
+ * 解析角色的系统提示词全文(v1.25.10,S142 用户:超长提示词 JSON 内嵌不可读):
677
+ * ① `systemPromptFile` 存在 → 读取文件内容(**推荐配置方法**;相对 CCC 根,
678
+ * 路径逃逸拒绝(resolveInside)+ BOM 剥除(readUtf8)+ 存在性校验)
679
+ * ② 否则 → 内嵌 `systemPrompt`(兼容旧配置)
680
+ * ③ 都无 → 空字符串
681
+ * 文件缺失/逃逸 → 抛错(调用方 catch 降级 + validate 报 issue)。
682
+ * 懒读取:readSkiffRoles 不读文件(guards/seams 每次工具调用查询的热路径零 IO),
683
+ * 仅在本函数(创建 agent / validate / list 时)读取。
684
+ */
685
+ function resolveRoleSystemPrompt(root, role) {
686
+ if (!role) return "";
687
+ const file = role.systemPromptFile?.trim();
688
+ if (file) {
689
+ const abs = resolveInside(root, file);
690
+ if (!existsSync(abs)) throw new Error(`skiff role "${role.systemPrompt ?? "(unnamed)"}": systemPromptFile "${file}" not found (resolved: ${abs})`);
691
+ return readUtf8(abs).trim();
692
+ }
693
+ return role.systemPrompt ?? "";
694
+ }
695
+ /** 角色系统提示词来源(validate/list 展示用) */
696
+ function systemPromptSource(role) {
697
+ if (role?.systemPromptFile?.trim()) return "file";
698
+ if (role?.systemPrompt?.trim()) return "inline";
699
+ return "none";
700
+ }
701
+ /**
675
702
  * Skiff 基础提示词(dsp 只给这部分;CCC 的 systemPrompt 段由调用方拼接):
676
703
  * 身份 + 可用 MSM/工具清单 + 调用协议 + 边界声明。动态生成(清单来自角色白名单)。
677
704
  */
@@ -694,22 +721,20 @@ function buildSkiffBasePrompt(roleName, role) {
694
721
  }
695
722
  //#endregion
696
723
  //#region src/skiff-registry.ts
697
- /**
698
- * skiff-registry.ts — Skiff 会话注册表(sessionId → role;零 DSH 依赖,可被任何 seams 安全 import)
699
- *
700
- * F4b 会话映射:Skiff agent 创建时注册(skiff-core),guards/seams 按 sessionId 查角色。
701
- * 独立成模块的原因:guards.ts 等拦截缝需要查角色而不引入 skiff-core 的运行时依赖
702
- * (skiff-core 依赖 @deepseek-ai/dsh-llm,测试/装配级联成本高)——注册表本身纯内存 Map。
703
- *
704
- * 生命周期:进程内存态;连接/页面关闭时 unregister;进程重启自然清空(skiff 会话不复存在)。
705
- */
706
724
  const skiffSessions = /* @__PURE__ */ new Map();
707
- /** 查 sessionId 的 Skiff 角色名(无 → null) */
725
+ /** 查 sessionId 的 Skiff 角色名(无 → null)——向后兼容(guards/seams 依赖) */
708
726
  function skiffRoleFor$1(sessionId) {
727
+ return skiffSessions.get(sessionId)?.role ?? null;
728
+ }
729
+ /** 查 sessionId 的完整绑定(role + ccc;无 → null)——v1.25.10 会话追问校验 */
730
+ function skiffSessionInfo$1(sessionId) {
709
731
  return skiffSessions.get(sessionId) ?? null;
710
732
  }
711
- function registerSkiffSession$1(sessionId, role) {
712
- skiffSessions.set(sessionId, role);
733
+ function registerSkiffSession$1(sessionId, role, ccc) {
734
+ skiffSessions.set(sessionId, {
735
+ role,
736
+ ccc
737
+ });
713
738
  }
714
739
  //#endregion
715
740
  //#region src/seams/guards.ts
@@ -2357,9 +2382,17 @@ const skiffAgents = /* @__PURE__ */ new Map();
2357
2382
  function skiffRoleFor(sessionId) {
2358
2383
  return skiffRoleFor$1(sessionId);
2359
2384
  }
2360
- function registerSkiffSession(sessionId, role, agent) {
2385
+ /** 查 sessionId 的会话绑定(role + ccc;无 → null)——v1.25.10 追问校验 */
2386
+ function skiffSessionInfo(sessionId) {
2387
+ return skiffSessionInfo$1(sessionId);
2388
+ }
2389
+ /** 查 sessionId 的活体 agent(进程内会话延续用;未注册/已清理 → undefined) */
2390
+ function getSkiffAgent(sessionId) {
2391
+ return skiffAgents.get(sessionId);
2392
+ }
2393
+ function registerSkiffSession(sessionId, role, ccc, agent) {
2361
2394
  skiffAgents.set(sessionId, agent);
2362
- registerSkiffSession$1(sessionId, role);
2395
+ registerSkiffSession$1(sessionId, role, ccc);
2363
2396
  }
2364
2397
  /** Skiff agent 挂载的 DSH preset(v1.25.3 修复:read/grep/glob 等平台工具由 preset 决定工具面;
2365
2398
  * handyman 经 composeFrom 继承父、skiff 无父上下文——直接挂 DSH 默认 standard preset;
@@ -2387,16 +2420,22 @@ async function createSkiffAgent(ctx, root, roleName, role, defaultModel) {
2387
2420
  ...model ? { agentOptions: splitModel(model) } : {}
2388
2421
  });
2389
2422
  const agent = handle.agent;
2423
+ let cccPrompt = "";
2424
+ try {
2425
+ cccPrompt = resolveRoleSystemPrompt(root, role);
2426
+ } catch (err) {
2427
+ console.warn(`[serenity-hooks] skiff 角色 "${roleName}" 系统提示词解析失败(回退仅基础段): ${String(err?.message ?? err)}`);
2428
+ }
2390
2429
  try {
2391
2430
  agent.ctx.systemPrompt.section({
2392
2431
  name: "serenity-skiff",
2393
2432
  order: -60,
2394
- text: () => [buildSkiffBasePrompt(roleName, role), role.systemPrompt ?? ""].filter(Boolean).join("\n")
2433
+ text: () => [buildSkiffBasePrompt(roleName, role), cccPrompt].filter(Boolean).join("\n")
2395
2434
  });
2396
2435
  } catch (err) {
2397
2436
  console.warn(`[serenity-hooks] skiff 系统提示词注册失败: ${String(err?.message ?? err)}`);
2398
2437
  }
2399
- registerSkiffSession(sessionId, roleName, agent);
2438
+ registerSkiffSession(sessionId, roleName, root, agent);
2400
2439
  return {
2401
2440
  handle,
2402
2441
  agent,
@@ -2478,11 +2517,12 @@ function truncate(s, n) {
2478
2517
  return s.length > n ? `${s.slice(0, n)}…` : s;
2479
2518
  }
2480
2519
  /**
2481
- * 提问一轮:followup → 等 idle → 读答案 + 本 turn 轨迹(增量 = followup 前 events 之后)。
2482
- * @param eventsStart 本轮开始前的 events 长度(0 = 全量轨迹)
2520
+ * 提问一轮:followup → 等 idle → 读答案 + 轨迹。
2521
+ * @param eventsStart 轨迹起点:显式传 0 = 全量轨迹(会话追问时页面重绘完整时间线,
2522
+ * v1.25.10 用户拍板);不传(undefined)= 本轮增量(followup 前 events 之后)
2483
2523
  */
2484
- async function askSkiff(ctx, agent, question, eventsStart = 0) {
2485
- const before = eventsStart > 0 ? eventsStart : agent.session.events.length;
2524
+ async function askSkiff(ctx, agent, question, eventsStart) {
2525
+ const before = eventsStart === void 0 ? agent.session.events.length : eventsStart;
2486
2526
  agent.followup(createUserMessage({
2487
2527
  content: [{
2488
2528
  type: "text",
@@ -6806,7 +6846,9 @@ dsp 只提供机制(双白名单强制 + 基础提示词 + 调试问答页)
6806
6846
  "msms": ["msm-a", "msm-b"], // MSM 白名单(独立):acc_msm exec 只能跑这些;register/deregister 必拒;list 只显示这些
6807
6847
  "tools": ["read","grep","glob",...], // 非 MSM 工具白名单(独立):白名单外工具一律不可用(guard 强制)
6808
6848
  "trajectory": { "session": false, "keeper": false, "rebuild": false }, // 轨迹纪律子集(缺省全关 = 完全独立)
6809
- "systemPrompt": "..." // 角色人格/认知边界/风格(CCC 完整定义;dsp 只给基础提示词)
6849
+ // 角色人格/认知边界/风格(CCC 完整定义;dsp 只给基础提示词)
6850
+ "systemPromptFile": ".opencode/skiff/<role>.md" // ★ 推荐:引用 md 文件(相对 CCC 根;超长提示词在 JSON 内嵌不可读)
6851
+ // "systemPrompt": "..." // 兼容:内嵌字符串仍可用;两者都设时 systemPromptFile 优先
6810
6852
  }
6811
6853
  } } }
6812
6854
 
@@ -6837,6 +6879,8 @@ dsp 只提供机制(双白名单强制 + 基础提示词 + 调试问答页)
6837
6879
  启停 = 人工(设置面板开关,不随插件加载自动启动);未开启零资源占用
6838
6880
  生效机制:角色配置**实时读取**(改 .opencode/serenity.json → 刷新调试页即生效);
6839
6881
  改配置后用 skiff_admin apply 做显式校验 + 应用确认(绑定 CCC + 角色清单)
6882
+ 会话追问(v1.25.10):调试页持有当前会话,追问自动续接(同会话上下文延续);
6883
+ 「新对话」按钮开新会话;进程重启后旧会话不可续(WebUI 仍可见历史)
6840
6884
  注意:skill 加载对 skiff **恒可用**(不设白名单——读知识面,无写能力)`;
6841
6885
  /** 校验当前 CCC 的 skiff 配置:roles schema 合法 / msms 均已注册 / model ∈ handyman.models / systemPrompt 非空 */
6842
6886
  function validateSkiffConfig(root) {
@@ -6852,7 +6896,11 @@ function validateSkiffConfig(root) {
6852
6896
  const hc = readHandymanConfig(root);
6853
6897
  const allowedModels = hc ? new Set(hc.models) : null;
6854
6898
  for (const [name, role] of roles) {
6855
- if (!role.systemPrompt?.trim()) issues.push(`role "${name}": systemPrompt is empty (CCC should fully define the role persona)`);
6899
+ try {
6900
+ if (!resolveRoleSystemPrompt(root, role).trim()) issues.push(`role "${name}": system prompt is empty (define systemPromptFile (recommended) or systemPrompt)`);
6901
+ } catch (err) {
6902
+ issues.push(`role "${name}": ${String(err?.message ?? err)}`);
6903
+ }
6856
6904
  for (const m of role.msms ?? []) if (!registered.has(m)) issues.push(`role "${name}": msms "${m}" is not registered in mech-registry.json`);
6857
6905
  if (role.model && allowedModels && !allowedModels.has(role.model)) issues.push(`role "${name}": model "${role.model}" not in handyman.models (${[...allowedModels].join(", ") || "(none)"})`);
6858
6906
  }
@@ -6879,7 +6927,8 @@ function listSkiffRoles(root) {
6879
6927
  keeper: role.trajectory?.keeper === true,
6880
6928
  rebuild: role.trajectory?.rebuild === true
6881
6929
  },
6882
- hasSystemPrompt: Boolean(role.systemPrompt?.trim())
6930
+ promptSource: systemPromptSource(role),
6931
+ ...role.systemPromptFile ? { systemPromptFile: role.systemPromptFile } : {}
6883
6932
  }));
6884
6933
  return {
6885
6934
  roles: items,
@@ -6914,7 +6963,7 @@ function applySkiffConfig(root) {
6914
6963
  }
6915
6964
  const skiffAdminTool = defineTool({
6916
6965
  name: "skiff_admin",
6917
- description: "Skiff (F4, experimental): CCC cognitive-subset roles (subsets of the full serenity trajectory). guide: definition tutorial (concept/role schema/cognitive MSM writing/dual whitelist/trajectory subset/examples); validate: check the CCC skiff config (roles schema legal / msms registered / model in handyman.models / systemPrompt non-empty); apply: validate then confirm the config is live (bound CCC + role list; roles are read live on every request); list: role summary (name/model/msms/tools/trajectory). Roles are defined by the CCC in .opencode/serenity.json skiff.roles; skill loading is always available to skiff sessions (not whitelisted).",
6966
+ description: "Skiff (F4, experimental): CCC cognitive-subset roles (subsets of the full serenity trajectory). guide: definition tutorial (concept/role schema/cognitive MSM writing/dual whitelist/trajectory subset/examples); validate: check the CCC skiff config (roles schema legal / msms registered / model in handyman.models / system prompt resolvable — systemPromptFile (recommended) or systemPrompt non-empty); apply: validate then confirm the config is live (bound CCC + role list; roles are read live on every request); list: role summary (name/model/msms/tools/trajectory/prompt source). Roles are defined by the CCC in .opencode/serenity.json skiff.roles; skill loading is always available to skiff sessions (not whitelisted).",
6918
6967
  parameters: { action: {
6919
6968
  type: "string",
6920
6969
  enum: [
@@ -9336,6 +9385,1656 @@ function registerGateway(ctx) {
9336
9385
  });
9337
9386
  }
9338
9387
  //#endregion
9388
+ //#region node_modules/.pnpm/marked@18.0.11/node_modules/marked/lib/marked.esm.js
9389
+ /**
9390
+ * marked v18.0.11 - a markdown parser
9391
+ * Copyright (c) 2018-2026, MarkedJS. (MIT License)
9392
+ * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT License)
9393
+ * https://github.com/markedjs/marked
9394
+ */
9395
+ /**
9396
+ * DO NOT EDIT THIS FILE
9397
+ * The code in this file is generated from files in ./src/
9398
+ */
9399
+ function A() {
9400
+ return {
9401
+ async: !1,
9402
+ breaks: !1,
9403
+ extensions: null,
9404
+ gfm: !0,
9405
+ hooks: null,
9406
+ pedantic: !1,
9407
+ renderer: null,
9408
+ silent: !1,
9409
+ tokenizer: null,
9410
+ walkTokens: null
9411
+ };
9412
+ }
9413
+ var R = A();
9414
+ function j(l) {
9415
+ R = l;
9416
+ }
9417
+ var z$1 = { exec: () => null };
9418
+ function I(l) {
9419
+ let e = [];
9420
+ return (t) => {
9421
+ let n = Math.max(0, Math.min(3, t - 1)), s = e[n];
9422
+ return s || (s = l(n), e[n] = s), s;
9423
+ };
9424
+ }
9425
+ function k(l, e = "") {
9426
+ let t = typeof l == "string" ? l : l.source, n = {
9427
+ replace: (s, r) => {
9428
+ let i = typeof r == "string" ? r : r.source;
9429
+ return i = i.replace(m.caret, "$1"), t = t.replace(s, i), n;
9430
+ },
9431
+ getRegex: () => new RegExp(t, e)
9432
+ };
9433
+ return n;
9434
+ }
9435
+ var Oe = ((l = "") => {
9436
+ try {
9437
+ return !!new RegExp("(?<=1)(?<!1)" + l);
9438
+ } catch {
9439
+ return !1;
9440
+ }
9441
+ })();
9442
+ var m = {
9443
+ codeRemoveIndent: /^(?: {1,4}| {0,3}\t)/gm,
9444
+ outputLinkReplace: /\\([\[\]])/g,
9445
+ indentCodeCompensation: /^(\s+)(?:```)/,
9446
+ beginningSpace: /^\s+/,
9447
+ endingHash: /#$/,
9448
+ startingSpaceChar: /^ /,
9449
+ endingSpaceChar: / $/,
9450
+ nonSpaceChar: /[^ ]/,
9451
+ newLineCharGlobal: /\n/g,
9452
+ tabCharGlobal: /\t/g,
9453
+ multipleSpaceGlobal: /\s+/g,
9454
+ blankLine: /^[ \t]*$/,
9455
+ doubleBlankLine: /\n[ \t]*\n[ \t]*$/,
9456
+ blockquoteStart: /^ {0,3}>/,
9457
+ blockquoteSetextReplace: /\n {0,3}((?:=+|-+) *)(?=\n|$)/g,
9458
+ blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm,
9459
+ listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g,
9460
+ listIsTask: /^\[[ xX]\] +\S/,
9461
+ listReplaceTask: /^\[[ xX]\] +/,
9462
+ listTaskCheckbox: /\[[ xX]\]/,
9463
+ anyLine: /\n.*\n/,
9464
+ hrefBrackets: /^<(.*)>$/,
9465
+ tableDelimiter: /[:|]/,
9466
+ tableAlignChars: /^\||\| *$/g,
9467
+ tableRowBlankLine: /\n[ \t]*$/,
9468
+ tableAlignRight: /^ *-+: *$/,
9469
+ tableAlignCenter: /^ *:-+: *$/,
9470
+ tableAlignLeft: /^ *:-+ *$/,
9471
+ startATag: /^<a /i,
9472
+ endATag: /^<\/a>/i,
9473
+ startPreScriptTag: /^<(pre|code|kbd|script)(\s|>)/i,
9474
+ endPreScriptTag: /^<\/(pre|code|kbd|script)(\s|>)/i,
9475
+ startAngleBracket: /^</,
9476
+ endAngleBracket: />$/,
9477
+ pedanticHrefTitle: /^([^'"]*[^\s])\s+(['"])(.*)\2/,
9478
+ unicodeAlphaNumeric: /[\p{L}\p{N}]/u,
9479
+ escapeTest: /[&<>"']/,
9480
+ escapeReplace: /[&<>"']/g,
9481
+ escapeTestNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,
9482
+ escapeReplaceNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,
9483
+ caret: /(^|[^\[])\^/g,
9484
+ percentDecode: /%25/g,
9485
+ findPipe: /\|/g,
9486
+ splitPipe: / \|/,
9487
+ slashPipe: /\\\|/g,
9488
+ carriageReturn: /\r\n|\r/g,
9489
+ spaceLine: /^ +$/gm,
9490
+ notSpaceStart: /^\S*/,
9491
+ endingNewline: /\n$/,
9492
+ listItemRegex: (l) => new RegExp(`^( {0,3}${l})((?:[ ][^\\n]*)?(?:\\n|$))`),
9493
+ nextBulletRegex: I((l) => new RegExp(`^ {0,${l}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),
9494
+ hrRegex: I((l) => new RegExp(`^ {0,${l}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`)),
9495
+ fencesBeginRegex: I((l) => new RegExp(`^ {0,${l}}(?:\`\`\`|~~~)`)),
9496
+ headingBeginRegex: I((l) => new RegExp(`^ {0,${l}}#`)),
9497
+ htmlBeginRegex: I((l) => new RegExp(`^ {0,${l}}<(?:[a-z].*>|!--)`, "i")),
9498
+ blockquoteBeginRegex: I((l) => new RegExp(`^ {0,${l}}>`))
9499
+ };
9500
+ var Te = /^(?:[ \t]*(?:\n|$))+/;
9501
+ var we = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/;
9502
+ var ye = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/;
9503
+ var q = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
9504
+ var Pe = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/;
9505
+ var U = / {0,3}(?:[*+-]|\d{1,9}[.)])/;
9506
+ var oe = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/;
9507
+ var ae = k(oe).replace(/bull/g, U).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}(?:\s|$)/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/\|table/g, "").getRegex();
9508
+ var Se = k(oe).replace(/bull/g, U).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}(?:\s|$)/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex();
9509
+ var K = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/;
9510
+ var _e = /^[^\n]+/;
9511
+ var W = /(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/;
9512
+ var $e = k(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label", W).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex();
9513
+ var Le = k(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g, U).getRegex();
9514
+ var Q = "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";
9515
+ var X = /<!--(?:-?>|[\s\S]*?(?:-->|$))/;
9516
+ var Ee = k("^ {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", X).replace("tag", Q).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
9517
+ var le = (l) => k(K).replace("hr", q).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("|table", "").replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list", l).replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", Q).getRegex();
9518
+ var ze = le(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/);
9519
+ var Me = le(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/);
9520
+ var J = {
9521
+ blockquote: k(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", Me).getRegex(),
9522
+ code: we,
9523
+ def: $e,
9524
+ fences: ye,
9525
+ heading: Pe,
9526
+ hr: q,
9527
+ html: Ee,
9528
+ lheading: ae,
9529
+ list: Le,
9530
+ newline: Te,
9531
+ paragraph: ze,
9532
+ table: z$1,
9533
+ text: _e
9534
+ };
9535
+ var se = k("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr", q).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("blockquote", " {0,3}>").replace("code", "(?: {4}| {0,3} )[^\\n]").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list", " {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", Q).getRegex();
9536
+ var Ie = {
9537
+ ...J,
9538
+ lheading: Se,
9539
+ table: se,
9540
+ paragraph: k(K).replace("hr", q).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("table", se).replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list", " {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", Q).getRegex()
9541
+ };
9542
+ var Ce = {
9543
+ ...J,
9544
+ html: k(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment", X).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(),
9545
+ def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
9546
+ heading: /^(#{1,6})(.*)(?:\n+|$)/,
9547
+ fences: z$1,
9548
+ lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
9549
+ paragraph: k(K).replace("hr", q).replace("heading", ` *#{1,6} *[^
9550
+ ]`).replace("lheading", ae).replace("|table", "").replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").replace("|tag", "").getRegex()
9551
+ };
9552
+ var Be = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/;
9553
+ var De = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/;
9554
+ var ue = /^( {2,}|\\)\n(?!\s*$)/;
9555
+ var qe = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/;
9556
+ var _ = /[\p{P}\p{S}]/u;
9557
+ var C = /[\s\p{P}\p{S}]/u;
9558
+ var v = /[^\s\p{P}\p{S}]/u;
9559
+ var ve = k(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, C).getRegex();
9560
+ var He = /[\p{Pi}\p{Ps}"']/u;
9561
+ var pe = /(?!~)[\p{P}\p{S}]/u;
9562
+ var Ze = /(?!~)[\s\p{P}\p{S}]/u;
9563
+ var Ge = /(?:[^\s\p{P}\p{S}]|~)/u;
9564
+ var Qe = k(/link|precode-code|html/, "g").replace("link", /\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-", Oe ? "(?<!`)()" : "(^^|[^`])").replace("code", /(?<b>`+)[^`]+\k<b>(?!`)/).replace("html", /<(?! )[^<>]*?>/).getRegex();
9565
+ var ce = /^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/;
9566
+ var Ne = k(ce, "u").replace(/punct/g, _).getRegex();
9567
+ var je = k(ce, "u").replace(/punct/g, pe).getRegex();
9568
+ var Ue = k(/^(?:\*+(?:((?!\*)(?!openQuote)punct)|([^\s*]))?)|^_+(?:((?!_)(?!openQuote)punct)|([^\s_]))?/, "u").replace(/openQuote/g, He).replace(/punct/g, _).getRegex();
9569
+ var he = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)";
9570
+ var Ke = k(he, "gu").replace(/notPunctSpace/g, v).replace(/punctSpace/g, C).replace(/punct/g, _).getRegex();
9571
+ var We = k(he, "gu").replace(/notPunctSpace/g, Ge).replace(/punctSpace/g, Ze).replace(/punct/g, pe).getRegex();
9572
+ var Je = k("^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)[\\s](\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|(?:(?!\\*)punct|notPunctSpace)(\\*+)(?!\\*)(?=notPunctSpace)", "gu").replace(/notPunctSpace/g, v).replace(/punctSpace/g, C).replace(/punct/g, _).getRegex();
9573
+ var Ve = k("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)", "gu").replace(/notPunctSpace/g, v).replace(/punctSpace/g, C).replace(/punct/g, _).getRegex();
9574
+ var et = k("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)[\\s](_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)|(?:(?!_)punct|notPunctSpace)(_+)(?!_)(?=notPunctSpace)", "gu").replace(/notPunctSpace/g, v).replace(/punctSpace/g, C).replace(/punct/g, _).getRegex();
9575
+ var tt = k(/^~~?(?:((?!~)punct)|[^\s~])/, "u").replace(/punct/g, _).getRegex();
9576
+ var rt = k("^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)", "gu").replace(/notPunctSpace/g, v).replace(/punctSpace/g, C).replace(/punct/g, _).getRegex();
9577
+ var st = k(/\\(punct)/, "gu").replace(/punct/g, _).getRegex();
9578
+ var it = k(/^<(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();
9579
+ var ot = k(X).replace("(?:-->|$)", "-->").getRegex();
9580
+ var at = k("^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", ot).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex();
9581
+ var G = /(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/;
9582
+ var lt = k(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label", G).replace("href", /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex();
9583
+ var ke = k(/^!?\[(label)\]\[(ref)\]/).replace("label", G).replace("ref", W).getRegex();
9584
+ var de = k(/^!?\[(ref)\](?:\[\])?/).replace("ref", W).getRegex();
9585
+ var ut = k("reflink|nolink(?!\\()", "g").replace("reflink", ke).replace("nolink", de).getRegex();
9586
+ var ie = /[hH][tT][tT][pP][sS]?|[fF][tT][pP]/;
9587
+ var V = {
9588
+ _backpedal: z$1,
9589
+ anyPunctuation: st,
9590
+ autolink: it,
9591
+ blockSkip: Qe,
9592
+ br: ue,
9593
+ code: De,
9594
+ del: z$1,
9595
+ delLDelim: z$1,
9596
+ delRDelim: z$1,
9597
+ emStrongLDelim: Ne,
9598
+ emStrongRDelimAst: Ke,
9599
+ emStrongRDelimUnd: Ve,
9600
+ escape: Be,
9601
+ link: lt,
9602
+ nolink: de,
9603
+ punctuation: ve,
9604
+ reflink: ke,
9605
+ reflinkSearch: ut,
9606
+ tag: at,
9607
+ text: qe,
9608
+ url: z$1
9609
+ };
9610
+ var pt = {
9611
+ ...V,
9612
+ emStrongLDelim: Ue,
9613
+ emStrongRDelimAst: Je,
9614
+ emStrongRDelimUnd: et,
9615
+ link: k(/^!?\[(label)\]\((.*?)\)/).replace("label", G).getRegex(),
9616
+ reflink: k(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", G).getRegex()
9617
+ };
9618
+ var F = {
9619
+ ...V,
9620
+ emStrongRDelimAst: We,
9621
+ emStrongLDelim: je,
9622
+ delLDelim: tt,
9623
+ delRDelim: rt,
9624
+ url: k(/^((?: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(),
9625
+ _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
9626
+ del: /^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,
9627
+ text: k(/^(`+|~+|[^`~])(?:(?=[`~])|(?= {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()
9628
+ };
9629
+ var ct = {
9630
+ ...F,
9631
+ br: k(ue).replace("{2,}", "*").getRegex(),
9632
+ text: k(F.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex()
9633
+ };
9634
+ var H = {
9635
+ normal: J,
9636
+ gfm: Ie,
9637
+ pedantic: Ce
9638
+ };
9639
+ var B = {
9640
+ normal: V,
9641
+ gfm: F,
9642
+ breaks: ct,
9643
+ pedantic: pt
9644
+ };
9645
+ var ht = {
9646
+ "&": "&amp;",
9647
+ "<": "&lt;",
9648
+ ">": "&gt;",
9649
+ "\"": "&quot;",
9650
+ "'": "&#39;"
9651
+ };
9652
+ var ge = (l) => ht[l];
9653
+ function T(l, e) {
9654
+ if (e) {
9655
+ if (m.escapeTest.test(l)) return l.replace(m.escapeReplace, ge);
9656
+ } else if (m.escapeTestNoEncode.test(l)) return l.replace(m.escapeReplaceNoEncode, ge);
9657
+ return l;
9658
+ }
9659
+ function Y(l) {
9660
+ try {
9661
+ l = encodeURI(l).replace(m.percentDecode, "%");
9662
+ } catch {
9663
+ return null;
9664
+ }
9665
+ return l;
9666
+ }
9667
+ function ee(l, e) {
9668
+ let n = l.replace(m.findPipe, (r, i, o) => {
9669
+ let u = !1, a = i;
9670
+ for (; --a >= 0 && o[a] === "\\";) u = !u;
9671
+ return u ? "|" : " |";
9672
+ }).split(m.splitPipe), s = 0;
9673
+ if (n[0].trim() || n.shift(), n.length > 0 && !n.at(-1)?.trim() && n.pop(), e) if (n.length > e) n.splice(e);
9674
+ else for (; n.length < e;) n.push("");
9675
+ for (; s < n.length; s++) n[s] = n[s].trim().replace(m.slashPipe, "|");
9676
+ return n;
9677
+ }
9678
+ function $(l, e, t) {
9679
+ let n = l.length;
9680
+ if (n === 0) return "";
9681
+ let s = 0;
9682
+ for (; s < n;) {
9683
+ let r = l.charAt(n - s - 1);
9684
+ if (r === e && !t) s++;
9685
+ else if (r !== e && t) s++;
9686
+ else break;
9687
+ }
9688
+ return l.slice(0, n - s);
9689
+ }
9690
+ function te(l) {
9691
+ let e = l.split(`
9692
+ `), t = e.length - 1;
9693
+ for (; t >= 0 && m.blankLine.test(e[t]);) t--;
9694
+ return e.length - t <= 2 ? l : e.slice(0, t + 1).join(`
9695
+ `);
9696
+ }
9697
+ function fe(l, e) {
9698
+ if (l.indexOf(e[1]) === -1) return -1;
9699
+ let t = 0;
9700
+ for (let n = 0; n < l.length; n++) if (l[n] === "\\") n++;
9701
+ else if (l[n] === e[0]) t++;
9702
+ else if (l[n] === e[1] && (t--, t < 0)) return n;
9703
+ return t > 0 ? -2 : -1;
9704
+ }
9705
+ function me(l, e = 0) {
9706
+ let t = e, n = "";
9707
+ for (let s of l) if (s === " ") {
9708
+ let r = 4 - t % 4;
9709
+ n += " ".repeat(r), t += r;
9710
+ } else n += s, t++;
9711
+ return n;
9712
+ }
9713
+ function xe(l, e, t, n, s) {
9714
+ let r = e.href, i = e.title || null, o = l[1].replace(s.other.outputLinkReplace, "$1"), u = l[0].charAt(0) === "!";
9715
+ n.state.inLink = !0;
9716
+ let a = n.state.linkEmitted, p = n.state.inRawBlock;
9717
+ n.state.linkEmitted = !1;
9718
+ let c = n.inlineTokens(o), h = n.state.linkEmitted;
9719
+ if (n.state.linkEmitted = a, n.state.inLink = !1, !u) {
9720
+ if (h) {
9721
+ n.state.inRawBlock = p;
9722
+ return;
9723
+ }
9724
+ n.state.linkEmitted = !0;
9725
+ }
9726
+ return {
9727
+ type: u ? "image" : "link",
9728
+ raw: t,
9729
+ href: r,
9730
+ title: i,
9731
+ text: o,
9732
+ tokens: c
9733
+ };
9734
+ }
9735
+ function kt(l, e, t) {
9736
+ let n = l.match(t.other.indentCodeCompensation);
9737
+ if (n === null) return e;
9738
+ let s = n[1];
9739
+ return e.split(`
9740
+ `).map((r) => {
9741
+ let i = r.match(t.other.beginningSpace);
9742
+ if (i === null) return r;
9743
+ let [o] = i;
9744
+ return o.length >= s.length ? r.slice(s.length) : r;
9745
+ }).join(`
9746
+ `);
9747
+ }
9748
+ var y = class {
9749
+ options;
9750
+ rules;
9751
+ lexer;
9752
+ constructor(e) {
9753
+ this.options = e || R;
9754
+ }
9755
+ space(e) {
9756
+ let t = this.rules.block.newline.exec(e);
9757
+ if (t && t[0].length > 0) return {
9758
+ type: "space",
9759
+ raw: t[0]
9760
+ };
9761
+ }
9762
+ code(e) {
9763
+ let t = this.rules.block.code.exec(e);
9764
+ if (t) {
9765
+ let n = this.options.pedantic ? t[0] : te(t[0]);
9766
+ return {
9767
+ type: "code",
9768
+ raw: n,
9769
+ codeBlockStyle: "indented",
9770
+ text: n.replace(this.rules.other.codeRemoveIndent, "")
9771
+ };
9772
+ }
9773
+ }
9774
+ fences(e) {
9775
+ let t = this.rules.block.fences.exec(e);
9776
+ if (t) {
9777
+ let n = t[0], s = kt(n, t[3] || "", this.rules);
9778
+ return {
9779
+ type: "code",
9780
+ raw: n,
9781
+ lang: t[2] ? t[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : t[2],
9782
+ text: s
9783
+ };
9784
+ }
9785
+ }
9786
+ heading(e) {
9787
+ let t = this.rules.block.heading.exec(e);
9788
+ if (t) {
9789
+ let n = t[2].trim();
9790
+ if (this.rules.other.endingHash.test(n)) {
9791
+ let s = $(n, "#");
9792
+ (this.options.pedantic || !s || this.rules.other.endingSpaceChar.test(s)) && (n = s.trim());
9793
+ }
9794
+ return {
9795
+ type: "heading",
9796
+ raw: $(t[0], `
9797
+ `),
9798
+ depth: t[1].length,
9799
+ text: n,
9800
+ tokens: this.lexer.inline(n)
9801
+ };
9802
+ }
9803
+ }
9804
+ hr(e) {
9805
+ let t = this.rules.block.hr.exec(e);
9806
+ if (t) return {
9807
+ type: "hr",
9808
+ raw: $(t[0], `
9809
+ `)
9810
+ };
9811
+ }
9812
+ blockquote(e) {
9813
+ let t = this.rules.block.blockquote.exec(e);
9814
+ if (t) {
9815
+ let n = $(t[0], `
9816
+ `).split(`
9817
+ `), s = "", r = "", i = [];
9818
+ for (; n.length > 0;) {
9819
+ let o = !1, u = [], a;
9820
+ for (a = 0; a < n.length; a++) if (this.rules.other.blockquoteStart.test(n[a])) u.push(n[a]), o = !0;
9821
+ else if (!o) u.push(n[a]);
9822
+ else break;
9823
+ n = n.slice(a);
9824
+ let p = u.join(`
9825
+ `), c = p.replace(this.rules.other.blockquoteSetextReplace, `
9826
+ $1`).replace(this.rules.other.blockquoteSetextReplace2, "");
9827
+ s = s ? `${s}
9828
+ ${p}` : p, r = r ? `${r}
9829
+ ${c}` : c;
9830
+ let h = this.lexer.state.top;
9831
+ if (this.lexer.state.top = !0, this.lexer.blockTokens(c, i, !0), this.lexer.state.top = h, n.length === 0) break;
9832
+ let d = i.at(-1);
9833
+ if (d?.type === "code") break;
9834
+ if (d?.type === "blockquote") {
9835
+ let O = d, g = n.join(`
9836
+ `), w = O.raw + `
9837
+ ` + g.replace(this.rules.other.blockquoteSetextReplace2, ""), E = this.blockquote(w);
9838
+ i[i.length - 1] = E, s = `${s}
9839
+ ${g}`, r = r.substring(0, r.length - O.text.length) + E.text;
9840
+ break;
9841
+ } else if (d?.type === "list") {
9842
+ let O = d, g = O.raw + `
9843
+ ` + n.join(`
9844
+ `), w = this.list(g);
9845
+ i[i.length - 1] = w, s = s.substring(0, s.length - d.raw.length) + w.raw, r = r.substring(0, r.length - O.raw.length) + w.raw, n = g.substring(i.at(-1).raw.length).split(`
9846
+ `);
9847
+ continue;
9848
+ }
9849
+ }
9850
+ return {
9851
+ type: "blockquote",
9852
+ raw: s,
9853
+ tokens: i,
9854
+ text: r
9855
+ };
9856
+ }
9857
+ }
9858
+ list(e) {
9859
+ let t = this.rules.block.list.exec(e);
9860
+ if (t) {
9861
+ let n = t[1].trim(), s = n.length > 1, r = {
9862
+ type: "list",
9863
+ raw: "",
9864
+ ordered: s,
9865
+ start: s ? +n.slice(0, -1) : "",
9866
+ loose: !1,
9867
+ items: []
9868
+ };
9869
+ n = s ? `\\d{1,9}\\${n.slice(-1)}` : `\\${n}`, this.options.pedantic && (n = s ? n : "[*+-]");
9870
+ let i = this.rules.other.listItemRegex(n), o = !1;
9871
+ for (; e;) {
9872
+ let a = !1, p = "", c = "";
9873
+ if (!(t = i.exec(e)) || this.rules.block.hr.test(e)) break;
9874
+ p = t[0], e = e.substring(p.length);
9875
+ let h = me(t[2].split(`
9876
+ `, 1)[0], t[1].length), d = e.split(`
9877
+ `, 1)[0], O = !h.trim(), g = 0;
9878
+ if (this.options.pedantic ? (g = 2, c = h.trimStart()) : O ? g = t[1].length + 1 : (g = h.search(this.rules.other.nonSpaceChar), g = g > 4 ? 1 : g, c = h.slice(g), g += t[1].length), O && this.rules.other.blankLine.test(d) && (p += d + `
9879
+ `, e = e.substring(d.length + 1), a = !0), !a) {
9880
+ let w = this.rules.other.nextBulletRegex(g), E = this.rules.other.hrRegex(g), ne = this.rules.other.fencesBeginRegex(g), re = this.rules.other.headingBeginRegex(g), be = this.rules.other.htmlBeginRegex(g), Re = this.rules.other.blockquoteBeginRegex(g);
9881
+ for (; e;) {
9882
+ let N = e.split(`
9883
+ `, 1)[0], D;
9884
+ if (d = N, this.options.pedantic ? (d = d.replace(this.rules.other.listReplaceNesting, " "), D = d) : D = d.replace(this.rules.other.tabCharGlobal, " "), ne.test(d) || re.test(d) || be.test(d) || Re.test(d) || w.test(d) || E.test(d)) break;
9885
+ if (D.search(this.rules.other.nonSpaceChar) >= g || !d.trim()) c += `
9886
+ ` + D.slice(g);
9887
+ else {
9888
+ if (O || h.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4 || ne.test(h) || re.test(h) || E.test(h)) break;
9889
+ c += `
9890
+ ` + d;
9891
+ }
9892
+ O = !d.trim(), p += N + `
9893
+ `, e = e.substring(N.length + 1), h = D.slice(g);
9894
+ }
9895
+ }
9896
+ r.loose || (o ? r.loose = !0 : this.rules.other.doubleBlankLine.test(p) && (o = !0)), r.items.push({
9897
+ type: "list_item",
9898
+ raw: p,
9899
+ task: !!this.options.gfm && this.rules.other.listIsTask.test(c),
9900
+ loose: !1,
9901
+ text: c,
9902
+ tokens: []
9903
+ }), r.raw += p;
9904
+ }
9905
+ let u = r.items.at(-1);
9906
+ if (u) u.raw = u.raw.trimEnd(), u.text = u.text.trimEnd();
9907
+ else return;
9908
+ r.raw = r.raw.trimEnd();
9909
+ for (let a of r.items) if (this.lexer.state.top = !1, a.tokens = this.lexer.blockTokens(a.text, []), !r.loose) {
9910
+ let p = a.tokens.filter((h) => h.type === "space");
9911
+ r.loose = p.length > 0 && p.some((h) => this.rules.other.anyLine.test(h.raw));
9912
+ }
9913
+ for (let a of r.items) {
9914
+ let p = a.tokens[0];
9915
+ if (a.task && (p?.type === "text" || p?.type === "paragraph")) {
9916
+ a.text = a.text.replace(this.rules.other.listReplaceTask, ""), p.raw = p.raw.replace(this.rules.other.listReplaceTask, ""), p.text = p.text.replace(this.rules.other.listReplaceTask, "");
9917
+ for (let h = this.lexer.inlineQueue.length - 1; h >= 0; h--) if (this.rules.other.listIsTask.test(this.lexer.inlineQueue[h].src)) {
9918
+ this.lexer.inlineQueue[h].src = this.lexer.inlineQueue[h].src.replace(this.rules.other.listReplaceTask, "");
9919
+ break;
9920
+ }
9921
+ let c = this.rules.other.listTaskCheckbox.exec(a.raw);
9922
+ if (c) {
9923
+ let h = {
9924
+ type: "checkbox",
9925
+ raw: c[0] + " ",
9926
+ checked: c[0] !== "[ ]"
9927
+ };
9928
+ a.checked = h.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 = h.raw + a.tokens[0].raw, a.tokens[0].text = h.raw + a.tokens[0].text, a.tokens[0].tokens.unshift(h)) : a.tokens.unshift({
9929
+ type: "paragraph",
9930
+ raw: h.raw,
9931
+ text: h.raw,
9932
+ tokens: [h]
9933
+ }) : a.tokens.unshift(h);
9934
+ }
9935
+ } else a.task && (a.task = !1);
9936
+ }
9937
+ if (r.loose) for (let a of r.items) {
9938
+ a.loose = !0;
9939
+ for (let p of a.tokens) p.type === "text" && (p.type = "paragraph");
9940
+ }
9941
+ return r;
9942
+ }
9943
+ }
9944
+ html(e) {
9945
+ let t = this.rules.block.html.exec(e);
9946
+ if (t) {
9947
+ let n = te(t[0]);
9948
+ return {
9949
+ type: "html",
9950
+ block: !0,
9951
+ raw: n,
9952
+ pre: t[1] === "pre" || t[1] === "script" || t[1] === "style",
9953
+ text: n
9954
+ };
9955
+ }
9956
+ }
9957
+ def(e) {
9958
+ let t = this.rules.block.def.exec(e);
9959
+ if (t) {
9960
+ 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];
9961
+ return {
9962
+ type: "def",
9963
+ tag: n,
9964
+ raw: $(t[0], `
9965
+ `),
9966
+ href: s,
9967
+ title: r
9968
+ };
9969
+ }
9970
+ }
9971
+ table(e) {
9972
+ let t = this.rules.block.table.exec(e);
9973
+ if (!t || !this.rules.other.tableDelimiter.test(t[2])) return;
9974
+ let n = ee(t[1]), s = t[2].replace(this.rules.other.tableAlignChars, "").split("|"), r = t[3]?.trim() ? t[3].replace(this.rules.other.tableRowBlankLine, "").split(`
9975
+ `) : [], i = {
9976
+ type: "table",
9977
+ raw: $(t[0], `
9978
+ `),
9979
+ header: [],
9980
+ align: [],
9981
+ rows: []
9982
+ };
9983
+ if (n.length === s.length) {
9984
+ 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);
9985
+ for (let o = 0; o < n.length; o++) i.header.push({
9986
+ text: n[o],
9987
+ tokens: this.lexer.inline(n[o]),
9988
+ header: !0,
9989
+ align: i.align[o]
9990
+ });
9991
+ for (let o of r) i.rows.push(ee(o, i.header.length).map((u, a) => ({
9992
+ text: u,
9993
+ tokens: this.lexer.inline(u),
9994
+ header: !1,
9995
+ align: i.align[a]
9996
+ })));
9997
+ return i;
9998
+ }
9999
+ }
10000
+ lheading(e) {
10001
+ let t = this.rules.block.lheading.exec(e);
10002
+ if (t) {
10003
+ let n = t[1].trim();
10004
+ return {
10005
+ type: "heading",
10006
+ raw: $(t[0], `
10007
+ `),
10008
+ depth: t[2].charAt(0) === "=" ? 1 : 2,
10009
+ text: n,
10010
+ tokens: this.lexer.inline(n)
10011
+ };
10012
+ }
10013
+ }
10014
+ paragraph(e) {
10015
+ let t = this.rules.block.paragraph.exec(e);
10016
+ if (t) {
10017
+ let n = t[1].charAt(t[1].length - 1) === `
10018
+ ` ? t[1].slice(0, -1) : t[1];
10019
+ return {
10020
+ type: "paragraph",
10021
+ raw: t[0],
10022
+ text: n,
10023
+ tokens: this.lexer.inline(n)
10024
+ };
10025
+ }
10026
+ }
10027
+ text(e) {
10028
+ let t = this.rules.block.text.exec(e);
10029
+ if (t) return {
10030
+ type: "text",
10031
+ raw: t[0],
10032
+ text: t[0],
10033
+ tokens: this.lexer.inline(t[0])
10034
+ };
10035
+ }
10036
+ escape(e) {
10037
+ let t = this.rules.inline.escape.exec(e);
10038
+ if (t) return {
10039
+ type: "escape",
10040
+ raw: t[0],
10041
+ text: t[1]
10042
+ };
10043
+ }
10044
+ tag(e) {
10045
+ let t = this.rules.inline.tag.exec(e);
10046
+ if (t) return !this.lexer.state.inLink && this.rules.other.startATag.test(t[0]) ? this.lexer.state.inLink = !0 : this.lexer.state.inLink && this.rules.other.endATag.test(t[0]) && (this.lexer.state.inLink = !1), !this.lexer.state.inRawBlock && this.rules.other.startPreScriptTag.test(t[0]) ? this.lexer.state.inRawBlock = !0 : this.lexer.state.inRawBlock && this.rules.other.endPreScriptTag.test(t[0]) && (this.lexer.state.inRawBlock = !1), {
10047
+ type: "html",
10048
+ raw: t[0],
10049
+ inLink: this.lexer.state.inLink,
10050
+ inRawBlock: this.lexer.state.inRawBlock,
10051
+ block: !1,
10052
+ text: t[0]
10053
+ };
10054
+ }
10055
+ link(e) {
10056
+ let t = this.rules.inline.link.exec(e);
10057
+ if (t) {
10058
+ let n = t[2].trim();
10059
+ if (!this.options.pedantic && this.rules.other.startAngleBracket.test(n)) {
10060
+ if (!this.rules.other.endAngleBracket.test(n)) return;
10061
+ let i = $(n.slice(0, -1), "\\");
10062
+ if ((n.length - i.length) % 2 === 0) return;
10063
+ } else {
10064
+ let i = fe(t[2], "()");
10065
+ if (i === -2) return;
10066
+ if (i > -1) {
10067
+ let u = (t[0].indexOf("!") === 0 ? 5 : 4) + t[1].length + i;
10068
+ t[2] = t[2].substring(0, i), t[0] = t[0].substring(0, u).trim(), t[3] = "";
10069
+ }
10070
+ }
10071
+ let s = t[2], r = "";
10072
+ if (this.options.pedantic) {
10073
+ let i = this.rules.other.pedanticHrefTitle.exec(s);
10074
+ i && (s = i[1], r = i[3]);
10075
+ } else r = t[3] ? t[3].slice(1, -1) : "";
10076
+ 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, {
10077
+ href: s && s.replace(this.rules.inline.anyPunctuation, "$1"),
10078
+ title: r && r.replace(this.rules.inline.anyPunctuation, "$1")
10079
+ }, t[0], this.lexer, this.rules);
10080
+ }
10081
+ }
10082
+ reflink(e, t) {
10083
+ let n;
10084
+ if ((n = this.rules.inline.reflink.exec(e)) || (n = this.rules.inline.nolink.exec(e))) {
10085
+ let r = t[(n[2] || n[1]).replace(this.rules.other.multipleSpaceGlobal, " ").toLowerCase()];
10086
+ if (!r) {
10087
+ let i = n[0].charAt(0);
10088
+ return {
10089
+ type: "text",
10090
+ raw: i,
10091
+ text: i
10092
+ };
10093
+ }
10094
+ return xe(n, r, n[0], this.lexer, this.rules);
10095
+ }
10096
+ }
10097
+ emStrong(e, t, n = "") {
10098
+ let s = this.rules.inline.emStrongLDelim.exec(e);
10099
+ if (!s || !s[1] && !s[2] && !s[3] && !s[4] || s[4] && n.match(this.rules.other.unicodeAlphaNumeric)) return;
10100
+ if (!(s[1] || s[3] || "") || !n || this.rules.inline.punctuation.exec(n)) {
10101
+ let i = [...s[0]].length - 1, o, u, a = i, p = 0, c = s[0][0], h = n === c, d = c === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
10102
+ for (d.lastIndex = 0, t = t.slice(-1 * e.length + i); (s = d.exec(t)) !== null;) {
10103
+ if (o = s[1] || s[2] || s[3] || s[4] || s[5] || s[6], !o) continue;
10104
+ if (u = [...o].length, s[3] || s[4]) {
10105
+ a += u;
10106
+ continue;
10107
+ } else if (s[5] || s[6]) {
10108
+ if (i % 3 && !((i + u) % 3)) {
10109
+ p += u;
10110
+ continue;
10111
+ }
10112
+ if (h) break;
10113
+ }
10114
+ if (a -= u, a > 0) continue;
10115
+ u = Math.min(u, u + a + p);
10116
+ let O = [...s[0]][0].length, g = e.slice(0, i + s.index + O + u);
10117
+ if (Math.min(i, u) % 2) {
10118
+ let E = g.slice(1, -1);
10119
+ return {
10120
+ type: "em",
10121
+ raw: g,
10122
+ text: E,
10123
+ tokens: this.lexer.inlineTokens(E)
10124
+ };
10125
+ }
10126
+ let w = g.slice(2, -2);
10127
+ return {
10128
+ type: "strong",
10129
+ raw: g,
10130
+ text: w,
10131
+ tokens: this.lexer.inlineTokens(w)
10132
+ };
10133
+ }
10134
+ }
10135
+ }
10136
+ codespan(e) {
10137
+ let t = this.rules.inline.code.exec(e);
10138
+ if (t) {
10139
+ 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);
10140
+ return s && r && (n = n.substring(1, n.length - 1)), {
10141
+ type: "codespan",
10142
+ raw: t[0],
10143
+ text: n
10144
+ };
10145
+ }
10146
+ }
10147
+ br(e) {
10148
+ let t = this.rules.inline.br.exec(e);
10149
+ if (t) return {
10150
+ type: "br",
10151
+ raw: t[0]
10152
+ };
10153
+ }
10154
+ del(e, t, n = "") {
10155
+ let s = this.rules.inline.delLDelim.exec(e);
10156
+ if (!s) return;
10157
+ if (!(s[1] || "") || !n || this.rules.inline.punctuation.exec(n)) {
10158
+ let i = [...s[0]].length - 1, o, u, a = i, p = this.rules.inline.delRDelim;
10159
+ for (p.lastIndex = 0, t = t.slice(-1 * e.length + i); (s = p.exec(t)) !== null;) {
10160
+ if (o = s[1] || s[2] || s[3] || s[4] || s[5] || s[6], !o || (u = [...o].length, u !== i)) continue;
10161
+ if (s[3] || s[4]) {
10162
+ a += u;
10163
+ continue;
10164
+ }
10165
+ if (a -= u, a > 0) continue;
10166
+ u = Math.min(u, u + a);
10167
+ let c = [...s[0]][0].length, h = e.slice(0, i + s.index + c + u), d = h.slice(i, -i);
10168
+ return {
10169
+ type: "del",
10170
+ raw: h,
10171
+ text: d,
10172
+ tokens: this.lexer.inlineTokens(d)
10173
+ };
10174
+ }
10175
+ }
10176
+ }
10177
+ autolink(e) {
10178
+ let t = this.rules.inline.autolink.exec(e);
10179
+ if (t) {
10180
+ let n, s;
10181
+ return t[2] === "@" ? (n = t[1], s = "mailto:" + n) : (n = t[1], s = n), {
10182
+ type: "link",
10183
+ raw: t[0],
10184
+ text: n,
10185
+ href: s,
10186
+ tokens: [{
10187
+ type: "text",
10188
+ raw: n,
10189
+ text: n
10190
+ }]
10191
+ };
10192
+ }
10193
+ }
10194
+ url(e) {
10195
+ let t;
10196
+ if (t = this.rules.inline.url.exec(e)) {
10197
+ let n, s;
10198
+ if (t[2] === "@") n = t[0], s = "mailto:" + n;
10199
+ else {
10200
+ let r;
10201
+ do
10202
+ r = t[0], t[0] = this.rules.inline._backpedal.exec(t[0])?.[0] ?? "";
10203
+ while (r !== t[0]);
10204
+ n = t[0], t[1] === "www." ? s = "http://" + t[0] : s = t[0];
10205
+ }
10206
+ return {
10207
+ type: "link",
10208
+ raw: t[0],
10209
+ text: n,
10210
+ href: s,
10211
+ tokens: [{
10212
+ type: "text",
10213
+ raw: n,
10214
+ text: n
10215
+ }]
10216
+ };
10217
+ }
10218
+ }
10219
+ inlineText(e) {
10220
+ let t = this.rules.inline.text.exec(e);
10221
+ if (t) {
10222
+ let n = this.lexer.state.inRawBlock;
10223
+ return {
10224
+ type: "text",
10225
+ raw: t[0],
10226
+ text: t[0],
10227
+ escaped: n
10228
+ };
10229
+ }
10230
+ }
10231
+ };
10232
+ var x = class l {
10233
+ tokens;
10234
+ options;
10235
+ state;
10236
+ inlineQueue;
10237
+ tokenizer;
10238
+ constructor(e) {
10239
+ this.tokens = [], this.tokens.links = Object.create(null), this.options = e || R, this.options.tokenizer = this.options.tokenizer || new y(), this.tokenizer = this.options.tokenizer, this.tokenizer.options = this.options, this.tokenizer.lexer = this, this.inlineQueue = [], this.state = {
10240
+ inLink: !1,
10241
+ inRawBlock: !1,
10242
+ linkEmitted: !1,
10243
+ top: !0
10244
+ };
10245
+ let t = {
10246
+ other: m,
10247
+ block: H.normal,
10248
+ inline: B.normal
10249
+ };
10250
+ this.options.pedantic ? (t.block = H.pedantic, t.inline = B.pedantic) : this.options.gfm && (t.block = H.gfm, this.options.breaks ? t.inline = B.breaks : t.inline = B.gfm), this.tokenizer.rules = t;
10251
+ }
10252
+ static get rules() {
10253
+ return {
10254
+ block: H,
10255
+ inline: B
10256
+ };
10257
+ }
10258
+ static lex(e, t) {
10259
+ return new l(t).lex(e);
10260
+ }
10261
+ static lexInline(e, t) {
10262
+ return new l(t).inlineTokens(e);
10263
+ }
10264
+ lex(e) {
10265
+ e = e.replace(m.carriageReturn, `
10266
+ `), this.blockTokens(e, this.tokens);
10267
+ for (let t = 0; t < this.inlineQueue.length; t++) {
10268
+ let n = this.inlineQueue[t];
10269
+ this.inlineTokens(n.src, n.tokens);
10270
+ }
10271
+ return this.inlineQueue = [], this.tokens;
10272
+ }
10273
+ blockTokens(e, t = [], n = !1) {
10274
+ this.tokenizer.lexer = this, this.options.pedantic && (e = e.replace(m.tabCharGlobal, " ").replace(m.spaceLine, ""));
10275
+ let s = 1 / 0;
10276
+ for (; e;) {
10277
+ if (e.length < s) s = e.length;
10278
+ else {
10279
+ this.infiniteLoopError(e.charCodeAt(0));
10280
+ break;
10281
+ }
10282
+ let r;
10283
+ if (this.options.extensions?.block?.some((o) => (r = o.call({ lexer: this }, e, t)) ? (e = e.substring(r.raw.length), t.push(r), !0) : !1)) continue;
10284
+ if (r = this.tokenizer.space(e)) {
10285
+ e = e.substring(r.raw.length);
10286
+ let o = t.at(-1);
10287
+ r.raw.length === 1 && o !== void 0 ? o.raw += `
10288
+ ` : t.push(r);
10289
+ continue;
10290
+ }
10291
+ if (r = this.tokenizer.code(e)) {
10292
+ e = e.substring(r.raw.length);
10293
+ let o = t.at(-1);
10294
+ o?.type === "paragraph" || o?.type === "text" ? (o.raw += (o.raw.endsWith(`
10295
+ `) ? "" : `
10296
+ `) + r.raw, o.text += `
10297
+ ` + r.text, this.inlineQueue.at(-1).src = o.text) : t.push(r);
10298
+ continue;
10299
+ }
10300
+ if (r = this.tokenizer.fences(e)) {
10301
+ e = e.substring(r.raw.length), t.push(r);
10302
+ continue;
10303
+ }
10304
+ if (r = this.tokenizer.heading(e)) {
10305
+ e = e.substring(r.raw.length), t.push(r);
10306
+ continue;
10307
+ }
10308
+ if (r = this.tokenizer.hr(e)) {
10309
+ e = e.substring(r.raw.length), t.push(r);
10310
+ continue;
10311
+ }
10312
+ if (r = this.tokenizer.blockquote(e)) {
10313
+ e = e.substring(r.raw.length), t.push(r);
10314
+ continue;
10315
+ }
10316
+ if (r = this.tokenizer.list(e)) {
10317
+ e = e.substring(r.raw.length), t.push(r);
10318
+ continue;
10319
+ }
10320
+ if (r = this.tokenizer.html(e)) {
10321
+ e = e.substring(r.raw.length), t.push(r);
10322
+ continue;
10323
+ }
10324
+ if (r = this.tokenizer.def(e)) {
10325
+ e = e.substring(r.raw.length);
10326
+ let o = t.at(-1);
10327
+ o?.type === "paragraph" || o?.type === "text" ? (o.raw += (o.raw.endsWith(`
10328
+ `) ? "" : `
10329
+ `) + r.raw, o.text += `
10330
+ ` + r.raw, this.inlineQueue.at(-1).src = o.text) : this.tokens.links[r.tag] || (this.tokens.links[r.tag] = {
10331
+ href: r.href,
10332
+ title: r.title
10333
+ }, t.push(r));
10334
+ continue;
10335
+ }
10336
+ if (r = this.tokenizer.table(e)) {
10337
+ e = e.substring(r.raw.length), t.push(r);
10338
+ continue;
10339
+ }
10340
+ if (r = this.tokenizer.lheading(e)) {
10341
+ e = e.substring(r.raw.length), t.push(r);
10342
+ continue;
10343
+ }
10344
+ let i = e;
10345
+ if (this.options.extensions?.startBlock) {
10346
+ let o = 1 / 0, u = e.slice(1), a;
10347
+ this.options.extensions.startBlock.forEach((p) => {
10348
+ a = p.call({ lexer: this }, u), typeof a == "number" && a >= 0 && (o = Math.min(o, a));
10349
+ }), o < 1 / 0 && o >= 0 && (i = e.substring(0, o + 1));
10350
+ }
10351
+ if (this.state.top && (r = this.tokenizer.paragraph(i))) {
10352
+ let o = t.at(-1);
10353
+ n && o?.type === "paragraph" ? (o.raw += (o.raw.endsWith(`
10354
+ `) ? "" : `
10355
+ `) + r.raw, o.text += `
10356
+ ` + 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);
10357
+ continue;
10358
+ }
10359
+ if (r = this.tokenizer.text(e)) {
10360
+ e = e.substring(r.raw.length);
10361
+ let o = t.at(-1);
10362
+ o?.type === "text" ? (o.raw += (o.raw.endsWith(`
10363
+ `) ? "" : `
10364
+ `) + r.raw, o.text += `
10365
+ ` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = o.text) : t.push(r);
10366
+ continue;
10367
+ }
10368
+ if (e) {
10369
+ this.infiniteLoopError(e.charCodeAt(0));
10370
+ break;
10371
+ }
10372
+ }
10373
+ return this.state.top = !0, t;
10374
+ }
10375
+ inline(e, t = []) {
10376
+ return this.inlineQueue.push({
10377
+ src: e,
10378
+ tokens: t
10379
+ }), t;
10380
+ }
10381
+ linkInText(e) {
10382
+ if (!e.includes("[")) return !1;
10383
+ let t = this.tokenizer.rules.inline.link;
10384
+ for (let n of e.matchAll(this.tokenizer.rules.inline.blockSkip)) if (t.test(n[0]) && e.charAt(n.index - 1) !== "!") return !0;
10385
+ for (let n of e.matchAll(this.tokenizer.rules.inline.reflinkSearch)) {
10386
+ let s = n[0], r = s.lastIndexOf("[");
10387
+ if (!(s.charAt(0) === "!" || !Object.hasOwn(this.tokens.links, s.slice(r + 1, -1))) && !(r > 1 && this.linkInText(s.slice(1, r - 1)))) return !0;
10388
+ }
10389
+ return !1;
10390
+ }
10391
+ inlineTokens(e, t = []) {
10392
+ this.tokenizer.lexer = this;
10393
+ let n = e;
10394
+ if (this.tokens.links && e.includes("[")) {
10395
+ let o = this.tokenizer.rules.inline.reflinkSearch, u = (a) => {
10396
+ let p = a.lastIndexOf("[");
10397
+ if (!Object.hasOwn(this.tokens.links, a.slice(p + 1, -1))) return a;
10398
+ if (p > 1 && a.charAt(0) !== "!") {
10399
+ let c = a.slice(1, p - 1);
10400
+ if (this.linkInText(c)) return "[" + c.replace(o, u) + "][" + "a".repeat(a.length - p - 2) + "]";
10401
+ }
10402
+ return "[" + "a".repeat(a.length - 2) + "]";
10403
+ };
10404
+ n = n.replace(o, u);
10405
+ }
10406
+ n = n.replace(this.tokenizer.rules.inline.anyPunctuation, (o) => "+".repeat(o.length)), n = n.replace(this.tokenizer.rules.inline.blockSkip, (o, u, a) => {
10407
+ let p = a ? a.length : 0;
10408
+ return o.slice(0, p) + "[" + "a".repeat(o.length - p - 2) + "]";
10409
+ }), n = this.options.hooks?.emStrongMask?.call({ lexer: this }, n) ?? n;
10410
+ let s = !1, r = "", i = 1 / 0;
10411
+ for (; e;) {
10412
+ if (e.length < i) i = e.length;
10413
+ else {
10414
+ this.infiniteLoopError(e.charCodeAt(0));
10415
+ break;
10416
+ }
10417
+ s || (r = ""), s = !1;
10418
+ let o;
10419
+ if (this.options.extensions?.inline?.some((a) => (o = a.call({ lexer: this }, e, t)) ? (e = e.substring(o.raw.length), t.push(o), !0) : !1)) continue;
10420
+ if (o = this.tokenizer.escape(e)) {
10421
+ e = e.substring(o.raw.length), t.push(o);
10422
+ continue;
10423
+ }
10424
+ if (o = this.tokenizer.tag(e)) {
10425
+ e = e.substring(o.raw.length), t.push(o);
10426
+ continue;
10427
+ }
10428
+ if (o = this.tokenizer.link(e)) {
10429
+ e = e.substring(o.raw.length), t.push(o);
10430
+ continue;
10431
+ }
10432
+ if (o = this.tokenizer.reflink(e, this.tokens.links)) {
10433
+ e = e.substring(o.raw.length);
10434
+ let a = t.at(-1);
10435
+ o.type === "text" && a?.type === "text" ? (a.raw += o.raw, a.text += o.text) : t.push(o);
10436
+ continue;
10437
+ }
10438
+ if (o = this.tokenizer.emStrong(e, n, r)) {
10439
+ e = e.substring(o.raw.length), t.push(o);
10440
+ continue;
10441
+ }
10442
+ if (o = this.tokenizer.codespan(e)) {
10443
+ e = e.substring(o.raw.length), t.push(o);
10444
+ continue;
10445
+ }
10446
+ if (o = this.tokenizer.br(e)) {
10447
+ e = e.substring(o.raw.length), t.push(o);
10448
+ continue;
10449
+ }
10450
+ if (o = this.tokenizer.del(e, n, r)) {
10451
+ e = e.substring(o.raw.length), t.push(o);
10452
+ continue;
10453
+ }
10454
+ if (o = this.tokenizer.autolink(e)) {
10455
+ e = e.substring(o.raw.length), t.push(o);
10456
+ continue;
10457
+ }
10458
+ if (!this.state.inLink && (o = this.tokenizer.url(e))) {
10459
+ e = e.substring(o.raw.length), t.push(o);
10460
+ continue;
10461
+ }
10462
+ let u = e;
10463
+ if (this.options.extensions?.startInline) {
10464
+ let a = 1 / 0, p = e.slice(1), c;
10465
+ this.options.extensions.startInline.forEach((h) => {
10466
+ c = h.call({ lexer: this }, p), typeof c == "number" && c >= 0 && (a = Math.min(a, c));
10467
+ }), a < 1 / 0 && a >= 0 && (u = e.substring(0, a + 1));
10468
+ }
10469
+ if (o = this.tokenizer.inlineText(u)) {
10470
+ e = e.substring(o.raw.length), o.raw.slice(-1) !== "_" && (r = o.raw.slice(-1)), s = !0;
10471
+ let a = t.at(-1);
10472
+ a?.type === "text" ? (a.raw += o.raw, a.text += o.text) : t.push(o);
10473
+ continue;
10474
+ }
10475
+ if (e) {
10476
+ this.infiniteLoopError(e.charCodeAt(0));
10477
+ break;
10478
+ }
10479
+ }
10480
+ return t;
10481
+ }
10482
+ infiniteLoopError(e) {
10483
+ let t = "Infinite loop on byte: " + e;
10484
+ if (this.options.silent) console.error(t);
10485
+ else throw new Error(t);
10486
+ }
10487
+ };
10488
+ var P = class {
10489
+ options;
10490
+ parser;
10491
+ constructor(e) {
10492
+ this.options = e || R;
10493
+ }
10494
+ space(e) {
10495
+ return "";
10496
+ }
10497
+ code({ text: e, lang: t, escaped: n }) {
10498
+ let s = (t || "").match(m.notSpaceStart)?.[0], r = e.replace(m.endingNewline, "") + `
10499
+ `;
10500
+ return s ? "<pre><code class=\"language-" + T(s) + "\">" + (n ? r : T(r, !0)) + `</code></pre>
10501
+ ` : "<pre><code>" + (n ? r : T(r, !0)) + `</code></pre>
10502
+ `;
10503
+ }
10504
+ blockquote({ tokens: e }) {
10505
+ return `<blockquote>
10506
+ ${this.parser.parse(e)}</blockquote>
10507
+ `;
10508
+ }
10509
+ html({ text: e }) {
10510
+ return e;
10511
+ }
10512
+ def(e) {
10513
+ return "";
10514
+ }
10515
+ heading({ tokens: e, depth: t }) {
10516
+ return `<h${t}>${this.parser.parseInline(e)}</h${t}>
10517
+ `;
10518
+ }
10519
+ hr(e) {
10520
+ return `<hr>
10521
+ `;
10522
+ }
10523
+ list(e) {
10524
+ let t = e.ordered, n = e.start, s = "";
10525
+ for (let o = 0; o < e.items.length; o++) {
10526
+ let u = e.items[o];
10527
+ s += this.listitem(u);
10528
+ }
10529
+ let r = t ? "ol" : "ul", i = t && n !== 1 ? " start=\"" + n + "\"" : "";
10530
+ return "<" + r + i + `>
10531
+ ` + s + "</" + r + `>
10532
+ `;
10533
+ }
10534
+ listitem(e) {
10535
+ return `<li>${this.parser.parse(e.tokens)}</li>
10536
+ `;
10537
+ }
10538
+ checkbox({ checked: e }) {
10539
+ return "<input " + (e ? "checked=\"\" " : "") + "disabled=\"\" type=\"checkbox\"> ";
10540
+ }
10541
+ paragraph({ tokens: e }) {
10542
+ return `<p>${this.parser.parseInline(e)}</p>
10543
+ `;
10544
+ }
10545
+ table(e) {
10546
+ let t = "", n = "";
10547
+ for (let r = 0; r < e.header.length; r++) n += this.tablecell(e.header[r]);
10548
+ t += this.tablerow({ text: n });
10549
+ let s = "";
10550
+ for (let r = 0; r < e.rows.length; r++) {
10551
+ let i = e.rows[r];
10552
+ n = "";
10553
+ for (let o = 0; o < i.length; o++) n += this.tablecell(i[o]);
10554
+ s += this.tablerow({ text: n });
10555
+ }
10556
+ return s && (s = `<tbody>${s}</tbody>`), `<table>
10557
+ <thead>
10558
+ ` + t + `</thead>
10559
+ ` + s + `</table>
10560
+ `;
10561
+ }
10562
+ tablerow({ text: e }) {
10563
+ return `<tr>
10564
+ ${e}</tr>
10565
+ `;
10566
+ }
10567
+ tablecell(e) {
10568
+ let t = this.parser.parseInline(e.tokens), n = e.header ? "th" : "td";
10569
+ return (e.align ? `<${n} align="${e.align}">` : `<${n}>`) + t + `</${n}>
10570
+ `;
10571
+ }
10572
+ strong({ tokens: e }) {
10573
+ return `<strong>${this.parser.parseInline(e)}</strong>`;
10574
+ }
10575
+ em({ tokens: e }) {
10576
+ return `<em>${this.parser.parseInline(e)}</em>`;
10577
+ }
10578
+ codespan({ text: e }) {
10579
+ return `<code>${T(e, !0)}</code>`;
10580
+ }
10581
+ br(e) {
10582
+ return "<br>";
10583
+ }
10584
+ del({ tokens: e }) {
10585
+ return `<del>${this.parser.parseInline(e)}</del>`;
10586
+ }
10587
+ link({ href: e, title: t, tokens: n }) {
10588
+ let s = this.parser.parseInline(n), r = Y(e);
10589
+ if (r === null) return s;
10590
+ e = r;
10591
+ let i = "<a href=\"" + e + "\"";
10592
+ return t && (i += " title=\"" + T(t) + "\""), i += ">" + s + "</a>", i;
10593
+ }
10594
+ image({ href: e, title: t, text: n, tokens: s }) {
10595
+ s && (n = this.parser.parseInline(s, this.parser.textRenderer));
10596
+ let r = Y(e);
10597
+ if (r === null) return T(n);
10598
+ e = r;
10599
+ let i = `<img src="${e}" alt="${T(n)}"`;
10600
+ return t && (i += ` title="${T(t)}"`), i += ">", i;
10601
+ }
10602
+ text(e) {
10603
+ return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : "escaped" in e && e.escaped ? e.text : T(e.text);
10604
+ }
10605
+ };
10606
+ var L = class {
10607
+ strong({ text: e }) {
10608
+ return e;
10609
+ }
10610
+ em({ text: e }) {
10611
+ return e;
10612
+ }
10613
+ codespan({ text: e }) {
10614
+ return e;
10615
+ }
10616
+ del({ text: e }) {
10617
+ return e;
10618
+ }
10619
+ html({ text: e }) {
10620
+ return e;
10621
+ }
10622
+ text({ text: e }) {
10623
+ return e;
10624
+ }
10625
+ link({ text: e }) {
10626
+ return "" + e;
10627
+ }
10628
+ image({ text: e }) {
10629
+ return "" + e;
10630
+ }
10631
+ br() {
10632
+ return "";
10633
+ }
10634
+ checkbox({ raw: e }) {
10635
+ return e;
10636
+ }
10637
+ };
10638
+ var b = class l {
10639
+ options;
10640
+ renderer;
10641
+ textRenderer;
10642
+ constructor(e) {
10643
+ this.options = e || R, this.options.renderer = this.options.renderer || new P(), this.renderer = this.options.renderer, this.renderer.options = this.options, this.renderer.parser = this, this.textRenderer = new L();
10644
+ }
10645
+ static parse(e, t) {
10646
+ return new l(t).parse(e);
10647
+ }
10648
+ static parseInline(e, t) {
10649
+ return new l(t).parseInline(e);
10650
+ }
10651
+ parse(e) {
10652
+ this.renderer.parser = this;
10653
+ let t = "";
10654
+ for (let n = 0; n < e.length; n++) {
10655
+ let s = e[n];
10656
+ if (this.options.extensions?.renderers?.[s.type]) {
10657
+ let i = s, o = this.options.extensions.renderers[i.type].call({ parser: this }, i);
10658
+ if (o !== !1 || ![
10659
+ "space",
10660
+ "hr",
10661
+ "heading",
10662
+ "code",
10663
+ "table",
10664
+ "blockquote",
10665
+ "list",
10666
+ "checkbox",
10667
+ "html",
10668
+ "def",
10669
+ "paragraph",
10670
+ "text"
10671
+ ].includes(i.type)) {
10672
+ t += o || "";
10673
+ continue;
10674
+ }
10675
+ }
10676
+ let r = s;
10677
+ switch (r.type) {
10678
+ case "space":
10679
+ t += this.renderer.space(r);
10680
+ break;
10681
+ case "hr":
10682
+ t += this.renderer.hr(r);
10683
+ break;
10684
+ case "heading":
10685
+ t += this.renderer.heading(r);
10686
+ break;
10687
+ case "code":
10688
+ t += this.renderer.code(r);
10689
+ break;
10690
+ case "table":
10691
+ t += this.renderer.table(r);
10692
+ break;
10693
+ case "blockquote":
10694
+ t += this.renderer.blockquote(r);
10695
+ break;
10696
+ case "list":
10697
+ t += this.renderer.list(r);
10698
+ break;
10699
+ case "checkbox":
10700
+ t += this.renderer.checkbox(r);
10701
+ break;
10702
+ case "html":
10703
+ t += this.renderer.html(r);
10704
+ break;
10705
+ case "def":
10706
+ t += this.renderer.def(r);
10707
+ break;
10708
+ case "paragraph":
10709
+ t += this.renderer.paragraph(r);
10710
+ break;
10711
+ case "text":
10712
+ t += this.renderer.text(r);
10713
+ break;
10714
+ default: {
10715
+ let i = "Token with \"" + r.type + "\" type was not found.";
10716
+ if (this.options.silent) return console.error(i), "";
10717
+ throw new Error(i);
10718
+ }
10719
+ }
10720
+ }
10721
+ return t;
10722
+ }
10723
+ parseInline(e, t = this.renderer) {
10724
+ this.renderer.parser = this;
10725
+ let n = "";
10726
+ for (let s = 0; s < e.length; s++) {
10727
+ let r = e[s];
10728
+ if (this.options.extensions?.renderers?.[r.type]) {
10729
+ let o = this.options.extensions.renderers[r.type].call({ parser: this }, r);
10730
+ if (o !== !1 || ![
10731
+ "escape",
10732
+ "html",
10733
+ "link",
10734
+ "image",
10735
+ "checkbox",
10736
+ "strong",
10737
+ "em",
10738
+ "codespan",
10739
+ "br",
10740
+ "del",
10741
+ "text"
10742
+ ].includes(r.type)) {
10743
+ n += o || "";
10744
+ continue;
10745
+ }
10746
+ }
10747
+ let i = r;
10748
+ switch (i.type) {
10749
+ case "escape":
10750
+ n += t.text(i);
10751
+ break;
10752
+ case "html":
10753
+ n += t.html(i);
10754
+ break;
10755
+ case "link":
10756
+ n += t.link(i);
10757
+ break;
10758
+ case "image":
10759
+ n += t.image(i);
10760
+ break;
10761
+ case "checkbox":
10762
+ n += t.checkbox(i);
10763
+ break;
10764
+ case "strong":
10765
+ n += t.strong(i);
10766
+ break;
10767
+ case "em":
10768
+ n += t.em(i);
10769
+ break;
10770
+ case "codespan":
10771
+ n += t.codespan(i);
10772
+ break;
10773
+ case "br":
10774
+ n += t.br(i);
10775
+ break;
10776
+ case "del":
10777
+ n += t.del(i);
10778
+ break;
10779
+ case "text":
10780
+ n += t.text(i);
10781
+ break;
10782
+ default: {
10783
+ let o = "Token with \"" + i.type + "\" type was not found.";
10784
+ if (this.options.silent) return console.error(o), "";
10785
+ throw new Error(o);
10786
+ }
10787
+ }
10788
+ }
10789
+ return n;
10790
+ }
10791
+ };
10792
+ var S = class {
10793
+ options;
10794
+ block;
10795
+ constructor(e) {
10796
+ this.options = e || R;
10797
+ }
10798
+ static passThroughHooks = /* @__PURE__ */ new Set([
10799
+ "preprocess",
10800
+ "postprocess",
10801
+ "processAllTokens",
10802
+ "emStrongMask"
10803
+ ]);
10804
+ static passThroughHooksRespectAsync = /* @__PURE__ */ new Set([
10805
+ "preprocess",
10806
+ "postprocess",
10807
+ "processAllTokens"
10808
+ ]);
10809
+ preprocess(e) {
10810
+ return e;
10811
+ }
10812
+ postprocess(e) {
10813
+ return e;
10814
+ }
10815
+ processAllTokens(e) {
10816
+ return e;
10817
+ }
10818
+ emStrongMask(e) {
10819
+ return e;
10820
+ }
10821
+ provideLexer(e = this.block) {
10822
+ return e ? x.lex : x.lexInline;
10823
+ }
10824
+ provideParser(e = this.block) {
10825
+ return e ? b.parse : b.parseInline;
10826
+ }
10827
+ };
10828
+ var Z = class {
10829
+ defaults = A();
10830
+ options = this.setOptions;
10831
+ parse = this.parseMarkdown(!0);
10832
+ parseInline = this.parseMarkdown(!1);
10833
+ Parser = b;
10834
+ Renderer = P;
10835
+ TextRenderer = L;
10836
+ Lexer = x;
10837
+ Tokenizer = y;
10838
+ Hooks = S;
10839
+ constructor(...e) {
10840
+ this.use(...e);
10841
+ }
10842
+ walkTokens(e, t) {
10843
+ let n = [];
10844
+ for (let s of e) switch (n = n.concat(t.call(this, s)), s.type) {
10845
+ case "table": {
10846
+ let r = s;
10847
+ for (let i of r.header) n = n.concat(this.walkTokens(i.tokens, t));
10848
+ for (let i of r.rows) for (let o of i) n = n.concat(this.walkTokens(o.tokens, t));
10849
+ break;
10850
+ }
10851
+ case "list": {
10852
+ let r = s;
10853
+ n = n.concat(this.walkTokens(r.items, t));
10854
+ break;
10855
+ }
10856
+ default: {
10857
+ let r = s;
10858
+ this.defaults.extensions?.childTokens?.[r.type] ? this.defaults.extensions.childTokens[r.type].forEach((i) => {
10859
+ let o = r[i].flat(1 / 0);
10860
+ n = n.concat(this.walkTokens(o, t));
10861
+ }) : r.tokens && (n = n.concat(this.walkTokens(r.tokens, t)));
10862
+ }
10863
+ }
10864
+ return n;
10865
+ }
10866
+ use(...e) {
10867
+ let t = this.defaults.extensions || {
10868
+ renderers: {},
10869
+ childTokens: {}
10870
+ };
10871
+ return e.forEach((n) => {
10872
+ let s = { ...n };
10873
+ if (s.async = this.defaults.async || s.async || !1, n.extensions && (n.extensions.forEach((r) => {
10874
+ if (!r.name) throw new Error("extension name required");
10875
+ if ("renderer" in r) {
10876
+ let i = t.renderers[r.name];
10877
+ i ? t.renderers[r.name] = function(...o) {
10878
+ let u = r.renderer.apply(this, o);
10879
+ return u === !1 && (u = i.apply(this, o)), u;
10880
+ } : t.renderers[r.name] = r.renderer;
10881
+ }
10882
+ if ("tokenizer" in r) {
10883
+ if (!r.level || r.level !== "block" && r.level !== "inline") throw new Error("extension level must be 'block' or 'inline'");
10884
+ let i = t[r.level];
10885
+ 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]));
10886
+ }
10887
+ "childTokens" in r && r.childTokens && (t.childTokens[r.name] = r.childTokens);
10888
+ }), s.extensions = t), n.renderer) {
10889
+ let r = this.defaults.renderer || new P(this.defaults);
10890
+ for (let i in n.renderer) {
10891
+ if (!(i in r)) throw new Error(`renderer '${i}' does not exist`);
10892
+ if (["options", "parser"].includes(i)) continue;
10893
+ let o = i, u = n.renderer[o], a = r[o];
10894
+ r[o] = (...p) => {
10895
+ let c = u.apply(r, p);
10896
+ return c === !1 && (c = a.apply(r, p)), c || "";
10897
+ };
10898
+ }
10899
+ s.renderer = r;
10900
+ }
10901
+ if (n.tokenizer) {
10902
+ let r = this.defaults.tokenizer || new y(this.defaults);
10903
+ for (let i in n.tokenizer) {
10904
+ if (!(i in r)) throw new Error(`tokenizer '${i}' does not exist`);
10905
+ if ([
10906
+ "options",
10907
+ "rules",
10908
+ "lexer"
10909
+ ].includes(i)) continue;
10910
+ let o = i, u = n.tokenizer[o], a = r[o];
10911
+ r[o] = (...p) => {
10912
+ let c = u.apply(r, p);
10913
+ return c === !1 && (c = a.apply(r, p)), c;
10914
+ };
10915
+ }
10916
+ s.tokenizer = r;
10917
+ }
10918
+ if (n.hooks) {
10919
+ let r = this.defaults.hooks || new S();
10920
+ for (let i in n.hooks) {
10921
+ if (!(i in r)) throw new Error(`hook '${i}' does not exist`);
10922
+ if (["options", "block"].includes(i)) continue;
10923
+ let o = i, u = n.hooks[o], a = r[o];
10924
+ S.passThroughHooks.has(i) ? r[o] = (p) => {
10925
+ if (this.defaults.async && S.passThroughHooksRespectAsync.has(i)) return (async () => {
10926
+ let h = await u.call(r, p);
10927
+ return a.call(r, h);
10928
+ })();
10929
+ let c = u.call(r, p);
10930
+ return a.call(r, c);
10931
+ } : r[o] = (...p) => {
10932
+ if (this.defaults.async) return (async () => {
10933
+ let h = await u.apply(r, p);
10934
+ return h === !1 && (h = await a.apply(r, p)), h;
10935
+ })();
10936
+ let c = u.apply(r, p);
10937
+ return c === !1 && (c = a.apply(r, p)), c;
10938
+ };
10939
+ }
10940
+ s.hooks = r;
10941
+ }
10942
+ if (n.walkTokens) {
10943
+ let r = this.defaults.walkTokens, i = n.walkTokens;
10944
+ s.walkTokens = function(o) {
10945
+ let u = [];
10946
+ return u.push(i.call(this, o)), r && (u = u.concat(r.call(this, o))), u;
10947
+ };
10948
+ }
10949
+ this.defaults = {
10950
+ ...this.defaults,
10951
+ ...s
10952
+ };
10953
+ }), this;
10954
+ }
10955
+ setOptions(e) {
10956
+ return this.defaults = {
10957
+ ...this.defaults,
10958
+ ...e
10959
+ }, this;
10960
+ }
10961
+ lexer(e, t) {
10962
+ return x.lex(e, t ?? this.defaults);
10963
+ }
10964
+ parser(e, t) {
10965
+ return b.parse(e, t ?? this.defaults);
10966
+ }
10967
+ parseMarkdown(e) {
10968
+ return (n, s) => {
10969
+ let r = { ...s }, i = {
10970
+ ...this.defaults,
10971
+ ...r
10972
+ }, o = this.onError(!!i.silent, !!i.async);
10973
+ if (this.defaults.async === !0 && r.async === !1) return o(/* @__PURE__ */ 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."));
10974
+ if (typeof n > "u" || n === null) return o(/* @__PURE__ */ new Error("marked(): input parameter is undefined or null"));
10975
+ if (typeof n != "string") return o(/* @__PURE__ */ new Error("marked(): input parameter is of type " + Object.prototype.toString.call(n) + ", string expected"));
10976
+ if (i.hooks && (i.hooks.options = i, i.hooks.block = e), i.async) return (async () => {
10977
+ let u = i.hooks ? await i.hooks.preprocess(n) : n, p = await (i.hooks ? await i.hooks.provideLexer(e) : e ? x.lex : x.lexInline)(u, i), c = i.hooks ? await i.hooks.processAllTokens(p) : p;
10978
+ i.walkTokens && await Promise.all(this.walkTokens(c, i.walkTokens));
10979
+ let d = await (i.hooks ? await i.hooks.provideParser(e) : e ? b.parse : b.parseInline)(c, i);
10980
+ return i.hooks ? await i.hooks.postprocess(d) : d;
10981
+ })().catch(o);
10982
+ try {
10983
+ i.hooks && (n = i.hooks.preprocess(n));
10984
+ let a = (i.hooks ? i.hooks.provideLexer(e) : e ? x.lex : x.lexInline)(n, i);
10985
+ i.hooks && (a = i.hooks.processAllTokens(a)), i.walkTokens && this.walkTokens(a, i.walkTokens);
10986
+ let c = (i.hooks ? i.hooks.provideParser(e) : e ? b.parse : b.parseInline)(a, i);
10987
+ return i.hooks && (c = i.hooks.postprocess(c)), c;
10988
+ } catch (u) {
10989
+ return o(u);
10990
+ }
10991
+ };
10992
+ }
10993
+ onError(e, t) {
10994
+ return (n) => {
10995
+ if (n.message += `
10996
+ Please report this to https://github.com/markedjs/marked.`, e) {
10997
+ let s = "<p>An error occurred:</p><pre>" + T(n.message + "", !0) + "</pre>";
10998
+ return t ? Promise.resolve(s) : s;
10999
+ }
11000
+ if (t) return Promise.reject(n);
11001
+ throw n;
11002
+ };
11003
+ }
11004
+ };
11005
+ var M = new Z();
11006
+ function f(l, e) {
11007
+ return M.parse(l, e);
11008
+ }
11009
+ f.options = f.setOptions = function(l) {
11010
+ return M.setOptions(l), f.defaults = M.defaults, j(f.defaults), f;
11011
+ };
11012
+ f.getDefaults = A;
11013
+ f.defaults = R;
11014
+ function dt(...l) {
11015
+ return M.use(...l), f.defaults = M.defaults, j(f.defaults), f;
11016
+ }
11017
+ f.use = dt;
11018
+ f.walkTokens = function(l, e) {
11019
+ return M.walkTokens(l, e);
11020
+ };
11021
+ f.parseInline = M.parseInline;
11022
+ f.Parser = b;
11023
+ f.parser = b.parse;
11024
+ f.Renderer = P;
11025
+ f.TextRenderer = L;
11026
+ f.Lexer = x;
11027
+ f.lexer = x.lex;
11028
+ f.Tokenizer = y;
11029
+ f.Hooks = S;
11030
+ f.parse = f;
11031
+ f.options;
11032
+ f.setOptions;
11033
+ f.walkTokens;
11034
+ f.parseInline;
11035
+ b.parse;
11036
+ x.lex;
11037
+ //#endregion
9339
11038
  //#region src/skiff-debug.ts
9340
11039
  /**
9341
11040
  * skiff-debug.ts — Skiff 调试问答页(F4a',v1.25.x 实验性)
@@ -9434,6 +11133,13 @@ function skiffDebugPage(cccs, defaultRoot, webPort) {
9434
11133
  .sub { opacity: .65; font-size: 13px; margin-bottom: 16px; }
9435
11134
  .ccc { display: inline-block; padding: 3px 10px; border-radius: 999px; background: rgba(11,168,117,.12); color: #0ba875; font-size: 12px; font-weight: 600; margin-bottom: 12px; word-break: break-all; }
9436
11135
  @media (prefers-color-scheme: dark) { .ccc { color: #3ddc9a; } }
11136
+ .sessionbar { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
11137
+ .session-badge { font-family: ui-monospace, SFMono-Regular, monospace; font-size: 12px; padding: 3px 10px; border-radius: 999px; background: rgba(127,127,127,.12); word-break: break-all; }
11138
+ .session-badge.continued { background: rgba(11,168,117,.12); color: #0ba875; }
11139
+ @media (prefers-color-scheme: dark) { .session-badge.continued { color: #3ddc9a; } }
11140
+ button.ghost { background: transparent; color: #57606a; border: 1px solid #d0d7de; padding: 4px 12px; font-size: 12px; border-radius: 8px; cursor: pointer; margin-top: 0; }
11141
+ @media (prefers-color-scheme: dark) { button.ghost { color: #8b949e; border-color: #3a3d42; } }
11142
+ button.ghost:hover { background: rgba(127,127,127,.1); }
9437
11143
  label { font-size: 13px; font-weight: 600; display: block; margin: 12px 0 4px; }
9438
11144
  select, textarea { width: 100%; box-sizing: border-box; padding: 8px 10px; border-radius: 8px; border: 1px solid #d0d7de; background: #fff; color: inherit; font-size: 14px; }
9439
11145
  @media (prefers-color-scheme: dark) { select, textarea { background: #26282c; border-color: #3a3d42; } }
@@ -9470,14 +11176,18 @@ function skiffDebugPage(cccs, defaultRoot, webPort) {
9470
11176
  <body>
9471
11177
  <main>
9472
11178
  <h1>Skiff Debug</h1>
9473
- <div class="sub">宁静号 trajectory 子集角色问答页(v1.25.4 实验性)— 多 CCC 可切换,走 DSH agent-loop 会话核心,轨迹与 WebUI 同源</div>
11179
+ <div class="sub">宁静号 trajectory 子集角色问答页(v1.25.10 实验性)— 多 CCC 可切换,同会话可追问(新对话按钮开新会话),回答 marked 服务端渲染 + think 折叠</div>
9474
11180
  <div class="ccc" id="cccBadge"></div>
11181
+ <div class="sessionbar">
11182
+ <span id="sessionBadge" class="session-badge muted">(新会话)</span>
11183
+ <button id="newChat" type="button" class="ghost">新对话</button>
11184
+ </div>
9475
11185
  <label for="ccc">认知容器</label>
9476
11186
  <select id="ccc"></select>
9477
11187
  <label for="role">角色</label>
9478
11188
  <select id="role"></select>
9479
11189
  <label for="q">问题</label>
9480
- <textarea id="q" placeholder="向该角色提问…"></textarea>
11190
+ <textarea id="q" placeholder="向该角色提问…(追问直接继续输入)"></textarea>
9481
11191
  <button id="ask">提问</button>
9482
11192
  <div id="answer" class="muted">等待提问…</div>
9483
11193
  <div id="trajectory"></div>
@@ -9490,10 +11200,26 @@ const defaultRoot = document.getElementById('skiff-data').dataset.default
9490
11200
  const cccSel = document.getElementById('ccc')
9491
11201
  const roleSel = document.getElementById('role')
9492
11202
  const badge = document.getElementById('cccBadge')
11203
+ const sessionBadge = document.getElementById('sessionBadge')
11204
+ const newChatBtn = document.getElementById('newChat')
9493
11205
  const btn = document.getElementById('ask')
9494
11206
  const answer = document.getElementById('answer')
9495
11207
  const traj = document.getElementById('trajectory')
9496
11208
  const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]))
11209
+ let sessionId = ''
11210
+ function shortId(id) { return id.length > 24 ? id.slice(0, 18) + '…' + id.slice(-6) : id }
11211
+ function renderSessionBadge() {
11212
+ sessionBadge.textContent = sessionId ? '会话 ' + shortId(sessionId) + '(追问续接)' : '(新会话)'
11213
+ sessionBadge.className = 'session-badge' + (sessionId ? ' continued' : '')
11214
+ }
11215
+ function newConversation() {
11216
+ sessionId = ''
11217
+ renderSessionBadge()
11218
+ answer.className = 'muted'
11219
+ answer.textContent = '已开启新对话'
11220
+ traj.innerHTML = ''
11221
+ document.getElementById('q').value = ''
11222
+ }
9497
11223
  function currentCcc() {
9498
11224
  return CCCS.find((c) => c.root === cccSel.value) || (CCCS[0] || { root: '', name: '', roles: [] })
9499
11225
  }
@@ -9512,8 +11238,11 @@ function fillRoles() {
9512
11238
  ? c.roles.map((r) => '<option value="' + esc(r) + '">' + esc(r) + '</option>').join('')
9513
11239
  : '<option value="">(未配置角色)</option>'
9514
11240
  }
9515
- cccSel.addEventListener('change', fillRoles)
11241
+ cccSel.addEventListener('change', () => { fillRoles(); newConversation() })
11242
+ roleSel.addEventListener('change', () => newConversation())
11243
+ newChatBtn.addEventListener('click', newConversation)
9516
11244
  fillCccs()
11245
+ renderSessionBadge()
9517
11246
  btn.addEventListener('click', async () => {
9518
11247
  const c = currentCcc()
9519
11248
  const role = roleSel.value
@@ -9524,11 +11253,18 @@ btn.addEventListener('click', async () => {
9524
11253
  answer.textContent = '运行中…'
9525
11254
  traj.innerHTML = ''
9526
11255
  try {
9527
- const res = await fetch('/ask', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ ccc: c.root, role, question: q }) })
11256
+ const res = await fetch('/ask', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ ccc: c.root, role, question: q, sessionId: sessionId || undefined }) })
9528
11257
  const data = await res.json()
9529
- if (!res.ok) throw new Error(data.error || ('HTTP ' + res.status))
11258
+ if (!res.ok) {
11259
+ // 会话不可恢复/绑定不匹配 → 前端清空 sessionId 重建(用户拍板:切换即新对话)
11260
+ sessionId = ''
11261
+ renderSessionBadge()
11262
+ throw new Error(data.error || ('HTTP ' + res.status))
11263
+ }
9530
11264
  answer.className = ''
9531
- answer.innerHTML = data.answer ? renderMd(data.answer) : '(空回答)'
11265
+ answer.innerHTML = data.answer_html || esc(data.answer || '') || '(空回答)'
11266
+ sessionId = data.sessionId || sessionId
11267
+ renderSessionBadge()
9532
11268
  renderTrajectory(data.trajectory || [], data.sessionId || '')
9533
11269
  } catch (err) {
9534
11270
  answer.className = 'err'
@@ -9545,58 +11281,6 @@ function renderTrajectory(entries, sessionId) {
9545
11281
  return '<div class="t-entry ' + cls + '"><div class="t-role">' + role + '</div>' + esc(e.text) + '</div>'
9546
11282
  }).join('')
9547
11283
  }
9548
- /* v1.25.8 Markdown 渲染(零依赖轻量)——标题/粗斜体/行内代码/代码块/列表/引用/链接;
9549
- <think>…</think> 块提取为 <details> 折叠(🧠 思考过程,默认收起) */
9550
- function renderMd(src) {
9551
- const thinks = []
9552
- let body = String(src || '')
9553
- body = body.replace(/<think>([\s\S]*?)<\/think>/gi, (_m, inner) => {
9554
- const idx = thinks.length
9555
- thinks.push(esc(String(inner || '').trim()))
9556
- return '\u0000T' + idx + '\u0000'
9557
- })
9558
- const lines = body.split('\n')
9559
- let html = ''
9560
- let inCode = false
9561
- let codeBuf = []
9562
- let inList = false
9563
- for (const line of lines) {
9564
- // 代码围栏检测:反引号用 \u0060 转义(页面 JS 内嵌于 TS 模板字符串,裸反引号会提前终止模板)
9565
- const codeMatch = line.match(/^\u0060\u0060\u0060(\w*)\s*$/)
9566
- if (codeMatch) {
9567
- if (inCode) { html += '<pre><code>' + esc(codeBuf.join('\n')) + '</code></pre>'; codeBuf = []; inCode = false }
9568
- else inCode = true
9569
- continue
9570
- }
9571
- if (inCode) { codeBuf.push(line); continue }
9572
- const t = line.trim()
9573
- if (t === '') { inList = false; continue }
9574
- if (line.indexOf('\u0000T') >= 0) { html += line.replace(/\u0000T(\d+)\u0000/g, (_m2, i) => thinkHtml(thinks[Number(i)])); inList = false; continue }
9575
- const h = t.match(/^(#{1,3})\s+(.*)$/)
9576
- if (h) { const lvl = h[1].length; html += '<h' + lvl + '>' + inlineMd(h[2]) + '</h' + lvl + '>'; inList = false; continue }
9577
- const li = t.match(/^(?:[-*]|\d+[.)])\s+(.*)$/)
9578
- if (li) { if (!inList) { html += '<ul>'; inList = true } html += '<li>' + inlineMd(li[1]) + '</li>'; continue }
9579
- if (inList) { html += '</ul>'; inList = false }
9580
- const qt = t.match(/^>\s?(.*)$/)
9581
- if (qt) { html += '<blockquote>' + inlineMd(qt[1]) + '</blockquote>'; continue }
9582
- html += '<p>' + inlineMd(line) + '</p>'
9583
- }
9584
- if (inCode) html += '<pre><code>' + esc(codeBuf.join('\n')) + '</code></pre>'
9585
- if (inList) html += '</ul>'
9586
- return html
9587
- }
9588
- function inlineMd(s) {
9589
- let t = esc(s)
9590
- // 行内代码:反引号 \u0060 转义(页面 JS 内嵌于 TS 模板字符串,裸反引号提前终止模板)
9591
- t = t.replace(/[\u0060]([^\u0060]+)[\u0060]/g, '<code>$1</code>')
9592
- t = t.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
9593
- t = t.replace(/(^|[^*])\*([^*\n]+)\*/g, '$1<em>$2</em>')
9594
- t = t.replace(/\[([^\]]+)\]\((https?:[^)\s]+)\)/g, '<a href="$2" target="_blank" rel="noopener">$1</a>')
9595
- return t
9596
- }
9597
- function thinkHtml(inner) {
9598
- return '<details class="think"><summary>🧠 思考过程</summary><div class="think-body">' + (inner ? inner.replace(/\n/g, '<br>') : '(空)') + '</div></details>'
9599
- }
9600
11284
  <\/script>
9601
11285
  </body>
9602
11286
  </html>`;
@@ -9611,6 +11295,33 @@ function escapeHtml(s) {
9611
11295
  })[c] ?? c);
9612
11296
  }
9613
11297
  /**
11298
+ * Markdown 渲染(v1.25.9,正经库 marked 服务端渲染——替代手写正则渲染器,S142 用户要求):
11299
+ * ① 提取 `<think>…</think>` 块(占位符 \u0000T<idx>\u0000)
11300
+ * ② 正文与 think 内容**先 escapeHtml 再 marked.parse**(GFM + breaks)——markdown 语法不受
11301
+ * 转义影响,原始 HTML 注入被消除(安全);代码块内 `<` 显示为实体(可接受)
11302
+ * ③ think 占位符还原为 `<details class="think">` 折叠卡(🧠 思考过程,默认收起)
11303
+ */
11304
+ function renderSkiffMarkdown(raw) {
11305
+ const thinks = [];
11306
+ const body = raw.replace(/<think>([\s\S]*?)<\/think>/gi, (_m, inner) => {
11307
+ const idx = thinks.length;
11308
+ thinks.push(String(inner ?? "").trim());
11309
+ return `\u0000T${idx}\u0000`;
11310
+ });
11311
+ const parsed = f.parse(escapeHtml(body), {
11312
+ breaks: true,
11313
+ gfm: true
11314
+ });
11315
+ return (typeof parsed === "string" ? parsed : "").replace(/\u0000T(\d+)\u0000/g, (_m, idx) => {
11316
+ const inner = thinks[Number(idx)] ?? "";
11317
+ const innerHtml = inner === "" ? "" : f.parse(escapeHtml(inner), {
11318
+ breaks: true,
11319
+ gfm: true
11320
+ });
11321
+ return `<details class="think"><summary>🧠 思考过程</summary><div class="think-body">${typeof innerHtml === "string" ? innerHtml : ""}</div></details>`;
11322
+ });
11323
+ }
11324
+ /**
9614
11325
  * 启动调试问答服务(单实例;重复启动幂等返回既有实例)。
9615
11326
  *
9616
11327
  * **CCC 绑定(v1.25.2 用户指出)**:服务绑定一个默认 CCC root(调用方 resolveSkiffRoot
@@ -9663,6 +11374,7 @@ async function handle(ctx, defaultRoot, webPort, req, res) {
9663
11374
  const ccc = typeof body.ccc === "string" && body.ccc !== "" ? body.ccc : defaultRoot;
9664
11375
  const roleName = typeof body.role === "string" ? body.role : "";
9665
11376
  const question = typeof body.question === "string" ? body.question : "";
11377
+ const sessionId = typeof body.sessionId === "string" && body.sessionId !== "" ? body.sessionId : void 0;
9666
11378
  const role = readSkiffRoles(ccc).get(roleName);
9667
11379
  if (!roleName || !role) {
9668
11380
  sendJson(res, 400, { error: `unknown role: ${roleName} (ccc: ${ccc})` });
@@ -9672,10 +11384,30 @@ async function handle(ctx, defaultRoot, webPort, req, res) {
9672
11384
  sendJson(res, 400, { error: "empty question" });
9673
11385
  return;
9674
11386
  }
9675
- const result = await askSkiff(ctx, (await createSkiffAgent(ctx, ccc, roleName, role, readHandymanConfig(ccc)?.defaultModel)).agent, question);
11387
+ let agent;
11388
+ let continued = false;
11389
+ if (sessionId) {
11390
+ const info = skiffSessionInfo(sessionId);
11391
+ const live = getSkiffAgent(sessionId);
11392
+ if (!info || !live) {
11393
+ sendJson(res, 400, { error: "session is not recoverable (process restarted or session unknown) — start a new conversation" });
11394
+ return;
11395
+ }
11396
+ if (info.role !== roleName || info.ccc !== ccc) {
11397
+ sendJson(res, 400, { error: `session "${sessionId}" belongs to role "${info.role}" in another CCC — start a new conversation` });
11398
+ return;
11399
+ }
11400
+ agent = live;
11401
+ continued = true;
11402
+ }
11403
+ const hc = readHandymanConfig(ccc);
11404
+ if (!agent) agent = (await createSkiffAgent(ctx, ccc, roleName, role, hc?.defaultModel)).agent;
11405
+ const result = await askSkiff(ctx, agent, question, 0);
9676
11406
  sendJson(res, 200, {
9677
11407
  answer: result.answer,
11408
+ answer_html: renderSkiffMarkdown(result.answer),
9678
11409
  sessionId: result.sessionId,
11410
+ continued,
9679
11411
  trajectory: result.trajectory
9680
11412
  });
9681
11413
  return;