@@ -68,6 +68,8 @@ function findRegion(lines: Array<string>, regionName: string) {
68
68
return null
69
69
}
70
70
71
+ const reMonacoWrite = / ^ \{ m o n a c o - w r i t e \} /
72
+
71
73
/**
72
74
* format: ">>> /path/to/file.extension#region language meta..."
73
75
* where #region, language and meta are optional
@@ -93,8 +95,9 @@ export function transformSnippet({ s, slide, options }: MarkdownTransformContext
93
95
: path . resolve ( dir , filepath ) ,
94
96
)
95
97
96
- watchFiles [ src ] ??= new Set ( )
97
- watchFiles [ src ] . add ( slide . index )
98
+ meta = meta . trim ( )
99
+ lang = lang . trim ( )
100
+ lang = lang || path . extname ( filepath ) . slice ( 1 )
98
101
99
102
const isAFile = fs . statSync ( src ) . isFile ( )
100
103
if ( ! fs . existsSync ( src ) || ! isAFile ) {
@@ -119,17 +122,17 @@ export function transformSnippet({ s, slide, options }: MarkdownTransformContext
119
122
}
120
123
}
121
124
122
- meta = meta . trim ( )
123
- lang = lang . trim ( )
124
- lang = lang || path . extname ( filepath ) . slice ( 1 )
125
-
126
- if ( meta . match ( / ^ \{ m o n a c o - w r i t e \} / ) ) {
125
+ if ( meta . match ( reMonacoWrite ) ) {
127
126
monacoWriterWhitelist . add ( filepath )
128
127
lang = lang . trim ( )
129
- meta = meta . replace ( / ^ \{ m o n a c o - w r i t e \} / , '' ) . trim ( ) || '{}'
128
+ meta = meta . replace ( reMonacoWrite , '' ) . trim ( ) || '{}'
130
129
const encoded = lz . compressToBase64 ( content )
131
130
return `<Monaco writable=${ JSON . stringify ( filepath ) } code-lz="${ encoded } " lang="${ lang } " v-bind="${ meta } " />`
132
131
}
132
+ else {
133
+ watchFiles [ src ] ??= new Set ( )
134
+ watchFiles [ src ] . add ( slide . index )
135
+ }
133
136
134
137
return `\`\`\`${ lang } ${ meta } \n${ content } \n\`\`\``
135
138
} ,
0 commit comments