@@ -198,6 +198,14 @@ public string Render(string diagramText, Theme? theme, string? paletteJson, bool
198198 diagram . LayoutHints . EdgeRouting = frontmatter . EdgeRouting . Value ;
199199 }
200200
201+ // Frontmatter title/subtitle override the parser-supplied values only when the parser
202+ // did not already set them (inline directives take precedence over frontmatter).
203+ if ( frontmatter . Title is not null && string . IsNullOrWhiteSpace ( diagram . Title ) )
204+ diagram . Title = frontmatter . Title ;
205+
206+ if ( frontmatter . Subtitle is not null && string . IsNullOrWhiteSpace ( diagram . Subtitle ) )
207+ diagram . Subtitle = frontmatter . Subtitle ;
208+
201209 ResolveIcons ( diagram ) ;
202210 _layoutEngine . Layout ( diagram , effectiveTheme ) ;
203211 return _svgRenderer . Render ( diagram , effectiveTheme ) ;
@@ -407,6 +415,8 @@ private static FrontmatterOptions ParseFrontmatter(string raw)
407415 string ? parsedShadowStyle = null ;
408416 bool ? parsedTransparentBackground = null ;
409417 EdgeRouting ? parsedEdgeRouting = null ;
418+ string ? parsedTitle = null ;
419+ string ? parsedSubtitle = null ;
410420
411421 foreach ( string rawLine in frontmatter . Split ( '\n ' ) )
412422 {
@@ -468,9 +478,17 @@ private static FrontmatterOptions ParseFrontmatter(string raw)
468478 {
469479 parsedEdgeRouting = ParseEdgeRouting ( Unquote ( line [ "edge-routing:" . Length ..] . Trim ( ) ) , raw ) ;
470480 }
481+ else if ( line . StartsWith ( "title:" , StringComparison . OrdinalIgnoreCase ) )
482+ {
483+ parsedTitle = Unquote ( line [ "title:" . Length ..] . Trim ( ) ) ;
484+ }
485+ else if ( line . StartsWith ( "subtitle:" , StringComparison . OrdinalIgnoreCase ) )
486+ {
487+ parsedSubtitle = Unquote ( line [ "subtitle:" . Length ..] . Trim ( ) ) ;
488+ }
471489 }
472490
473- return new FrontmatterOptions ( diagramText , parsedTheme , parsedPaletteJson , parsedBorderStyle , parsedFillStyle , parsedShadowStyle , parsedTransparentBackground , parsedEdgeRouting ) ;
491+ return new FrontmatterOptions ( diagramText , parsedTheme , parsedPaletteJson , parsedBorderStyle , parsedFillStyle , parsedShadowStyle , parsedTransparentBackground , parsedEdgeRouting , parsedTitle , parsedSubtitle ) ;
474492 }
475493
476494 private static void ApplyBorderStyle ( Theme theme , string borderStyle )
@@ -607,7 +625,7 @@ private static bool ParseBoolean(string rawValue, string raw, string fieldName)
607625 } ;
608626 }
609627
610- private sealed record FrontmatterOptions ( string DiagramText , Theme ? Theme , string ? PaletteJson , string ? BorderStyle , string ? FillStyle , string ? ShadowStyle , bool ? TransparentBackground , EdgeRouting ? EdgeRouting = null ) ;
628+ private sealed record FrontmatterOptions ( string DiagramText , Theme ? Theme , string ? PaletteJson , string ? BorderStyle , string ? FillStyle , string ? ShadowStyle , bool ? TransparentBackground , EdgeRouting ? EdgeRouting = null , string ? Title = null , string ? Subtitle = null ) ;
611629}
612630
613631[ System . Text . Json . Serialization . JsonSerializable ( typeof ( List < string > ) ) ]
0 commit comments