@@ -24,6 +24,8 @@ public SharedExampleRegistry()
2424 . Build ( ) ;
2525 }
2626
27+ public List < string > Errors { get ; } = new ( ) ;
28+
2729 public void LoadExamples ( string directory )
2830 {
2931 if ( ! Directory . Exists ( directory ) )
@@ -36,14 +38,20 @@ public void LoadExamples(string directory)
3638
3739 // Extract frontmatter and code content
3840 var ( frontmatter , body ) = ParseFrontmatter ( content ) ;
39- var ( language , code ) = ParseCodeBlock ( body ) ;
41+
42+ if ( string . IsNullOrWhiteSpace ( frontmatter ? . Title ) )
43+ {
44+ Errors . Add ( $ "{ file } : Missing required 'title' in frontmatter") ;
45+ continue ;
46+ }
47+
48+ var codeBlocks = ParseCodeBlocks ( body ) ;
4049
4150 _examples [ name ] = new SharedExample
4251 {
4352 Name = name ,
44- Title = frontmatter ? . Title ,
45- Content = code ,
46- Language = language ,
53+ Title = frontmatter . Title ,
54+ Examples = codeBlocks ,
4755 SourceFile = file
4856 } ;
4957 }
@@ -82,8 +90,9 @@ public void LoadExamples(string directory)
8290 }
8391 }
8492
85- private static ( string ? language , string content ) ParseCodeBlock ( string content )
93+ private static List < SharedExampleCode > ParseCodeBlocks ( string content )
8694 {
95+ var blocks = new List < SharedExampleCode > ( ) ;
8796 var lines = content . Split ( '\n ' ) ;
8897 var codeLines = new List < string > ( ) ;
8998 string ? language = null ;
@@ -99,14 +108,19 @@ private static (string? language, string content) ParseCodeBlock(string content)
99108 {
100109 // Start of code block - extract language
101110 inCodeBlock = true ;
111+ codeLines . Clear ( ) ;
102112 var langPart = trimmed [ 3 ..] . Trim ( ) ;
103- if ( ! string . IsNullOrEmpty ( langPart ) )
104- language = langPart ;
113+ language = ! string . IsNullOrEmpty ( langPart ) ? langPart : null ;
105114 }
106115 else
107116 {
108- // End of code block
117+ // End of code block - save it
109118 inCodeBlock = false ;
119+ blocks . Add ( new SharedExampleCode
120+ {
121+ Content = string . Join ( "\n " , codeLines ) . Trim ( ) ,
122+ Language = language
123+ } ) ;
110124 }
111125 }
112126 else if ( inCodeBlock )
@@ -115,7 +129,7 @@ private static (string? language, string content) ParseCodeBlock(string content)
115129 }
116130 }
117131
118- return ( language , string . Join ( " \n " , codeLines ) . Trim ( ) ) ;
132+ return blocks ;
119133 }
120134
121135 public bool Contains ( string name ) => _examples . ContainsKey ( name ) ;
0 commit comments