nx-kv 0.65.4 → 0.66.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 (242) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/assets/nx-kv/SKILL.md +7 -2
  3. package/assets/nx-kv/references/A02-/346/217/220/344/272/244/344/273/273/345/212/241.md +59 -4
  4. package/assets/nx-kv/references/A06-/345/217/202/350/200/203/344/273/223/345/272/223/351/251/261/345/212/250/347/232/204/345/274/200/345/217/221.md +143 -0
  5. package/assets/nx-kv/references/A07-/344/273/273/345/212/241/351/223/276/345/233/236/351/241/276/344/270/216/346/243/200/347/264/242.md +86 -0
  6. package/package.json +2 -2
  7. package/src/core/config.ts +49 -0
  8. package/src/core/db/driver.ts +1 -1
  9. package/src/core/db/migrations/index.ts +2 -0
  10. package/src/core/db/migrations/v14.sql +37 -0
  11. package/src/core/db/version.ts +1 -1
  12. package/src/core/workflow/types.ts +1 -1
  13. package/src/modules/bundled/actions/_manifest.generated.ts +12 -12
  14. package/src/modules/bundled/actions/{bundled-get.ts → skill-get.ts} +4 -4
  15. package/src/modules/bundled/actions/{bundled-groups.ts → skill-groups.ts} +4 -4
  16. package/src/modules/bundled/actions/{bundled-install.ts → skill-install.ts} +4 -4
  17. package/src/modules/bundled/actions/{bundled-list.ts → skill-list.ts} +4 -4
  18. package/src/modules/claim/actions/_manifest.generated.ts +3 -3
  19. package/src/modules/claim/actions/{localtask-claim.ts → localtask-get.ts} +15 -6
  20. package/src/modules/claim/index.ts +1 -1
  21. package/src/modules/claim/panel-escort.ts +1 -1
  22. package/src/modules/claim/wait.ts +5 -5
  23. package/src/modules/docs/actions/_manifest.generated.ts +37 -37
  24. package/src/modules/docs/actions/{doc-attach.ts → docs-attach.ts} +4 -4
  25. package/src/modules/docs/actions/{doc-attachments.ts → docs-attachments.ts} +4 -4
  26. package/src/modules/docs/actions/{doc-detach.ts → docs-detach.ts} +4 -4
  27. package/src/modules/docs/actions/{doc-get.ts → docs-get.ts} +4 -4
  28. package/src/modules/docs/actions/{doc-link-file.ts → docs-link-file.ts} +3 -3
  29. package/src/modules/docs/actions/{doc-list.ts → docs-list.ts} +4 -4
  30. package/src/modules/docs/actions/{doc-mdfile.ts → docs-mdfile.ts} +3 -3
  31. package/src/modules/docs/actions/{doc-mdfiles.ts → docs-mdfiles.ts} +3 -3
  32. package/src/modules/docs/actions/{docs-notebind.ts → docs-note-bind.ts} +3 -3
  33. package/src/modules/docs/actions/{doc-ref.ts → docs-ref.ts} +4 -4
  34. package/src/modules/docs/actions/{doc-remove.ts → docs-remove.ts} +4 -4
  35. package/src/modules/docs/actions/{doc-update.ts → docs-set.ts} +4 -4
  36. package/src/modules/docs/actions/{doc-unbind.ts → docs-unbind.ts} +4 -4
  37. package/src/modules/docs/host-scrub.ts +1 -1
  38. package/src/modules/docs/index.ts +1 -1
  39. package/src/modules/localtask/actions/_manifest.generated.ts +14 -14
  40. package/src/modules/localtask/actions/{localtask-cancelMany.ts → localtask-cancel-many.ts} +3 -3
  41. package/src/modules/localtask/actions/{localtask-closeMany.ts → localtask-close-many.ts} +3 -3
  42. package/src/modules/localtask/actions/{localtask-removeMany.ts → localtask-remove-many.ts} +3 -3
  43. package/src/modules/localtask/actions/{localtask-get.ts → localtask-show.ts} +14 -5
  44. package/src/modules/localtask/actions/localtask-tasks.ts +19 -4
  45. package/src/modules/localtask/actions/{localtask-timegoalLog.ts → localtask-timegoal-log.ts} +3 -3
  46. package/src/modules/localtask/actions/{localtask-topic-removeMany.ts → localtask-topic-remove-many.ts} +3 -3
  47. package/src/modules/localtask/infra/repo/links.ts +1 -1
  48. package/src/modules/localtask/infra/repo/settings.ts +4 -1
  49. package/src/modules/localtask/lifecycle/task-lifecycle.ts +11 -7
  50. package/src/modules/localtask/lifecycle/task-ops.ts +5 -4
  51. package/src/modules/localtask/lifecycle/task-remove.ts +1 -1
  52. package/src/modules/localtask/lifecycle/task-view.ts +25 -0
  53. package/src/modules/localtask/ui/action-render.ts +16 -2
  54. package/src/modules/localtask/ui/contract-views.ts +9 -4
  55. package/src/modules/promptplug/plugins/goal-prompt.ts +1 -1
  56. package/src/modules/promptplug/template-store.ts +163 -58
  57. package/src/modules/setting/actions/setting-set.ts +1 -0
  58. package/src/modules/setting/service.ts +15 -1
  59. package/src/modules/templates/actions/_manifest.generated.ts +18 -18
  60. package/src/modules/templates/actions/{templates-add.ts → template-add.ts} +4 -4
  61. package/src/modules/templates/actions/{templates-default.ts → template-default.ts} +4 -4
  62. package/src/modules/templates/actions/{templates-list.ts → template-list.ts} +4 -4
  63. package/src/modules/templates/actions/{templates-remove.ts → template-remove.ts} +4 -4
  64. package/src/modules/templates/actions/{templates-reorder.ts → template-reorder.ts} +4 -4
  65. package/src/modules/templates/actions/{templates-update.ts → template-update.ts} +4 -4
  66. package/src/web/frontend/App.tsx +10 -9
  67. package/src/web/frontend/api/cli-tree.json +216 -216
  68. package/src/web/frontend/api/client.generated.ts +242 -240
  69. package/src/web/frontend/components/doc/doc-head.tsx +1 -1
  70. package/src/web/frontend/components/layout/crumbs.ts +3 -9
  71. package/src/web/frontend/components/md/{attach-area.tsx → attachments/attach-area.tsx} +5 -5
  72. package/src/web/frontend/components/md/{attach-bar.tsx → attachments/attach-bar.tsx} +1 -1
  73. package/src/web/frontend/components/md/{attach-common.ts → attachments/attach-common.ts} +1 -1
  74. package/src/web/frontend/components/md/{attach-modal.tsx → attachments/attach-modal.tsx} +4 -4
  75. package/src/web/frontend/components/md/{attach-picker.tsx → attachments/attach-picker.tsx} +4 -4
  76. package/src/web/frontend/components/md/{attachments.ts → attachments/attachments.ts} +1 -1
  77. package/src/web/frontend/components/md/{composer-launch.ts → composer/composer-launch.ts} +3 -3
  78. package/src/web/frontend/components/md/{composer-panel.tsx → composer/composer-panel.tsx} +12 -12
  79. package/src/web/frontend/components/md/{use-live-preview.ts → hooks/use-live-preview.ts} +8 -8
  80. package/src/web/frontend/components/md/{use-slash-menu.ts → hooks/use-slash-menu.ts} +4 -4
  81. package/src/web/frontend/components/md/{use-source-editor.ts → hooks/use-source-editor.ts} +7 -7
  82. package/src/web/frontend/components/md/{sel-menu.tsx → menus/sel-menu.tsx} +1 -1
  83. package/src/web/frontend/components/md/model/autolink-angle/index.ts +20 -0
  84. package/src/web/frontend/components/md/model/code/index.ts +30 -0
  85. package/src/web/frontend/components/md/model/divider/index.ts +19 -0
  86. package/src/web/frontend/components/md/model/emphasis/index.ts +21 -0
  87. package/src/web/frontend/components/md/model/escape/index.ts +35 -0
  88. package/src/web/frontend/components/md/model/footnote/index.ts +77 -0
  89. package/src/web/frontend/components/md/model/heading/index.ts +19 -0
  90. package/src/web/frontend/components/md/model/highlight/index.ts +10 -0
  91. package/src/web/frontend/components/md/model/image/index.ts +31 -0
  92. package/src/web/frontend/components/md/model/inline-scan.ts +47 -0
  93. package/src/web/frontend/components/md/model/link-ref/index.ts +41 -0
  94. package/src/web/frontend/components/md/model/list-common.ts +97 -0
  95. package/src/web/frontend/components/md/model/math/index.ts +70 -0
  96. package/src/web/frontend/components/md/model/math/latex.ts +106 -0
  97. package/src/web/frontend/components/md/model/ordered-list/index.ts +27 -0
  98. package/src/web/frontend/components/md/model/paragraph/index.ts +19 -0
  99. package/src/web/frontend/components/md/model/quote/index.ts +63 -0
  100. package/src/web/frontend/components/md/model/registry.ts +74 -0
  101. package/src/web/frontend/components/md/model/table/index.ts +100 -0
  102. package/src/web/frontend/components/md/model/types.ts +92 -0
  103. package/src/web/frontend/components/md/model/unordered-list/index.ts +37 -0
  104. package/src/web/frontend/components/md/{live-block.tsx → panes/live-block.tsx} +3 -3
  105. package/src/web/frontend/components/md/{md-panes-helpers.ts → panes/md-panes-helpers.ts} +15 -4
  106. package/src/web/frontend/components/md/{md-panes-keys.ts → panes/md-panes-keys.ts} +3 -3
  107. package/src/web/frontend/components/md/{md-panes-root.tsx → panes/md-panes-root.tsx} +2 -2
  108. package/src/web/frontend/components/md/{md-panes.tsx → panes/md-panes.tsx} +12 -12
  109. package/src/web/frontend/components/md/{ack-rail.tsx → rails/ack-rail.tsx} +2 -2
  110. package/src/web/frontend/components/md/{block-rail.tsx → rails/block-rail.tsx} +2 -2
  111. package/src/web/frontend/components/md/{doc-outline-rail.tsx → rails/doc-outline-rail.tsx} +1 -1
  112. package/src/web/frontend/components/md/{shortcut-sheet.tsx → shell/shortcut-sheet.tsx} +1 -1
  113. package/src/web/frontend/components/md/{tool-bar.tsx → shell/tool-bar.tsx} +5 -7
  114. package/src/web/frontend/components/md/standalone/task-chain-graph.tsx +194 -0
  115. package/src/web/frontend/components/md/{task-chain.tsx → standalone/task-chain.tsx} +34 -11
  116. package/src/web/frontend/components/md/{template-editor.tsx → standalone/template-editor.tsx} +2 -2
  117. package/src/web/frontend/components/repos/get-loop-members.tsx +54 -0
  118. package/src/web/frontend/components/repos/get-loop-modal.tsx +6 -4
  119. package/src/web/frontend/components/sidebar/brand-row.tsx +30 -0
  120. package/src/web/frontend/components/sidebar/drag.ts +53 -1
  121. package/src/web/frontend/components/sidebar/index.tsx +121 -62
  122. package/src/web/frontend/components/sidebar/model.ts +102 -7
  123. package/src/web/frontend/components/sidebar/ns-add-modal.tsx +81 -0
  124. package/src/web/frontend/components/sidebar/ns-dialogs.tsx +67 -0
  125. package/src/web/frontend/components/sidebar/ns-manage-modal.tsx +56 -0
  126. package/src/web/frontend/components/sidebar/ns-modal.tsx +58 -0
  127. package/src/web/frontend/components/sidebar/ns-observe-modal.tsx +36 -0
  128. package/src/web/frontend/components/sidebar/ns-picker.tsx +134 -0
  129. package/src/web/frontend/components/sidebar/ns-row.tsx +70 -0
  130. package/src/web/frontend/components/sidebar/row-menu.tsx +39 -5
  131. package/src/web/frontend/components/sidebar/search-row.tsx +37 -0
  132. package/src/web/frontend/components/sidebar/use-ns.ts +178 -0
  133. package/src/web/frontend/components/sidebar/use-sidebar-ns.ts +64 -0
  134. package/src/web/frontend/components/task-panel/task-row.tsx +26 -0
  135. package/src/web/frontend/components/tool-acts/bar.tsx +7 -7
  136. package/src/web/frontend/components/tool-acts/modules.ts +7 -4
  137. package/src/web/frontend/components/use-rail-drag.ts +1 -1
  138. package/src/web/frontend/modules/board/ack-nodes.ts +1 -1
  139. package/src/web/frontend/modules/board/ack-rail-pos.ts +1 -1
  140. package/src/web/frontend/modules/board/task-search.ts +43 -0
  141. package/src/web/frontend/modules/md/attach-mention.ts +2 -2
  142. package/src/web/frontend/modules/md/doc-store.ts +2 -2
  143. package/src/web/frontend/modules/md/md-blocks.ts +18 -1
  144. package/src/web/frontend/modules/md/md-edit-ops.ts +18 -3
  145. package/src/web/frontend/modules/md/md-render.ts +108 -179
  146. package/src/web/frontend/modules/md/styles/docs.css +89 -0
  147. package/src/web/frontend/modules/md/styles/editor.css +25 -7
  148. package/src/web/frontend/modules/md/styles/panels.css +107 -2
  149. package/src/web/frontend/page/dir/landing.tsx +35 -0
  150. package/src/web/frontend/page/dir/task-actions.ts +2 -2
  151. package/src/web/frontend/page/dir/task-chain.ts +5 -2
  152. package/src/web/frontend/page/dir/task-dock-panel.tsx +19 -28
  153. package/src/web/frontend/page/dir/task-feedback.ts +4 -4
  154. package/src/web/frontend/page/dir/task-utils.ts +19 -3
  155. package/src/web/frontend/page/dir/task.tsx +16 -13
  156. package/src/web/frontend/page/doc/doc-dock.tsx +1 -1
  157. package/src/web/frontend/page/doc/index.tsx +4 -4
  158. package/src/web/frontend/page/group/index.tsx +47 -2
  159. package/src/web/frontend/page/progress/api.ts +5 -0
  160. package/src/web/frontend/page/progress/chain-view.tsx +108 -0
  161. package/src/web/frontend/page/progress/index.tsx +210 -152
  162. package/src/web/frontend/page/repos/index.tsx +0 -11
  163. package/src/web/frontend/page/repos/repo-table.tsx +1 -20
  164. package/src/web/frontend/page/settings/api.ts +0 -4
  165. package/src/web/frontend/page/settings/index.tsx +1 -12
  166. package/src/web/frontend/page/settings/prompt-template-editor.tsx +1 -1
  167. package/src/web/frontend/page/settings/prompt-templates-section.tsx +1 -1
  168. package/src/web/frontend/page/templates/index.tsx +3 -3
  169. package/src/web/frontend/page/templates/manage.tsx +1 -1
  170. package/src/web/frontend/panels.tsx +2 -8
  171. package/src/web/frontend/prefs.ts +4 -3
  172. package/src/web/frontend/registry.ts +0 -1
  173. package/src/web/frontend/routes/index.ts +1 -2
  174. package/src/web/frontend/routes/static.ts +0 -1
  175. package/src/web/frontend/styles-v2/dag.css +17 -2
  176. package/src/web/frontend/styles-v2/dir.css +0 -36
  177. package/src/web/frontend/styles-v2/sidebar.css +92 -1
  178. package/src/web/frontend/types.ts +22 -1
  179. package/src/web/frontend/use-ns-persist.ts +63 -0
  180. package/src/web/frontend/workspace/areas.ts +1 -3
  181. package/src/web/frontend/workspace/panels.ts +1 -1
  182. package/src/web/public/assets/bar-Dy_QDX2h.js +1 -0
  183. package/src/web/public/assets/board-view-Cm8189wG.js +1 -0
  184. package/src/web/public/assets/composer-launch-B7DH53Yf.js +1 -0
  185. package/src/web/public/assets/composer-panel-CWFFEe5a.js +1 -0
  186. package/src/web/public/assets/dag-DjtLPr3j.js +1 -0
  187. package/src/web/public/assets/dir-DPboO_1M.js +3 -0
  188. package/src/web/public/assets/doc-_iteSM2X.js +6 -0
  189. package/src/web/public/assets/get-loop-modal-BW2dD9kv.js +2 -0
  190. package/src/web/public/assets/group-UEOT29Zq.js +1 -0
  191. package/src/web/public/assets/index-BpNXBbNQ.css +1 -0
  192. package/src/web/public/assets/index-BxrcTrww.js +3 -0
  193. package/src/web/public/assets/md-history-Bj790fdn.js +46 -0
  194. package/src/web/public/assets/progress-MPse2JLQ.js +3 -0
  195. package/src/web/public/assets/refs-DiIPoqnJ.js +2 -0
  196. package/src/web/public/assets/{repo-form-modal-DChK4NSX.js → repo-form-modal-CNLYR12c.js} +1 -1
  197. package/src/web/public/assets/repos-BGx-yAXd.js +12 -0
  198. package/src/web/public/assets/route-crumb-DX9C4jmQ.js +1 -0
  199. package/src/web/public/assets/settings-buy_qJGW.js +1 -0
  200. package/src/web/public/assets/task-DHlwHURz.js +13 -0
  201. package/src/web/public/assets/task-status-Cjsm0xF7.js +7 -0
  202. package/src/web/public/assets/{task-utils-cBR6Gj_c.js → task-utils-CJfMODCP.js} +1 -1
  203. package/src/web/public/assets/templates-DdMaVWok.js +10 -0
  204. package/src/web/public/assets/tool-bar-D5wLBLRl.js +28 -0
  205. package/src/web/public/assets/use-rail-drag-CNOHXWng.js +1 -0
  206. package/src/web/public/index.html +11 -13
  207. package/src/web/frontend/modules/md/progress-chain.ts +0 -34
  208. package/src/web/frontend/page/overview/api.ts +0 -29
  209. package/src/web/frontend/page/overview/index.tsx +0 -378
  210. package/src/web/frontend/page/settings/sidebar-section.tsx +0 -75
  211. package/src/web/public/assets/bar-kaVB6FAa.js +0 -1
  212. package/src/web/public/assets/board-view-Cwot54HC.js +0 -1
  213. package/src/web/public/assets/composer-launch-BMTU-BD9.js +0 -1
  214. package/src/web/public/assets/composer-panel-BF6gjNXv.js +0 -1
  215. package/src/web/public/assets/dag-BRE33yI8.js +0 -1
  216. package/src/web/public/assets/dir-B0IW4NIn.js +0 -3
  217. package/src/web/public/assets/doc-DsRb-4WT.js +0 -6
  218. package/src/web/public/assets/frontmatter-Bcseml1q.js +0 -2
  219. package/src/web/public/assets/group-CS8VP6z0.js +0 -1
  220. package/src/web/public/assets/index-BT2y9cTX.js +0 -2
  221. package/src/web/public/assets/index-DSAamoav.css +0 -1
  222. package/src/web/public/assets/md-history-CJ1N9-Jf.js +0 -39
  223. package/src/web/public/assets/md-parse-DAYCREP1.js +0 -2
  224. package/src/web/public/assets/model-TD5kGXzR.js +0 -2
  225. package/src/web/public/assets/overview-Bsq58sDd.js +0 -1
  226. package/src/web/public/assets/progress-B4DfpsyS.js +0 -3
  227. package/src/web/public/assets/refs-DIiA_49Z.js +0 -2
  228. package/src/web/public/assets/repos-PGFYkUgf.js +0 -12
  229. package/src/web/public/assets/route-crumb-SiMi2C_T.js +0 -1
  230. package/src/web/public/assets/settings-BzIllshQ.js +0 -1
  231. package/src/web/public/assets/status-tag-C9YVBvQh.js +0 -1
  232. package/src/web/public/assets/task-BL5uxmJh.js +0 -11
  233. package/src/web/public/assets/task-row-cE7qblNK.js +0 -1
  234. package/src/web/public/assets/templates-Cfn3Xmsf.js +0 -10
  235. package/src/web/public/assets/use-rail-drag-Boxl7pOG.js +0 -1
  236. package/src/web/public/assets/workspace-DojQ3RP4.js +0 -28
  237. /package/src/web/frontend/components/md/{use-block-drag.ts → hooks/use-block-drag.ts} +0 -0
  238. /package/src/web/frontend/components/md/{slash-menu.tsx → menus/slash-menu.tsx} +0 -0
  239. /package/src/web/frontend/components/md/{doc-keys.ts → panes/doc-keys.ts} +0 -0
  240. /package/src/web/frontend/components/md/{find-bar.tsx → shell/find-bar.tsx} +0 -0
  241. /package/src/web/frontend/components/md/{status-bar.tsx → shell/status-bar.tsx} +0 -0
  242. /package/src/web/public/assets/{md-history-CLIs9Dr0.css → tool-bar-CLIs9Dr0.css} +0 -0
