@tnotesjs/core 0.0.6 → 0.0.8
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/README.md +87 -84
- package/dist/{chunk-JDVN2QYW.js → chunk-JUMVJKWV.js} +615 -614
- package/dist/cli/index.js +125 -125
- package/dist/vitepress/config/index.js +184 -210
- package/package.json +15 -3
- package/types/config.ts +61 -61
- package/types/index.ts +11 -11
- package/types/note.ts +33 -33
- package/types/shims.d.ts +3 -4
- package/vitepress/assets/icons/icon__check.svg +3 -3
- package/vitepress/assets/icons/icon__clipboard.svg +7 -7
- package/vitepress/assets/icons/icon__close.svg +1 -1
- package/vitepress/assets/icons/icon__collapse.svg +1 -1
- package/vitepress/assets/icons/icon__confirm.svg +1 -1
- package/vitepress/assets/icons/icon__copy.svg +4 -4
- package/vitepress/assets/icons/icon__focus.svg +1 -1
- package/vitepress/assets/icons/icon__fold.svg +3 -3
- package/vitepress/assets/icons/icon__folder.svg +1 -1
- package/vitepress/assets/icons/icon__fullscreen.svg +1 -1
- package/vitepress/assets/icons/icon__fullscreen_exit.svg +1 -1
- package/vitepress/assets/icons/icon__github.svg +3 -3
- package/vitepress/assets/icons/icon__mindmap.svg +1 -1
- package/vitepress/assets/icons/icon__next.svg +1 -1
- package/vitepress/assets/icons/icon__number_gray.svg +1 -1
- package/vitepress/assets/icons/icon__number_purple.svg +1 -1
- package/vitepress/assets/icons/icon__prev.svg +1 -1
- package/vitepress/assets/icons/icon__restore.svg +1 -1
- package/vitepress/assets/icons/icon__rotate.svg +4 -4
- package/vitepress/assets/icons/icon__search.svg +1 -1
- package/vitepress/assets/icons/icon__sidebar_collapsed.svg +1 -1
- package/vitepress/assets/icons/icon__sidebar_opened.svg +1 -1
- package/vitepress/assets/icons/icon__totop.svg +5 -5
- package/vitepress/assets/icons/icon__vscode.svg +5 -5
- package/vitepress/assets/icons/icon__zoom_fit.svg +1 -1
- package/vitepress/assets/icons/icon__zoom_in.svg +1 -1
- package/vitepress/assets/icons/icon__zoom_out.svg +1 -1
- package/vitepress/assets/icons/icon__zoom_reset.svg +1 -1
- package/vitepress/assets/icons/index.ts +38 -38
- package/vitepress/components/BilibiliOutsidePlayer/BilibiliOutsidePlayer.vue +20 -20
- package/vitepress/components/CodeBlockFullscreen/CodeBlockFullscreen.vue +373 -372
- package/vitepress/components/CodeBlockFullscreen/index.ts +115 -114
- package/vitepress/components/CodeBlockFullscreen/styles.css +64 -64
- package/vitepress/components/Discussions/Discussions.module.scss +32 -32
- package/vitepress/components/Discussions/Discussions.vue +211 -210
- package/vitepress/components/EnWordList/EnWordList.module.scss +124 -124
- package/vitepress/components/EnWordList/EnWordList.vue +543 -542
- package/vitepress/components/EnWordList/RightClickMenu.module.scss +22 -22
- package/vitepress/components/EnWordList/RightClickMenu.vue +66 -66
- package/vitepress/components/Footprints/Footprints.module.scss +93 -93
- package/vitepress/components/Footprints/Footprints.vue +377 -377
- package/vitepress/components/Layout/AboutModal.module.scss +233 -233
- package/vitepress/components/Layout/AboutModal.vue +105 -105
- package/vitepress/components/Layout/AboutPanel.vue +270 -265
- package/vitepress/components/Layout/ContentCollapse.vue +603 -602
- package/vitepress/components/Layout/CustomSidebar.vue +608 -605
- package/vitepress/components/Layout/DocBeforeControls.vue +149 -139
- package/vitepress/components/Layout/DocFooter.vue +233 -232
- package/vitepress/components/Layout/ImagePreview.module.scss +201 -201
- package/vitepress/components/Layout/ImagePreview.vue +281 -280
- package/vitepress/components/Layout/Layout.module.scss +661 -661
- package/vitepress/components/Layout/Layout.vue +539 -542
- package/vitepress/components/Layout/NoteStatus.vue +140 -139
- package/vitepress/components/Layout/SidebarItems.vue +267 -262
- package/vitepress/components/Layout/SidebarNavBefore.vue +92 -92
- package/vitepress/components/Layout/Swiper.vue +167 -167
- package/vitepress/components/Layout/ToggleFullContent.module.scss +11 -11
- package/vitepress/components/Layout/ToggleFullContent.vue +35 -34
- package/vitepress/components/Layout/ToggleSidebar.module.scss +11 -11
- package/vitepress/components/Layout/ToggleSidebar.vue +36 -35
- package/vitepress/components/Layout/composables/useCollapseControl.ts +88 -88
- package/vitepress/components/Layout/composables/useNoteConfig.ts +119 -121
- package/vitepress/components/Layout/composables/useNoteSave.ts +173 -172
- package/vitepress/components/Layout/composables/useNoteValidation.ts +85 -85
- package/vitepress/components/Layout/composables/useRedirect.ts +113 -110
- package/vitepress/components/Layout/composables/useVSCodeIntegration.ts +86 -83
- package/vitepress/components/Layout/homeReadme.data.ts +124 -124
- package/vitepress/components/LoadingPage/LoadingPage.vue +192 -192
- package/vitepress/components/MarkMap/MarkMap.module.scss +159 -159
- package/vitepress/components/MarkMap/MarkMap.vue +405 -404
- package/vitepress/components/Mermaid/Mermaid.module.scss +275 -275
- package/vitepress/components/Mermaid/Mermaid.vue +365 -363
- package/vitepress/components/NotesTable/NotesTable.module.scss +77 -77
- package/vitepress/components/NotesTable/NotesTable.vue +98 -97
- package/vitepress/components/NotesTable/README.md +67 -67
- package/vitepress/components/Settings/Settings.module.scss +433 -433
- package/vitepress/components/Settings/Settings.vue +306 -305
- package/vitepress/components/SidebarCard/MindMapView.vue +484 -483
- package/vitepress/components/SidebarCard/NotesTrendChart.vue +108 -108
- package/vitepress/components/SidebarCard/SidebarCard.vue +946 -948
- package/vitepress/components/Tooltip/Tooltip.vue +70 -70
- package/vitepress/components/constants.ts +91 -91
- package/vitepress/components/notesConfig.data.ts +73 -73
- package/vitepress/components/sidebar.data.ts +59 -59
- package/vitepress/components/tnotes-config.data.ts +21 -21
- package/vitepress/components/utils.ts +26 -26
- package/vitepress/config/index.ts +160 -146
- package/vitepress/configs/constants.ts +26 -26
- package/vitepress/configs/head.config.ts +25 -24
- package/vitepress/configs/index.ts +9 -9
- package/vitepress/configs/markdown-it.d.ts +23 -20
- package/vitepress/configs/markdown.config.ts +366 -365
- package/vitepress/configs/theme.config.ts +108 -108
- package/vitepress/plugins/buildProgressPlugin.ts +434 -470
- package/vitepress/plugins/getNoteByConfigIdPlugin.ts +107 -106
- package/vitepress/plugins/renameNotePlugin.ts +60 -59
- package/vitepress/plugins/updateConfigPlugin.ts +63 -62
- package/vitepress/theme/index.ts +95 -93
- package/vitepress/theme/styles/base.scss +50 -50
- package/vitepress/theme/styles/components/404.scss +31 -31
- package/vitepress/theme/styles/components/collapse.scss +175 -175
- package/vitepress/theme/styles/components/markmap.scss +101 -101
- package/vitepress/theme/styles/components/swiper.scss +255 -255
- package/vitepress/theme/styles/index.scss +25 -25
- package/vitepress/theme/styles/layout.scss +62 -62
- package/vitepress/theme/styles/utilities.scss +39 -39
- package/vitepress/theme/styles/vitepress-override.scss +25 -25
|
@@ -1,366 +1,367 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* .vitepress/config/markdown.config.ts
|
|
3
|
-
*
|
|
4
|
-
* Markdown 配置
|
|
5
|
-
*/
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
1
|
+
/**
|
|
2
|
+
* .vitepress/config/markdown.config.ts
|
|
3
|
+
*
|
|
4
|
+
* Markdown 配置
|
|
5
|
+
*/
|
|
6
|
+
import fs from 'fs'
|
|
7
|
+
import MarkdownIt from 'markdown-it'
|
|
8
|
+
import markdownItContainer from 'markdown-it-container'
|
|
9
|
+
import mila from 'markdown-it-link-attributes'
|
|
10
|
+
import markdownItTaskLists from 'markdown-it-task-lists'
|
|
11
|
+
import path from 'path'
|
|
10
12
|
import { MarkdownOptions } from 'vitepress'
|
|
11
|
-
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
'
|
|
24
|
-
'
|
|
25
|
-
'
|
|
26
|
-
'"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
//
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
j
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
(/^
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
md.renderer.rules.
|
|
278
|
-
md.renderer.rules.
|
|
279
|
-
|
|
280
|
-
const token
|
|
281
|
-
const
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
<div class="tn-swiper
|
|
292
|
-
<div class="
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
md.renderer.rules.
|
|
304
|
-
md.renderer.rules.
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
<!--
|
|
310
|
-
<!--
|
|
311
|
-
<!--
|
|
312
|
-
<!--
|
|
313
|
-
<!--
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
}
|
|
13
|
+
|
|
14
|
+
import { generateAnchor } from '../../utils'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 辅助函数:HTML 转义
|
|
18
|
+
*/
|
|
19
|
+
function esc(s = '') {
|
|
20
|
+
return s.replace(
|
|
21
|
+
/[&<>"']/g,
|
|
22
|
+
(ch) =>
|
|
23
|
+
({
|
|
24
|
+
'&': '&',
|
|
25
|
+
'<': '<',
|
|
26
|
+
'>': '>',
|
|
27
|
+
'"': '"',
|
|
28
|
+
"'": ''',
|
|
29
|
+
}[ch]!)
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 简化的 Mermaid 处理函数
|
|
35
|
+
*/
|
|
36
|
+
const simpleMermaidMarkdown = (md: MarkdownIt) => {
|
|
37
|
+
const fence = md.renderer.rules.fence
|
|
38
|
+
? md.renderer.rules.fence.bind(md.renderer.rules)
|
|
39
|
+
: () => ''
|
|
40
|
+
|
|
41
|
+
md.renderer.rules.fence = (tokens, index, options, env, slf) => {
|
|
42
|
+
const token = tokens[index]
|
|
43
|
+
|
|
44
|
+
// 检查是否为 mermaid 代码块
|
|
45
|
+
if (token.info.trim() === 'mermaid') {
|
|
46
|
+
try {
|
|
47
|
+
const key = `mermaid-${Date.now()}-${Math.random()
|
|
48
|
+
.toString(36)
|
|
49
|
+
.substr(2, 9)}`
|
|
50
|
+
const content = token.content
|
|
51
|
+
return `<Mermaid id="${key}" graph="${encodeURIComponent(content)}" />`
|
|
52
|
+
} catch (err) {
|
|
53
|
+
return `<pre>${err}</pre>`
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 允许使用 mmd 标记显示 Mermaid 代码本身
|
|
58
|
+
if (token.info.trim() === 'mmd') {
|
|
59
|
+
tokens[index].info = 'mermaid'
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return fence(tokens, index, options, env, slf)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* MarkMap 容器配置
|
|
68
|
+
*/
|
|
69
|
+
function configureMarkMapContainer(md: MarkdownIt) {
|
|
70
|
+
// 先保留 container 的解析(负责把 ```markmap ``` 识别成 container tokens)
|
|
71
|
+
// 但让它本身不输出任何 HTML(render 返回空)
|
|
72
|
+
md.use(markdownItContainer, 'markmap', {
|
|
73
|
+
marker: '`',
|
|
74
|
+
validate(params: string) {
|
|
75
|
+
// 接受 "markmap", "markmap{...}" 或 "markmap key=val ..." 等写法
|
|
76
|
+
const p = (params || '').trim()
|
|
77
|
+
return p.startsWith('markmap')
|
|
78
|
+
},
|
|
79
|
+
render() {
|
|
80
|
+
return ''
|
|
81
|
+
},
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
// 在 core 阶段把整个 container 区间替换成一个 html_block(MarkMap 组件标签)
|
|
85
|
+
// 这样渲染时就只输出 <MarkMap ...>,中间的列表 token 已被移除
|
|
86
|
+
md.core.ruler.after('block', 'tn_replace_markmap_container', (state) => {
|
|
87
|
+
const src = state.env.source || ''
|
|
88
|
+
const lines = src.split('\n')
|
|
89
|
+
const tokens = state.tokens
|
|
90
|
+
|
|
91
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
92
|
+
const t = tokens[i]
|
|
93
|
+
if (t.type === 'container_markmap_open') {
|
|
94
|
+
// 找到对应的 close token
|
|
95
|
+
let j = i + 1
|
|
96
|
+
while (
|
|
97
|
+
j < tokens.length &&
|
|
98
|
+
tokens[j].type !== 'container_markmap_close'
|
|
99
|
+
)
|
|
100
|
+
j++
|
|
101
|
+
if (j >= tokens.length) continue // safety
|
|
102
|
+
|
|
103
|
+
// 使用 token.map 提取源文件对应行(open.token.map 存着 container 起止行)
|
|
104
|
+
const open = t
|
|
105
|
+
const startLine = open.map ? open.map[0] + 1 : null
|
|
106
|
+
const endLine = open.map ? open.map[1] - 1 : null
|
|
107
|
+
|
|
108
|
+
// 1) 从开头 fence 行解析参数(支持 `{a=1 b="x"}`、`a=1 b="x"`,并支持单个数字 shorthand)
|
|
109
|
+
const params: { [key: string]: any; initialExpandLevel?: number } = {}
|
|
110
|
+
|
|
111
|
+
if (open.map && typeof open.map[0] === 'number') {
|
|
112
|
+
const openLine = (lines[open.map[0]] || '').trim()
|
|
113
|
+
let paramPart = ''
|
|
114
|
+
|
|
115
|
+
// 优先匹配大括号形式 ```markmap{...}
|
|
116
|
+
const braceMatch = openLine.match(/\{([^}]*)\}/)
|
|
117
|
+
if (braceMatch) {
|
|
118
|
+
paramPart = braceMatch[1].trim()
|
|
119
|
+
} else {
|
|
120
|
+
// 否则尝试去掉前缀 ``` 和 markmap,剩下的作为参数部分
|
|
121
|
+
const after = openLine.replace(/^`+\s*/, '')
|
|
122
|
+
if (after.startsWith('markmap')) {
|
|
123
|
+
paramPart = after.slice('markmap'.length).trim()
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (paramPart) {
|
|
128
|
+
// 使用正则按 token 切分:保持用引号包裹的片段为单个 token(支持包含空格)
|
|
129
|
+
const tokenArr = paramPart.match(/"[^"]*"|'[^']*'|\S+/g) || []
|
|
130
|
+
|
|
131
|
+
// 如果第一个 token 是纯数字,把它当作 initialExpandLevel
|
|
132
|
+
let startIdx = 0
|
|
133
|
+
if (tokenArr.length > 0 && /^\d+$/.test(tokenArr[0] as string)) {
|
|
134
|
+
params.initialExpandLevel = Number(tokenArr[0])
|
|
135
|
+
startIdx = 1
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// 解析剩余 token 为 key=value(支持 key=val 或 key:val)
|
|
139
|
+
for (let k = startIdx; k < tokenArr.length; k++) {
|
|
140
|
+
const pair = tokenArr[k]
|
|
141
|
+
if (!pair) continue
|
|
142
|
+
const m = pair.match(/^([^=:\s]+)\s*(=|:)\s*(.+)$/)
|
|
143
|
+
if (m) {
|
|
144
|
+
const key = m[1]
|
|
145
|
+
let val = m[3]
|
|
146
|
+
|
|
147
|
+
// 去除外层引号(若存在)
|
|
148
|
+
if (
|
|
149
|
+
(/^".*"$/.test(val) && val.length >= 2) ||
|
|
150
|
+
(/^'.*'$/.test(val) && val.length >= 2)
|
|
151
|
+
) {
|
|
152
|
+
val = val.slice(1, -1)
|
|
153
|
+
} else if (/^\d+$/.test(val)) {
|
|
154
|
+
// 纯数字转字符串
|
|
155
|
+
val = String(Number(val))
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
params[key] = val
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// 2) 提取内容(支持文件引用语法 `<<< ./path/to/file.md`)
|
|
165
|
+
let content = ''
|
|
166
|
+
if (startLine !== null && endLine !== null) {
|
|
167
|
+
for (let k = startLine; k <= endLine && k < lines.length; k++) {
|
|
168
|
+
content += lines[k] + '\n'
|
|
169
|
+
}
|
|
170
|
+
} else {
|
|
171
|
+
// 回退:如果没有 map 信息,尝试用中间 tokens 拼接文本
|
|
172
|
+
for (let k = i + 1; k < j; k++) {
|
|
173
|
+
content += tokens[k].content || ''
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// --- 检查第一非空行是否为引用语法 ---
|
|
178
|
+
const firstNonEmptyLine =
|
|
179
|
+
(content || '').split('\n').find((ln) => ln.trim() !== '') || ''
|
|
180
|
+
const refMatch = firstNonEmptyLine.trim().match(/^<<<\s*(.+)$/)
|
|
181
|
+
if (refMatch) {
|
|
182
|
+
// 提取引用路径,支持引号包裹
|
|
183
|
+
const refRaw = refMatch[1].trim().replace(/^['"]|['"]$/g, '')
|
|
184
|
+
|
|
185
|
+
// 尝试同步读取文件内容(兼容常见 Node 环境)
|
|
186
|
+
try {
|
|
187
|
+
// 尝试根据当前 markdown 文件位置解析相对路径
|
|
188
|
+
const env = state.env || {}
|
|
189
|
+
const possibleRel =
|
|
190
|
+
env.relativePath || env.path || env.filePath || env.file || ''
|
|
191
|
+
let refFullPath = refRaw
|
|
192
|
+
|
|
193
|
+
if (!path.isAbsolute(refRaw)) {
|
|
194
|
+
if (possibleRel) {
|
|
195
|
+
// 将 relativePath 视作相对于项目根的路径(例如 'notes/foo/bar.md'),取其目录
|
|
196
|
+
const currentDir = path.dirname(possibleRel)
|
|
197
|
+
// 解析到 process.cwd()
|
|
198
|
+
refFullPath = path.resolve(process.cwd(), currentDir, refRaw)
|
|
199
|
+
} else {
|
|
200
|
+
// 没有相对文件信息,则相对于项目根解析
|
|
201
|
+
refFullPath = path.resolve(process.cwd(), refRaw)
|
|
202
|
+
}
|
|
203
|
+
} else {
|
|
204
|
+
// 绝对路径直接使用(按系统路径)
|
|
205
|
+
refFullPath = refRaw
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// console.log('refFullPath:', refFullPath)
|
|
209
|
+
const fileContent = fs.readFileSync(refFullPath, 'utf-8')
|
|
210
|
+
content = fileContent
|
|
211
|
+
} catch (err) {
|
|
212
|
+
// 读取失败:将错误写入 content 以便排查(不会让流程直接崩溃)
|
|
213
|
+
const errorMsg = err instanceof Error ? err.message : String(err)
|
|
214
|
+
content = `Failed to load referenced file: ${esc(
|
|
215
|
+
String(refRaw)
|
|
216
|
+
)}\n\nError: ${esc(errorMsg)}`
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// 3) 构造组件标签并把参数注入为 props
|
|
221
|
+
const encodedContent = encodeURIComponent(content.trim())
|
|
222
|
+
let propsStr = `content="${encodedContent}"`
|
|
223
|
+
|
|
224
|
+
for (const [k, v] of Object.entries(params)) {
|
|
225
|
+
if (typeof v === 'number' || /^\d+$/.test(String(v))) {
|
|
226
|
+
propsStr += ` :${k}="${v}"`
|
|
227
|
+
} else {
|
|
228
|
+
const safe = String(v).replace(/"/g, '"')
|
|
229
|
+
propsStr += ` ${k}="${safe}"`
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const html = `<MarkMap ${propsStr}></MarkMap>\n`
|
|
234
|
+
|
|
235
|
+
// 创建 html_block token
|
|
236
|
+
const htmlToken = new state.Token('html_block', '', 0)
|
|
237
|
+
htmlToken.content = html
|
|
238
|
+
|
|
239
|
+
// 用单个 html_token 替换 open..close 区间
|
|
240
|
+
tokens.splice(i, j - i + 1, htmlToken as any)
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return true
|
|
245
|
+
})
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Swiper 容器配置
|
|
250
|
+
*/
|
|
251
|
+
function configureSwiperContainer(md: MarkdownIt) {
|
|
252
|
+
let __tn_swiper_uid = 0
|
|
253
|
+
|
|
254
|
+
interface TN_RULES_STACK_ITEM {
|
|
255
|
+
image: any
|
|
256
|
+
pOpen: any
|
|
257
|
+
pClose: any
|
|
258
|
+
}
|
|
259
|
+
let __tn_rules_stack: Array<TN_RULES_STACK_ITEM> = []
|
|
260
|
+
|
|
261
|
+
// 每个文档渲染前重置计数器
|
|
262
|
+
md.core.ruler.before('block', 'tn_swiper_reset_uid', () => {
|
|
263
|
+
__tn_swiper_uid = 0
|
|
264
|
+
__tn_rules_stack = []
|
|
265
|
+
return true
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
md.use(markdownItContainer, 'swiper', {
|
|
269
|
+
render: (tokens: any[], idx: number) => {
|
|
270
|
+
if (tokens[idx].nesting === 1) {
|
|
271
|
+
// 进容器:保存原规则 & 局部覆盖
|
|
272
|
+
__tn_rules_stack.push({
|
|
273
|
+
image: md.renderer.rules.image,
|
|
274
|
+
pOpen: md.renderer.rules.paragraph_open,
|
|
275
|
+
pClose: md.renderer.rules.paragraph_close,
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
md.renderer.rules.paragraph_open = () => ''
|
|
279
|
+
md.renderer.rules.paragraph_close = () => ''
|
|
280
|
+
md.renderer.rules.image = (tokens: any[], i: number) => {
|
|
281
|
+
const token: any = tokens[i]
|
|
282
|
+
const src = token.attrGet('src') || ''
|
|
283
|
+
const alt = token.content || ''
|
|
284
|
+
const title = alt && alt.trim() ? alt : 'img'
|
|
285
|
+
return `<div class="swiper-slide" data-title="${esc(
|
|
286
|
+
title
|
|
287
|
+
)}"><img src="${esc(src)}" alt="${esc(alt)}"></div>`
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const id = `tn-swiper-${++__tn_swiper_uid}`
|
|
291
|
+
return `
|
|
292
|
+
<div class="tn-swiper" data-swiper-id="${id}">
|
|
293
|
+
<div class="tn-swiper-tabs"></div>
|
|
294
|
+
<div class="swiper-container">
|
|
295
|
+
<div class="swiper-wrapper">
|
|
296
|
+
`
|
|
297
|
+
} else {
|
|
298
|
+
// 出容器:恢复原规则并收尾
|
|
299
|
+
const prev: TN_RULES_STACK_ITEM = __tn_rules_stack.pop() || {
|
|
300
|
+
image: null,
|
|
301
|
+
pOpen: null,
|
|
302
|
+
pClose: null,
|
|
303
|
+
}
|
|
304
|
+
md.renderer.rules.image = prev.image
|
|
305
|
+
md.renderer.rules.paragraph_open = prev.pOpen
|
|
306
|
+
md.renderer.rules.paragraph_close = prev.pClose
|
|
307
|
+
|
|
308
|
+
return `
|
|
309
|
+
</div>
|
|
310
|
+
<!-- 下一页按钮 -->
|
|
311
|
+
<!-- <div class="swiper-button-next"></div> -->
|
|
312
|
+
<!-- 上一页按钮 -->
|
|
313
|
+
<!-- <div class="swiper-button-prev"></div> -->
|
|
314
|
+
<!-- 分页导航 -->
|
|
315
|
+
<!-- <div class="swiper-pagination"></div> -->
|
|
316
|
+
</div>
|
|
317
|
+
</div>
|
|
318
|
+
`
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
})
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Markdown 配置
|
|
326
|
+
*/
|
|
327
|
+
export function getMarkdownConfig(): MarkdownOptions {
|
|
328
|
+
const markdown: MarkdownOptions = {
|
|
329
|
+
lineNumbers: true,
|
|
330
|
+
math: true,
|
|
331
|
+
config(md) {
|
|
332
|
+
// 添加前置规则保存原始内容
|
|
333
|
+
md.core.ruler.before('normalize', 'save-source', (state) => {
|
|
334
|
+
state.env.source = state.src
|
|
335
|
+
return true
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
// 添加 Mermaid 支持
|
|
339
|
+
simpleMermaidMarkdown(md)
|
|
340
|
+
|
|
341
|
+
// 添加 MarkMap 支持
|
|
342
|
+
configureMarkMapContainer(md)
|
|
343
|
+
|
|
344
|
+
// 添加任务列表支持
|
|
345
|
+
md.use(markdownItTaskLists)
|
|
346
|
+
|
|
347
|
+
// 添加链接属性支持
|
|
348
|
+
md.use(mila, {
|
|
349
|
+
attrs: {
|
|
350
|
+
target: '_self',
|
|
351
|
+
rel: 'noopener',
|
|
352
|
+
},
|
|
353
|
+
})
|
|
354
|
+
|
|
355
|
+
// 添加 Swiper 支持
|
|
356
|
+
configureSwiperContainer(md)
|
|
357
|
+
},
|
|
358
|
+
anchor: {
|
|
359
|
+
slugify: generateAnchor,
|
|
360
|
+
},
|
|
361
|
+
image: {
|
|
362
|
+
lazyLoading: true,
|
|
363
|
+
},
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
return markdown
|
|
367
|
+
}
|