@@ -3,7 +3,7 @@ import type { Renderer, Token } from "markdown-it";
3
3
import type { SiteConfig } from "vitepress" ;
4
4
import container from "markdown-it-container" ;
5
5
import { readFileSync } from "fs" ;
6
- import { join , resolve , normalize } from "path" ;
6
+ import { join , resolve , posix } from "path" ;
7
7
import type { Demo } from "../../config" ;
8
8
9
9
interface ContainerOpts {
@@ -13,11 +13,10 @@ interface ContainerOpts {
13
13
}
14
14
15
15
const demoPlugin = ( md : MarkdownIt , option : Demo = { } ) => {
16
- console . log ( option ) ;
17
16
const siteConfig : SiteConfig = ( globalThis as any ) . VITEPRESS_CONFIG ;
18
17
const srcDir = siteConfig . srcDir ;
19
- const { path = "examples" } = option ;
20
- const demoPath = join ( srcDir , path || "" ) ;
18
+ const path = "examples" ;
19
+ const demoPath = join ( srcDir , path ) ;
21
20
22
21
const options : ContainerOpts = {
23
22
validate ( params ) {
@@ -34,7 +33,6 @@ const demoPlugin = (md: MarkdownIt, option: Demo = {}) => {
34
33
const containerContent = sourceFileToken . children ?. [ 0 ] . content ?? "" ;
35
34
// 确保文件路径带 .vue
36
35
const sourceFile = containerContent ? `${ containerContent . replace ( / .v u e $ / , "" ) } .vue` : "" ;
37
- const sourceRelativeFile = normalize ( join ( path , sourceFile ) ) ;
38
36
39
37
if ( sourceFile && sourceFileToken . type === "inline" ) {
40
38
source = readFileSync ( resolve ( demoPath , sourceFile ) , "utf-8" ) ;
@@ -43,7 +41,7 @@ const demoPlugin = (md: MarkdownIt, option: Demo = {}) => {
43
41
44
42
return `<TkDemoCode source="${ encodeURIComponent (
45
43
md . render ( `\`\`\` vue\n${ source } \`\`\`` )
46
- ) } " path="${ sourceRelativeFile } " raw-source="${ encodeURIComponent (
44
+ ) } " path="${ posix . join ( path , sourceFile ) } " raw-source="${ encodeURIComponent (
47
45
source
48
46
) } " description="${ encodeURIComponent ( md . render ( description ) ) } " demo="${ encodeURIComponent ( JSON . stringify ( option ) ) } ">`;
49
47
} else return "</TkDemoCode>" ;
0 commit comments