11import { CodeMapping , type LanguagePlugin , type VirtualCode } from '@volar/language-core' ;
22import type * as ts from 'typescript' ;
33import type { URI } from 'vscode-uri' ;
4+ import { FILES_FOLDER , SOLUTION_FOLDER } from '../models/tree/constants' ;
45
5- export function frontmatterPlugin ( debug : ( message : string ) => void ) : LanguagePlugin < URI > {
6+ export function frontmatterPlugin ( _debug : ( message : string ) => void ) : LanguagePlugin < URI > {
67 return {
78 getLanguageId ( uri ) {
8- debug ( 'URI: ' + uri . path ) ;
9-
109 if ( uri . path . endsWith ( '.md' ) ) {
1110 return 'markdown' ;
1211 }
@@ -17,7 +16,17 @@ export function frontmatterPlugin(debug: (message: string) => void): LanguagePlu
1716
1817 return undefined ;
1918 } ,
20- createVirtualCode ( _uri , languageId , snapshot ) {
19+ createVirtualCode ( uri , languageId , snapshot ) {
20+ // only match markdown files inside the src/content/tutorial folder
21+ if ( ! uri . path . match ( / .* s r c \/ c o n t e n t \/ t u t o r i a l \/ .* ( c o n t e n t | m e t a ) \. m d x ? $ / ) ) {
22+ return undefined ;
23+ }
24+
25+ // but ignore all files under _files or _solution
26+ if ( uri . path . includes ( FILES_FOLDER ) || uri . path . includes ( SOLUTION_FOLDER ) ) {
27+ return undefined ;
28+ }
29+
2130 if ( languageId === 'markdown' || languageId === 'mdx' ) {
2231 return new FrontMatterVirtualCode ( snapshot ) ;
2332 }
@@ -74,7 +83,7 @@ function* frontMatterCode(snapshot: ts.IScriptSnapshot): Generator<VirtualCode>
7483 const frontMatterText = content . substring ( frontMatterStartIndex , frontMatterEndIndex ) ;
7584
7685 yield {
77- id : 'frontmatter_1 ' ,
86+ id : 'tutorialkit_frontmatter ' ,
7887 languageId : 'yaml' ,
7988 snapshot : {
8089 getText : ( start , end ) => frontMatterText . slice ( start , end ) ,
0 commit comments