@@ -54,6 +54,7 @@ const highlighter = await createHighlighterCore({
54
54
import ( '@shikijs/langs/css' ) ,
55
55
import ( '@shikijs/langs/bash' ) ,
56
56
import ( '@shikijs/langs/yaml' ) ,
57
+ import ( '@shikijs/langs/toml' ) ,
57
58
import ( '@shikijs/langs/svelte' )
58
59
] ,
59
60
engine : createOnigurumaEngine ( import ( 'shiki/wasm' ) )
@@ -234,7 +235,14 @@ export async function render_content_markdown(
234
235
235
236
if ( ( token . lang === 'js' || token . lang === 'ts' ) && check ) {
236
237
const match = / ( (?: [ \s \S ] + ) \/ \/ - - - c u t - - - \n ) ? ( [ \s \S ] + ) / . exec ( source ) ! ;
237
- [ , prelude = '// ---cut---\n' , source ] = match ;
238
+ // we need to ensure that the source content is separated from the
239
+ // injected content by a '// @filename: ...' otherwise it will be
240
+ // interpreted as the same file and prevent types from working
241
+ [
242
+ ,
243
+ prelude = `${ source . includes ( '// @filename:' ) ? '' : '// @filename: dummy.' + token . lang } \n// ---cut---\n` ,
244
+ source
245
+ ] = match ;
238
246
239
247
const banner = twoslashBanner ?.( filename , source ) ;
240
248
if ( banner ) prelude = '// @filename: injected.d.ts\n' + banner + '\n' + prelude ;
@@ -757,7 +765,7 @@ async function syntax_highlight({
757
765
/** We need to stash code wrapped in `---` highlights, because otherwise TS will error on e.g. bad syntax, duplicate declarations */
758
766
const redactions : string [ ] = [ ] ;
759
767
760
- const redacted = source . replace ( / ( { 13 } (?: [ ^ ] [ ^ ] + ?) { 13 } ) / g, ( _ , content ) => {
768
+ let redacted = source . replace ( / ( { 13 } (?: [ ^ ] [ ^ ] + ?) { 13 } ) / g, ( _ , content ) => {
761
769
redactions . push ( content ) ;
762
770
return ' ' . repeat ( content . length ) ;
763
771
} ) ;
@@ -773,7 +781,9 @@ async function syntax_highlight({
773
781
compilerOptions : {
774
782
allowJs : true ,
775
783
checkJs : true ,
776
- types : [ 'svelte' , '@sveltejs/kit' ]
784
+ // we always include the Svelte types because it's easier
785
+ // than adding a reference when we detect a rune being used
786
+ types : [ 'node' , 'svelte' ]
777
787
}
778
788
} ,
779
789
// by default, twoslash does not run on .js files, change that through this option
@@ -860,7 +870,7 @@ async function syntax_highlight({
860
870
html = replace_blank_lines ( html ) ;
861
871
} else {
862
872
const highlighted = highlighter . codeToHtml ( source , {
863
- lang : SHIKI_LANGUAGE_MAP [ language as keyof typeof SHIKI_LANGUAGE_MAP ] ,
873
+ lang : SHIKI_LANGUAGE_MAP [ language as keyof typeof SHIKI_LANGUAGE_MAP ] ?? language ,
864
874
theme
865
875
} ) ;
866
876
@@ -884,6 +894,7 @@ async function syntax_highlight({
884
894
. replace ( / { 11 } ( [ ^ ] [ ^ ] + ?) { 11 } / g, ( _ , content ) => {
885
895
return highlight_spans ( content , 'highlight add' ) ;
886
896
} )
897
+ // TODO: make this not highlight the static adapter's github yaml deploy file
887
898
. replace ( / { 9 } ( [ ^ ] [ ^ ] + ?) { 9 } / g, ( _ , content ) => {
888
899
return highlight_spans ( content , 'highlight' ) ;
889
900
} ) ;
0 commit comments