@@ -4,9 +4,11 @@ import type { Plugin, ViteDevServer } from 'vite'
4
4
import { notNullish , range } from '@antfu/utils'
5
5
import * as parser from '@slidev/parser/fs'
6
6
import equal from 'fast-deep-equal'
7
+ import MarkdownIt from 'markdown-it'
7
8
import YAML from 'yaml'
8
- import { sharedMd } from '../commands/shared'
9
9
import { createDataUtils } from '../options'
10
+ import MarkdownItKatex from '../syntax/markdown-it/markdown-it-katex'
11
+ import markdownItLink from '../syntax/markdown-it/markdown-it-link'
10
12
import { getBodyJson , updateFrontmatterPatch } from '../utils'
11
13
import { templates } from '../virtual'
12
14
import { templateConfigs } from '../virtual/configs'
@@ -16,32 +18,17 @@ import { templateSlides, VIRTUAL_SLIDE_PREFIX } from '../virtual/slides'
16
18
import { templateTitleRendererMd } from '../virtual/titles'
17
19
import { regexSlideFacadeId , regexSlideReqPath , regexSlideSourceId } from './common'
18
20
19
- function renderNote ( text : string = '' ) {
20
- let clickCount = 0
21
- const html = sharedMd . render ( text
22
- // replace [click] marker with span
23
- . replace ( / \[ c l i c k (?: : ( \d + ) ) ? \] / gi, ( _ , count = 1 ) => {
24
- clickCount += Number ( count )
25
- return `<span class="slidev-note-click-mark" data-clicks="${ clickCount } "></span>`
26
- } ) ,
27
- )
28
-
29
- return html
30
- }
31
-
32
- function withRenderedNote ( data : SlideInfo ) : SlideInfo {
33
- return {
34
- ...data ,
35
- noteHTML : renderNote ( data ?. note ) ,
36
- }
37
- }
38
-
39
21
export function createSlidesLoader (
40
22
options : ResolvedSlidevOptions ,
41
23
serverOptions : SlidevServerOptions ,
42
24
) : Plugin {
43
25
const { data, mode, utils } = options
44
26
27
+ const notesMd = MarkdownIt ( { html : true } )
28
+ notesMd . use ( markdownItLink )
29
+ if ( data . features . katex )
30
+ notesMd . use ( MarkdownItKatex , utils . katexOptions )
31
+
45
32
const hmrSlidesIndexes = new Set < number > ( )
46
33
let server : ViteDevServer | undefined
47
34
let skipHmr : { filePath : string , fileContent : string } | null = null
@@ -374,4 +361,24 @@ export function createSlidesLoader(
374
361
return ''
375
362
} ,
376
363
}
364
+
365
+ function renderNote ( text : string = '' ) {
366
+ let clickCount = 0
367
+ const html = notesMd . render ( text
368
+ // replace [click] marker with span
369
+ . replace ( / \[ c l i c k (?: : ( \d + ) ) ? \] / gi, ( _ , count = 1 ) => {
370
+ clickCount += Number ( count )
371
+ return `<span class="slidev-note-click-mark" data-clicks="${ clickCount } "></span>`
372
+ } ) ,
373
+ )
374
+
375
+ return html
376
+ }
377
+
378
+ function withRenderedNote ( data : SlideInfo ) : SlideInfo {
379
+ return {
380
+ ...data ,
381
+ noteHTML : renderNote ( data ?. note ) ,
382
+ }
383
+ }
377
384
}
0 commit comments