@@ -8,7 +8,7 @@
8
8
  import { useState } from 'react';
9
9
  import type { ReactNode } from 'react';
10
10
  import { createPortal } from 'react-dom';
11
- import { MenuPortal, openMenuAt, useMenu } from '../md/tool-bar.jsx';
11
+ import { MenuPortal, openMenuAt, useMenu } from '../md/shell/tool-bar.jsx';
12
12
  import { inMoreOf, metaOf, onBarOf } from '../tool-acts/modules.js';
13
13
  import { Icon } from '../icons.jsx';
14
14
  import { useToolActsLayout } from '../tool-acts/use-layout.js';
@@ -54,8 +54,6 @@ export function crumbsOf(route: Partial<AppRoute> | null | undefined, ctx: SpecC
54
54
  return ctx.boardName ? [ctx.boardName] : ['项目组'];
55
55
  case 'repos':
56
56
  return ['仓库管理'];
57
- case 'overview':
58
- return ['全部目录总览'];
59
57
  case 'templates': {
60
58
  if (route.mode === 'new') return ['新建模板'];
61
59
  if (route.mode === 'edit') return ['编辑模板'];
@@ -113,8 +111,6 @@ export function crumbTrailOf(route: Partial<AppRoute> | null | undefined, ctx: S
113
111
  }
114
112
  case 'repos':
115
113
  return [{ label: '仓库管理', hash: '' }];
116
- case 'overview':
117
- return [{ label: '全部目录总览', hash: '' }];
118
114
  case 'templates': {
119
115
  if (route.mode === 'new') return [{ label: '任务模板', hash: '#/templates' }, { label: '新建模板', hash: '' }];
120
116
  if (route.mode === 'edit') return [{ label: '任务模板', hash: '#/templates' }, { label: '编辑模板', hash: '' }];
@@ -144,19 +140,17 @@ export function parentRouteOf(route: Partial<AppRoute> | null | undefined, _ctx?
144
140
  switch (route.view) {
145
141
  case 'dir':
146
142
  if (route.task) return `#/dir/${encodeURIComponent(route.key || '')}`;
147
- return '#/overview';
143
+ return '#/repos';
148
144
  case 'group':
149
145
  if (route.task) return `#/group/${encodeURIComponent(route.key || '')}`;
150
- return '#/overview';
151
- case 'overview':
152
- return '';
146
+ return '#/repos';
153
147
  // 文档页(#88):退回归属页(仓库 → #/repos;项目组 → #/group/<id>)
154
148
  case 'doc':
155
149
  if (route.repoKey) return '#/repos';
156
150
  if (route.boardKey) return `#/group/${encodeURIComponent(route.boardKey)}`;
157
151
  return '#/repos';
158
152
  default:
159
- return '#/overview';
153
+ return '#/repos';
160
154
  }
161
155
  }
162
156
 
@@ -8,10 +8,10 @@
8
8
  // 移除时二选一:只解除关联 / 连资源与字节一起删。
9
9
  import { useCallback, useEffect, useImperativeHandle, useMemo, useState } from 'react';
10
10
  import type { ComponentType, DragEvent, ReactNode, Ref } from 'react';
11
- import { Modal, useDialog } from '../popup/index.jsx';
12
- import { useToast } from '../toast/index.jsx';
13
- import { api } from '../../api/client.js';
14
- import { uploadOne, droppedFiles } from '../attach/upload.js';
11
+ import { Modal, useDialog } from '../../popup/index.jsx';
12
+ import { useToast } from '../../toast/index.jsx';
13
+ import { api } from '../../../api/client.js';
14
+ import { uploadOne, droppedFiles } from '../../attach/upload.js';
15
15
  import AttachModal from './attach-modal.jsx';
16
16
  import {
17
17
  AREA_LABEL,
@@ -20,7 +20,7 @@ import {
20
20
  endpointOf,
21
21
  normAttachment,
22
22
  } from './attach-common.js';
23
- import { renderMarkdownHtml } from '../../modules/md/md-render.js';
23
+ import { renderMarkdownHtml } from '../../../modules/md/md-render.js';
24
24
  import type {
25
25
  AttachAllow,
26
26
  AttachHostKind,
@@ -1,4 +1,4 @@
1
- import { Icon } from '../icons.jsx';
1
+ import { Icon } from '../../icons.jsx';
2
2
  import type { Attachment } from './attach-common.js';
3
3
 
4
4
  /** 附件列表(添加入口在工具区,此处只展示/移除) */
@@ -2,7 +2,7 @@
2
2
  //
3
3
  // 前端**不拼正文**:所有写入都走 `localtask attach` / `docs attach` 的
4
4
  // `--no-embed` 路径(attachments + task_attach/ref_attach),正文由编辑器自己管。
5
- import { api } from '../../api/client.js';
5
+ import { api } from '../../../api/client.js';
6
6
 
7
7
  /** 附件分区:正文内嵌(role=inline)/ 附件区(role=attach|doc)。 */
8
8
  export type AttachAreaKind = 'area' | 'inline';
@@ -9,10 +9,10 @@
9
9
  // 前端不拼正文(关系表是附件清单的权威)。
10
10
  import { useEffect, useMemo, useRef, useState } from 'react';
11
11
  import type { ClipboardEvent, ComponentType, ReactNode } from 'react';
12
- import { Modal } from '../popup/index.jsx';
13
- import { api } from '../../api/client.js';
14
- import { clipboardFiles, droppedFiles, readableName, uploadOne } from '../attach/upload.js';
15
- import StatusTag from '../status-tag/index.jsx';
12
+ import { Modal } from '../../popup/index.jsx';
13
+ import { api } from '../../../api/client.js';
14
+ import { clipboardFiles, droppedFiles, readableName, uploadOne } from '../../attach/upload.js';
15
+ import StatusTag from '../../status-tag/index.jsx';
16
16
  import {
17
17
  attachBodyOf,
18
18
  badgeOf,
@@ -22,11 +22,11 @@ import type {
22
22
  DocOption,
23
23
  TaskOption,
24
24
  } from './attach-common.js';
25
- import { caretLineCol } from '../../modules/md/md-edit-ops.js';
26
- import { embedForAttachment } from '../../modules/md/attach-mention.js';
25
+ import { caretLineCol } from '../../../modules/md/md-edit-ops.js';
26
+ import { embedForAttachment } from '../../../modules/md/attach-mention.js';
27
27
  import AttachModal from './attach-modal.jsx';
28
- import { useApp } from '../../app-context.jsx';
29
- import { openBesideMain } from '../../workspace.js';
28
+ import { useApp } from '../../../app-context.jsx';
29
+ import { openBesideMain } from '../../../workspace.js';
30
30
 
31
31
  /** 附件清单的取数描述(可带 allow/taskOptions 供「添加附件」弹窗用)。 */
32
32
  export interface AttachHost extends AttachHostRef {
@@ -7,7 +7,7 @@
7
7
  // 任务走(CLI / 其他机器认语法,本机仓按 id 给文件)。
8
8
  // 本机仓不可达(serve 没起来——面板本身也起不来)时退回 localStorage 老路:
9
9
  // 功能不中断,代价是这类附件只活在当前浏览器(界面会照常显示)。
10
- import { uploadMany } from '../attach/upload.js';
10
+ import { uploadMany } from '../../attach/upload.js';
11
11
  import type { Attachment } from './attach-common.js';
12
12
 
13
13
  const ATT_KEY = 'nx-kv-md-attachments-v1';
@@ -8,10 +8,10 @@
8
8
  // 但那套逻辑带着会话状态(doc / topic / taskRow / 草稿判定),搬不动,也不该
9
9
  // 复制一份——于是用**模块级登记表**:启动时登记 token → 回调,面板按 token
10
10
  // 取回;面板提交或关闭后销号(否则登记表随开关面板无限增长)。
11
- import { openPanel, currentMainPanel } from '../../workspace.js';
11
+ import { openPanel, currentMainPanel } from '../../../workspace.js';
12
12
  import type { Model } from 'flexlayout-react';
13
- import type { PanelSpec } from '../../types.js';
14
- import type { Attachment } from './attach-common.js';
13
+ import type { PanelSpec } from '../../../types.js';
14
+ import type { Attachment } from '../attachments/attach-common.js';
15
15
 
16
16
  /** 原文定位(点引用区在右侧并排打开原文时用)。 */
17
17
  export interface ComposerSrc {
@@ -7,20 +7,20 @@
7
7
  // 提交逻辑在任务页那边(带会话状态),这里按 token 取回回调——见 composer-launch.js。
8
8
  import { useEffect, useRef, useState } from 'react';
9
9
  import type { MouseEvent as ReactMouseEvent } from 'react';
10
- import { MdPanes } from './md-panes.jsx';
11
- import AttachBar from './attach-bar.jsx';
12
- import { Icon } from '../icons.jsx';
13
- import { filesToAttachments } from './attachments.js';
14
- import { insertAttachmentSnippet } from '../../modules/md/md-parse.js';
10
+ import { MdPanes } from '../panes/md-panes.jsx';
11
+ import AttachBar from '../attachments/attach-bar.jsx';
12
+ import { Icon } from '../../icons.jsx';
13
+ import { filesToAttachments } from '../attachments/attachments.js';
14
+ import { insertAttachmentSnippet } from '../../../modules/md/md-parse.js';
15
15
  import { composerOf, restoreComposerSource } from './composer-launch.js';
16
16
  import type { ComposerSrc } from './composer-launch.js';
17
- import { pushHistory, undoHistory, redoHistory, clearHistory } from '../../modules/md/md-history.js';
18
- import { useApp } from '../../app-context.jsx';
19
- import { useToast } from '../toast/index.jsx';
20
- import { openBesideMain } from '../../workspace.js';
21
- import type { Attachment } from './attach-common.js';
22
- import type { EditorApi } from './md-panes-helpers.js';
23
- import '../../modules/md/style.css';
17
+ import { pushHistory, undoHistory, redoHistory, clearHistory } from '../../../modules/md/md-history.js';
18
+ import { useApp } from '../../../app-context.jsx';
19
+ import { useToast } from '../../toast/index.jsx';
20
+ import { openBesideMain } from '../../../workspace.js';
21
+ import type { Attachment } from '../attachments/attach-common.js';
22
+ import type { EditorApi } from '../panes/md-panes-helpers.js';
23
+ import '../../../modules/md/style.css';
24
24
 
25
25
  // 底部附件 dock(#155):与任务页 mdw-dock 同一套视觉;高度/开关单独存
26
26
  // (nxkv.cmpDock*,不与任务页的 nxkv.taskDock* 串台)。
@@ -3,15 +3,15 @@
3
3
  // 与 JSX 装配。返回值即组件所需的全部上下文。
4
4
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
5
5
  import type { RefObject } from 'react';
6
- import { useAttachPicker } from './attach-picker.jsx';
7
- import type { AttachHost } from './attach-picker.jsx';
8
- import { atTriggerAt, padEmbed } from '../../modules/md/attach-mention.js';
9
- import { diffIndex, moveBlockInList, reindexAfterMove, runFormat, turnBlock } from '../../modules/md/md-edit-ops.js';
10
- import { joinMdBlocks, normalizeBlockText } from '../../modules/md/md-parse.js';
11
- import { bodyBlocksOnly, useDropFiles } from './md-panes-helpers.js';
12
- import type { EditOpResult, EditorApi, FileDropCtx, PendingSel } from './md-panes-helpers.js';
6
+ import { useAttachPicker } from '../attachments/attach-picker.jsx';
7
+ import type { AttachHost } from '../attachments/attach-picker.jsx';
8
+ import { atTriggerAt, padEmbed } from '../../../modules/md/attach-mention.js';
9
+ import { diffIndex, moveBlockInList, reindexAfterMove, runFormat, turnBlock } from '../../../modules/md/md-edit-ops.js';
10
+ import { joinMdBlocks, normalizeBlockText } from '../../../modules/md/md-parse.js';
11
+ import { bodyBlocksOnly, useDropFiles } from '../panes/md-panes-helpers.js';
12
+ import type { EditOpResult, EditorApi, FileDropCtx, PendingSel } from '../panes/md-panes-helpers.js';
13
13
  import { useSlashMenu } from './use-slash-menu.js';
14
- import type { Attachment } from './attach-common.js';
14
+ import type { Attachment } from '../attachments/attach-common.js';
15
15
 
16
16
  /** 查找命中:块序号 + 块内起始偏移。 */
17
17
  export interface LiveMatch {
@@ -3,10 +3,10 @@
3
3
  // (预览按块矩形、源码按行列推算行高)、onApply 把选中的命令结果写回
4
4
  // (预览走块级 applyBlockOp,源码走全文 applyOp)。
5
5
  import { useEffect, useRef, useState } from 'react';
6
- import { applySlashCommand, filterSlashCmds, slashQueryAt } from '../../modules/md/md-edit-ops.js';
7
- import { handleSlashKey, slashActiveIndex } from './slash-menu.jsx';
8
- import type { SlashItem, SlashState } from './slash-menu.jsx';
9
- import type { EditOpResult } from './md-panes-helpers.js';
6
+ import { applySlashCommand, filterSlashCmds, slashQueryAt } from '../../../modules/md/md-edit-ops.js';
7
+ import { handleSlashKey, slashActiveIndex } from '../menus/slash-menu.jsx';
8
+ import type { SlashItem, SlashState } from '../menus/slash-menu.jsx';
9
+ import type { EditOpResult } from '../panes/md-panes-helpers.js';
10
10
 
11
11
  /** 调用方注入的三个差异点(见文件头注释)。 */
12
12
  export interface UseSlashMenuArgs {
@@ -21,14 +21,14 @@ import {
21
21
  scrollTextareaToIndex,
22
22
  slashQueryAt,
23
23
  turnLine,
24
- } from '../../modules/md/md-edit-ops.js';
25
- import { FMT_KEYS, useDropFiles } from './md-panes-helpers.js';
26
- import type { DropRootProps, EditOpResult, EditorApi, FileDropCtx } from './md-panes-helpers.js';
27
- import { handleSlashKey } from './slash-menu.jsx';
28
- import type { SlashMenuProps } from './slash-menu.jsx';
24
+ } from '../../../modules/md/md-edit-ops.js';
25
+ import { FMT_KEYS, useDropFiles } from '../panes/md-panes-helpers.js';
26
+ import type { DropRootProps, EditOpResult, EditorApi, FileDropCtx } from '../panes/md-panes-helpers.js';
27
+ import { handleSlashKey } from '../menus/slash-menu.jsx';
28
+ import type { SlashMenuProps } from '../menus/slash-menu.jsx';
29
29
  import { useSlashMenu } from './use-slash-menu.js';
30
- import type { EditorFindBarProps } from './find-bar.jsx';
31
- import type { StatusBarProps } from './status-bar.jsx';
30
+ import type { EditorFindBarProps } from '../shell/find-bar.jsx';
31
+ import type { StatusBarProps } from '../shell/status-bar.jsx';
32
32
 
33
33
  export interface UseSourceEditorArgs {
34
34
  body: string;
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * #104:原先这里还带一套「撰写中」形态(浮层里直接展开一个 textarea 写评论
5
5
  * 或反馈)——用户口径是「评论和反馈不该是输入框弹窗,要新开一个 md 编辑
6
- * 页面」,所以撰写态整体移走(见 components/md/composer-panel.jsx)。这里只
6
+ * 页面」,所以撰写态整体移走(见 components/md/composer/composer-panel.jsx)。这里只
7
7
  * 留**动作条**:格式按钮 / 复制 / 评论(点评论 → 打开那块 md 编辑面板)。
8
8
  */
9
9
 
@@ -0,0 +1,20 @@
1
+ // 尖括号自动链接:`<https://example.com>` / `<mailto:a@b.c>` → 可点链接。
2
+ //
3
+ // 走**转义之后**的阶段:`<` 此刻已是 `&lt;`,正好用实体作锚点匹配,不会与真正的
4
+ // HTML 标签混淆(正文里的 `<div>` 也被转义成字面量,不会变成标签)。
5
+ //
6
+ // 裸 URL(不带尖括号)由编排层的 autolinkHtml 兜底;两者互不重叠:本规则只吃
7
+ // 成对尖括号包起来的那一种(CommonMark 里这种写法用于「URL 紧贴标点」的场景)。
8
+ import type { InlineRule } from '../types.js';
9
+ import { mapOutsideTags } from '../inline-scan.js';
10
+
11
+ const ANGLE_RE = /&lt;((?:https?:\/\/|mailto:)[^\s]+?)&gt;/g;
12
+
13
+ export const angleAutolinkInlineRule: InlineRule = (html: string): string =>
14
+ mapOutsideTags(html, (text) =>
15
+ text.replace(
16
+ ANGLE_RE,
17
+ (_m, href: string) =>
18
+ `<a class="md-link" href="${href}" target="_blank" rel="noopener noreferrer" title="${href}">${href}</a>`,
19
+ ),
20
+ );
@@ -0,0 +1,30 @@
1
+ // 代码块语法:fenced ``` 包起来的整块原样输出(不跑行内渲染)。
2
+ //
3
+ // 代码里的 `[[示例]]`、`**x**`、`$x$` 都不该变成链接/粗体/公式——整段由本规则
4
+ // 独占,块内文本只做 HTML 转义。未闭合时按到文末处理(与原实现一致)。
5
+ //
6
+ // 语言标记(```js)不再被丢弃:写进 `data-lang`,样式层按需显示角标。不做语法
7
+ // 高亮(那要引入整棵 grammar,与本仓库零依赖的取向冲突)。
8
+ import type { BlockMatch, BlockRule } from '../types.js';
9
+
10
+ export const codeBlockSyntax: BlockRule = {
11
+ id: 'code-fence',
12
+ priority: 10,
13
+ match(lines, i, ctx): BlockMatch | null {
14
+ const fence = lines[i] ?? '';
15
+ if (!fence.startsWith('```')) return null;
16
+ const lang = fence.slice(3).trim().split(/\s+/)[0] ?? '';
17
+ let j = i + 1;
18
+ let body = '';
19
+ while (j < lines.length && !(lines[j] ?? '').startsWith('```')) {
20
+ body += `${ctx.esc(lines[j] ?? '')}\n`;
21
+ j += 1;
22
+ }
23
+ const closed = j < lines.length;
24
+ const attr = lang ? ` data-lang="${ctx.esc(lang)}"` : '';
25
+ return {
26
+ html: `<pre class="mdw-code"${attr}><code>${body}</code></pre>`,
27
+ next: closed ? j + 1 : j,
28
+ };
29
+ },
30
+ };
@@ -0,0 +1,19 @@
1
+ // 分隔线语法:独占一行的 3 个以上 `-` / `*` / `_`(可夹空格)→ `<hr>`。
2
+ //
3
+ // 不匹配 `- ` 列表(需要三个以上且整行只有分隔符)。frontmatter 在渲染前已被
4
+ // stripFrontmatter 剥掉,正文里的 `---` 一律按 thematic break 处理。
5
+ import type { BlockMatch, BlockRule } from '../types.js';
6
+
7
+ export const dividerSyntax: BlockRule = {
8
+ id: 'divider',
9
+ // 必须**先于无序列表**(45):`* * *` / `- - -` 同时符合「列表项」的形状,
10
+ // 整行只有分隔符时以分隔线为准(CommonMark 的 thematic break 优先)。
11
+ priority: 44,
12
+ match(lines, i): BlockMatch | null {
13
+ const t = (lines[i] ?? '').trim();
14
+ if (!/^(?:-[ \t]*){3,}$/.test(t) && !/^(?:\*[ \t]*){3,}$/.test(t) && !/^(?:_[ \t]*){3,}$/.test(t)) {
15
+ return null;
16
+ }
17
+ return { html: '<hr class="md-divider">', next: i + 1 };
18
+ },
19
+ };
@@ -0,0 +1,21 @@
1
+ // 强调语法:斜体 `*x*` / 删除线 `~~x~~`(粗体 `**x**` 仍在渲染器主链,避免重复)。
2
+ //
3
+ // 行内规则,输入是**已转义**的 HTML 串。两个顺序要点:
4
+ // 1. 必须先吃掉 `**bold**` 再处理单 `*` 斜体,否则斜体会把粗体的星号拆散——
5
+ // 所以本规则只在渲染器已经替换完 `**`(变成 <b>)之后套用;斜体正则用
6
+ // `(^|[^*])` 排除双星。
7
+ // 2. 必须跳过 `<code>` / `<a>` 内部的文本(mapOutsideTags):代码里写
8
+ // `a*b*c` 或 `~~x~~` 应当原样显示,那不是在标记强调。
9
+ //
10
+ // 刻意**不认** `_x_` 下划线斜体:中文技术文档里 snake_case 标识符(`file_name`、
11
+ // `user_id`)极常见,按 CommonMark 的 intraword 规则放过它反而漏判更多,收益不抵
12
+ // 误伤风险。要斜体请用 `*x*`。
13
+ import type { InlineRule } from '../types.js';
14
+ import { mapOutsideTags } from '../inline-scan.js';
15
+
16
+ export const emphasisInlineRule: InlineRule = (html: string): string =>
17
+ mapOutsideTags(html, (text) =>
18
+ text
19
+ .replace(/~~([^~]+)~~/g, '<del>$1</del>')
20
+ .replace(/(^|[^*])\*([^*\n]+)\*(?!\*)/g, '$1<em>$2</em>'),
21
+ );
@@ -0,0 +1,35 @@
1
+ // 转义语法:反斜杠让紧跟的标点按字面显示(`\*` → `*`,不开启强调)。
2
+ //
3
+ // 必须在 **HTML 转义之前**动手:等到 `*` 被强调规则吃掉就晚了。做法是把
4
+ // `\X` 换成私有区占位符(`\uE000 <hex> \uE001`),整条渲染流水线都看不见那个
5
+ // 字符,最后一步再由 `restoreEscapes` 换回**转义后的字面字符**。
6
+ //
7
+ // 为什么占位符里存**十六进制**而不是字符本身:占位符要穿过行内规则(强调 / 高亮 /
8
+ // 公式),若里面直接放着 `*`,强调规则照样会把两个占位符之间的内容当斜体
9
+ // (实测:`\*不是斜体\*` 会渲染成 `<em>`)。存成 `2a` 之后,串里没有任何 markdown
10
+ // 标记字符,规则自然无从匹配。
11
+ //
12
+ // 为什么不用 `&#42;` 这类实体:`esc()` 会把 `&` 转成 `&amp;`,实体反而被打散。
13
+ // 占位符是唯一能安全穿过「转义 → 标签生成 → 行内规则」的载体。
14
+ //
15
+ // 代码片段内部的 `\` 是内容(`` `\*` `` 就该显示 `\*`),所以替换要跳过 code span。
16
+ import type { InlinePreRule } from '../types.js';
17
+ import { mapOutsideCodeSpans } from '../inline-scan.js';
18
+
19
+ const PH_OPEN = '\uE000';
20
+ const PH_CLOSE = '\uE001';
21
+
22
+ export const escapePreRule: InlinePreRule = (text: string): string =>
23
+ mapOutsideCodeSpans(text, (chunk) =>
24
+ chunk.replace(/\\([\\`*_{}[\]()#+\-.!|~=^$<>])/g, (_m, ch: string) => {
25
+ const hex = ch.charCodeAt(0).toString(16).padStart(2, '0');
26
+ return `${PH_OPEN}${hex}${PH_CLOSE}`;
27
+ }),
28
+ );
29
+
30
+ /** 占位符还原:把 `\uE0002a\uE001` 换回经 HTML 转义的字面字符。 */
31
+ export function restoreEscapes(html: string, esc: (value: unknown) => string): string {
32
+ return html.replace(/\uE000([0-9a-f]{2})\uE001/g, (_m, hex: string) =>
33
+ esc(String.fromCharCode(parseInt(hex, 16))),
34
+ );
35
+ }
@@ -0,0 +1,77 @@
1
+ // 脚注语法:正文 `[^note]` + 定义行 `[^note]: 说明` → 上标引用 + 文末脚注列表。
2
+ //
3
+ // 这是本仓库第一个**文档级**语法(DocRule):定义行不能就地渲染,必须先全文扫一遍
4
+ // 把它们抽走登记,引用点才能查到编号与正文。三个阶段:
5
+ // 1. collect —— 抽走定义行(含缩进续行),登记 label → 正文行
6
+ // 2. preRule —— 把 `[^label]` 换成占位符(转义前,避免被 `[..]` 链接正则误吃)
7
+ // 3. restore —— 占位符换成 `<sup>` 并在文末追加 `<ol class="md-fn-list">`
8
+ //
9
+ // 为什么不复用「定义顺序 = 引用顺序」:占位符只带编号,编号按**定义顺序**给。
10
+ // 正常文档里两者一致;不一致时编号会跳跃,但换来无状态、渲染幂等(同一份正文
11
+ // 无论渲染几次结果都相同,不会因为调用顺序变编号)。
12
+ import type { DocCtx, DocRule, InlineEnv, InlinePreRule } from '../types.js';
13
+
14
+ const REF_OPEN = '\uE004';
15
+ const REF_CLOSE = '\uE005';
16
+
17
+ const DEF_RE = /^\[\^([^\]\s]+)\]:[ \t]*(.*)$/;
18
+
19
+ /** 定义行起始 + 其后缩进续行(≥2 空格)合成一条脚注。 */
20
+ export const footnoteDocRule: DocRule = {
21
+ id: 'footnote-def',
22
+ collect(lines: string[], ctx: DocCtx): string[] {
23
+ const out: string[] = [];
24
+ for (let i = 0; i < lines.length; i++) {
25
+ const line = lines[i] ?? '';
26
+ const m = DEF_RE.exec(line);
27
+ if (!m) {
28
+ out.push(line);
29
+ continue;
30
+ }
31
+ const body: string[] = [m[2] ?? ''];
32
+ let j = i + 1;
33
+ while (j < lines.length) {
34
+ const next = lines[j] ?? '';
35
+ if (!/^[ \t]{2,}\S/.test(next)) break;
36
+ body.push(next.trim());
37
+ j += 1;
38
+ }
39
+ ctx.footnotes.set(String(m[1] ?? ''), body);
40
+ i = j - 1;
41
+ }
42
+ return out;
43
+ },
44
+ };
45
+
46
+ /** `[^label]` → 占位符(只带编号;未定义的 label 原样留着,当普通文字)。 */
47
+ export const footnotePreRule: InlinePreRule = (text: string, env: InlineEnv): string => {
48
+ if (!env.footnotes.size) return text;
49
+ const labels = Array.from(env.footnotes.keys());
50
+ return text.replace(/\[\^([^\]\s]+)\]/g, (m, label: string) => {
51
+ const idx = labels.indexOf(label);
52
+ if (idx < 0) return m;
53
+ return `${REF_OPEN}${idx + 1}${REF_CLOSE}`;
54
+ });
55
+ };
56
+
57
+ /** 占位符 → 上标引用,并在文末追加脚注列表(无脚注时原样返回)。 */
58
+ export function restoreFootnotes(
59
+ html: string,
60
+ ctx: DocCtx,
61
+ inline: (text: string) => string,
62
+ ): string {
63
+ if (!ctx.footnotes.size) return html;
64
+ const body = html.replace(
65
+ /\uE004(\d+)\uE005/g,
66
+ (_m, n: string) =>
67
+ `<sup class="md-fn-ref"><a href="#md-fn-${n}" id="md-fnref-${n}">${n}</a></sup>`,
68
+ );
69
+ const items = Array.from(ctx.footnotes.values())
70
+ .map((lines, k) => {
71
+ const n = String(k + 1);
72
+ const text = lines.map((l) => inline(l)).join('<br>');
73
+ return `<li id="md-fn-${n}">${text}<a class="md-fn-back" href="#md-fnref-${n}" aria-label="返回正文">↩</a></li>`;
74
+ })
75
+ .join('');
76
+ return `${body}<ol class="md-fn-list">${items}</ol>`;
77
+ }
@@ -0,0 +1,19 @@
1
+ // 标题语法:`#` … `######` 行 → h1–h6(带滚动目录用的锚点 id)。
2
+ //
3
+ // 渲染支持全部 6 级(CommonMark);右侧滚动目录仍只抽 1–3 级(extractMdHeadings),
4
+ // 更深的层级在长文里会淹没导航,那是**目录**的取舍,不该限制渲染能力。
5
+ import type { BlockMatch, BlockRule } from '../types.js';
6
+
7
+ export const headingSyntax: BlockRule = {
8
+ id: 'heading',
9
+ priority: 30,
10
+ match(lines, i, ctx): BlockMatch | null {
11
+ const line = lines[i] ?? '';
12
+ const m = /^(#{1,6})\s+(.*)$/.exec(line);
13
+ if (!m) return null;
14
+ const level = (m[1] ?? '#').length;
15
+ const text = m[2] ?? '';
16
+ const id = ctx.headingId(text.trim(), ctx.usedIds);
17
+ return { html: `<h${level} id="${ctx.esc(id)}">${ctx.inline(text)}</h${level}>`, next: i + 1 };
18
+ },
19
+ };
@@ -0,0 +1,10 @@
1
+ // 高亮语法:`==重点==` → `<mark>`(Obsidian 口径,非 CommonMark 标准但文档写作常用)。
2
+ //
3
+ // 跑在「代码/链接已就位」的 HTML 上,必须跳过受保护标签内部:`<code>==x==</code>`
4
+ // 里的等号是代码内容。`==` 在 LaTeX 公式里也可能出现,公式标签由数学规则自己
5
+ // 把控顺序(公式先于本规则生成标签,标签内部受保护)。
6
+ import type { InlineRule } from '../types.js';
7
+ import { mapOutsideTags } from '../inline-scan.js';
8
+
9
+ export const highlightInlineRule: InlineRule = (html: string): string =>
10
+ mapOutsideTags(html, (text) => text.replace(/==([^=\n]+)==/g, '<mark>$1</mark>'));
@@ -0,0 +1,31 @@
1
+ // 整行图片语法:`![说明](目标)` 独占一行 → 段落包裹的图片。
2
+ //
3
+ // 目标命中 fileId(图床附件)→ 走面板内容端点直出;否则按附件清单的 name→url
4
+ // 映射兜底(v1 老数据);都不命中 → 降级成行内代码,原样可见。
5
+ import type { BlockMatch, BlockRule } from '../types.js';
6
+ import { looksLikeFileId } from '../../../../../../shared/attach.js';
7
+
8
+ const IMG_RE = /^!\[([^\]]*)\]\(([^)]+)\)\s*$/;
9
+
10
+ export const imageSyntax: BlockRule = {
11
+ id: 'image',
12
+ priority: 18,
13
+ match(lines, i, ctx): BlockMatch | null {
14
+ const m = IMG_RE.exec(lines[i] ?? '');
15
+ if (!m) return null;
16
+ const alt = m[1] ?? '';
17
+ const target = (m[2] ?? '').trim();
18
+ if (looksLikeFileId(target)) {
19
+ return {
20
+ html: `<p><img class="md-att-img" src="/api/file/content/${target}" alt="${ctx.esc(alt)}"></p>`,
21
+ next: i + 1,
22
+ };
23
+ }
24
+ const raw = ctx.imgMap[m[2] ?? ''] || m[2] || '';
25
+ const safe = /^(data:|blob:|https?:|#)/.test(raw) ? raw : '';
26
+ const html = safe
27
+ ? `<p><img src="${safe}" alt="${ctx.esc(alt)}"></p>`
28
+ : `<p><code>![${ctx.esc(alt)}](${ctx.esc(m[2] ?? '')})</code></p>`;
29
+ return { html, next: i + 1 };
30
+ },
31
+ };
@@ -0,0 +1,47 @@
1
+ // 行内扫描工具:只对**文本节点**套用替换,跳过已生成的受保护标签内部。
2
+ //
3
+ // 为什么需要:行内规则跑在「代码 / 链接已就位」的 HTML 上(见 md-render 的 inline
4
+ // 主链)。若不加区分地对整串做正则,`<code>a*b*c</code>` 会被斜体规则改成
5
+ // `<code>a<em>b</em>c</code>`——代码里的星号本该原样显示。同理 `<a>` 的锚文本与
6
+ // `<mark>` 内部不该被二次套用。
7
+ //
8
+ // 按标签切分而不是用「负向断言」:HTML 是嵌套的,正则断言管不住深度,切分 + 计数
9
+ // 才能正确覆盖 `<code><b>x</b></code>` 这种嵌套。
10
+
11
+ /** 内部文本不再套用行内规则的标签(内容属于别的语法所有)。 */
12
+ const PROTECTED = new Set(['code', 'pre', 'a', 'mark']);
13
+
14
+ /**
15
+ * 对 HTML 串的文本节点套用 `fn`,受保护标签内部的文本原样保留。
16
+ *
17
+ * 标签本身不参与匹配(只作为边界),因此不会破坏既有标签结构。
18
+ */
19
+ export function mapOutsideTags(html: string, fn: (text: string) => string): string {
20
+ const parts = html.split(/(<[^>]*>)/);
21
+ const out: string[] = [];
22
+ let depth = 0; // >0 = 处在受保护标签内部
23
+ for (const p of parts) {
24
+ if (p.startsWith('<')) {
25
+ const m = /^<(\/?)\s*([a-zA-Z][\w-]*)/.exec(p);
26
+ const name = (m && m[2] ? m[2] : '').toLowerCase();
27
+ if (PROTECTED.has(name)) {
28
+ if (m && m[1] === '/') depth = Math.max(0, depth - 1);
29
+ else if (!p.endsWith('/>')) depth += 1;
30
+ }
31
+ out.push(p);
32
+ continue;
33
+ }
34
+ out.push(depth > 0 ? p : fn(p));
35
+ }
36
+ return out.join('');
37
+ }
38
+
39
+ /**
40
+ * 对**原始 markdown 文本**里代码片段(`` `…` ``)之外的片段套用 `fn`。
41
+ *
42
+ * 用于转义预处理:`` `\*` `` 里的反斜杠是代码内容,不该被当成转义符吃掉。
43
+ */
44
+ export function mapOutsideCodeSpans(text: string, fn: (chunk: string) => string): string {
45
+ const parts = text.split(/(`[^`]*`)/);
46
+ return parts.map((p) => (p.startsWith('`') && p.endsWith('`') && p.length >= 2 ? p : fn(p))).join('');
47
+ }
@@ -0,0 +1,41 @@
1
+ // 引用式链接:`[文字][标签]` 引用 `[标签]: https://…` 定义(CommonMark reference link)。
2
+ //
3
+ // 与脚注同属**文档级**语法:定义行被抽走登记,引用点在转义前改写成内联形态
4
+ // `[文字](url)`,随后交给既有的链接渲染链处理——这样外链 / 附件 / 内部资源三类
5
+ // 目标不用各写一遍解析,引用式链接自动继承它们的全部行为。
6
+ //
7
+ // 只支持 `[文字][标签]` 与 `[文字][]` 两种形态;**不做** shortcut `[标签]`:它和
8
+ // 普通方括号、双链 `[[x]]` 的边界太容易互相误吃,收益不抵风险。
9
+ import type { DocCtx, DocRule, InlineEnv, InlinePreRule } from '../types.js';
10
+
11
+ /** `[标签]: url` 或 `[标签]: url "标题"`(标题部分丢弃,仅用于识别整行)。 */
12
+ const DEF_RE = /^\[([^\[\]]+)\]:[ \t]*(\S+)(?:[ \t]+(?:"[^"]*"|'[^']*'|\([^)]*\)))?[ \t]*$/;
13
+
14
+ export const linkRefDocRule: DocRule = {
15
+ id: 'link-ref-def',
16
+ collect(lines: string[], ctx: DocCtx): string[] {
17
+ const out: string[] = [];
18
+ for (const line of lines) {
19
+ const m = DEF_RE.exec(line);
20
+ // 脚注定义 `[^x]: …` 也会被上面的正则命中(标签以 ^ 开头),跳过交给脚注规则
21
+ if (!m || String(m[1] ?? '').startsWith('^')) {
22
+ out.push(line);
23
+ continue;
24
+ }
25
+ const label = String(m[1] ?? '').trim().toLowerCase();
26
+ const url = String(m[2] ?? '').trim();
27
+ if (label && url) ctx.refLinks.set(label, url);
28
+ }
29
+ return out;
30
+ },
31
+ };
32
+
33
+ /** `[文字][标签]` / `[文字][]` → `[文字](url)`;标签未定义时原样保留。 */
34
+ export const linkRefPreRule: InlinePreRule = (text: string, env: InlineEnv): string => {
35
+ if (!env.refLinks.size) return text;
36
+ return text.replace(/\[([^\[\]]+)\]\[([^\[\]]*)\]/g, (m, label: string, key: string) => {
37
+ const k = String(key || label).trim().toLowerCase();
38
+ const url = env.refLinks.get(k);
39
+ return url ? `[${label}](${url})` : m;
40
+ });
41
+ };