@@ -54,6 +54,7 @@ const highlighter = await createHighlighterCore({
5454 import ( '@shikijs/langs/css' ) ,
5555 import ( '@shikijs/langs/bash' ) ,
5656 import ( '@shikijs/langs/yaml' ) ,
57+ import ( '@shikijs/langs/toml' ) ,
5758 import ( '@shikijs/langs/svelte' )
5859 ] ,
5960 engine : createOnigurumaEngine ( import ( 'shiki/wasm' ) )
@@ -234,7 +235,14 @@ export async function render_content_markdown(
234235
235236 if ( ( token . lang === 'js' || token . lang === 'ts' ) && check ) {
236237 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 ;
238246
239247 const banner = twoslashBanner ?.( filename , source ) ;
240248 if ( banner ) prelude = '// @filename: injected.d.ts\n' + banner + '\n' + prelude ;
@@ -757,7 +765,7 @@ async function syntax_highlight({
757765 /** We need to stash code wrapped in `---` highlights, because otherwise TS will error on e.g. bad syntax, duplicate declarations */
758766 const redactions : string [ ] = [ ] ;
759767
760- const redacted = source . replace ( / ( { 13 } (?: [ ^ ] [ ^ ] + ?) { 13 } ) / g, ( _ , content ) => {
768+ let redacted = source . replace ( / ( { 13 } (?: [ ^ ] [ ^ ] + ?) { 13 } ) / g, ( _ , content ) => {
761769 redactions . push ( content ) ;
762770 return ' ' . repeat ( content . length ) ;
763771 } ) ;
@@ -773,7 +781,9 @@ async function syntax_highlight({
773781 compilerOptions : {
774782 allowJs : true ,
775783 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' ]
777787 }
778788 } ,
779789 // by default, twoslash does not run on .js files, change that through this option
@@ -860,7 +870,7 @@ async function syntax_highlight({
860870 html = replace_blank_lines ( html ) ;
861871 } else {
862872 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 ,
864874 theme
865875 } ) ;
866876
@@ -884,6 +894,7 @@ async function syntax_highlight({
884894 . replace ( / { 11 } ( [ ^ ] [ ^ ] + ?) { 11 } / g, ( _ , content ) => {
885895 return highlight_spans ( content , 'highlight add' ) ;
886896 } )
897+ // TODO: make this not highlight the static adapter's github yaml deploy file
887898 . replace ( / { 9 } ( [ ^ ] [ ^ ] + ?) { 9 } / g, ( _ , content ) => {
888899 return highlight_spans ( content , 'highlight' ) ;
889900 } ) ;
0 commit comments