1+ using System . Text . Json . Serialization ;
12using Markdig ;
23using Markdig . Renderers ;
34using Markdig . Renderers . Html ;
5+ using Newtonsoft . Json ;
46using PlantUml . Net ;
57
68namespace Docfx . MarkdigEngine . Extensions ;
79
8- public class DocfxPlantUmlSettings : PlantUmlSettings
10+ public class PlantUmlOptions
911{
10- public DocfxPlantUmlSettings ( ) : base ( )
11- {
12- }
12+ [ JsonProperty ( "javaPath" ) ]
13+ [ JsonPropertyName ( "javaPath" ) ]
14+ public string JavaPath { get ; set ; }
1315
14- public DocfxPlantUmlSettings ( IReadOnlyDictionary < string , string > config ) : this ( )
15- {
16- if ( config . TryGetValue ( "remoteUrl" , out var url ) )
17- RemoteUrl = url ;
18- if ( config . TryGetValue ( "outputFormat" , out var format ) )
19- OutputFormat = Enum . Parse < OutputFormat > ( format , true ) ;
20- if ( config . TryGetValue ( "javaPath" , out var path ) )
21- JavaPath = path ;
22- if ( config . TryGetValue ( "localPlantUmlPath" , out path ) )
23- LocalPlantUmlPath = path ;
24- if ( config . TryGetValue ( "localGraphvizDotPath" , out path ) )
25- LocalGraphvizDotPath = path ;
26- if ( config . TryGetValue ( "renderingMode" , out var renderMode ) )
27- RenderingMode = Enum . Parse < RenderingMode > ( renderMode , true ) ;
28- }
16+ [ JsonProperty ( "remoteUrl" ) ]
17+ [ JsonPropertyName ( "remoteUrl" ) ]
18+ public string RemoteUrl { get ; set ; }
19+
20+ [ JsonProperty ( "localPlantUmlPath" ) ]
21+ [ JsonPropertyName ( "localPlantUmlPath" ) ]
22+ public string LocalPlantUmlPath { get ; set ; }
2923
24+ [ JsonProperty ( "localGraphvizDotPath" ) ]
25+ [ JsonPropertyName ( "localGraphvizDotPath" ) ]
26+ public string LocalGraphvizDotPath { get ; set ; }
27+
28+ [ JsonProperty ( "renderingMode" ) ]
29+ [ JsonPropertyName ( "renderingMode" ) ]
30+ public RenderingMode RenderingMode { get ; set ; }
31+
32+ [ JsonProperty ( "delimitor" ) ]
33+ [ JsonPropertyName ( "delimitor" ) ]
34+ public string Delimitor { get ; set ; }
35+
36+ [ JsonProperty ( "outputFormat" ) ]
37+ [ JsonPropertyName ( "outputFormat" ) ]
3038 public OutputFormat OutputFormat { get ; set ; } = OutputFormat . Svg ;
3139}
3240
3341internal class PlantUmlExtension : IMarkdownExtension
3442{
3543 private readonly MarkdownContext _context ;
36- private readonly DocfxPlantUmlSettings _settings ;
44+ private readonly PlantUmlOptions _settings ;
3745
38- public PlantUmlExtension ( MarkdownContext context )
46+ public PlantUmlExtension ( MarkdownContext context , PlantUmlOptions settings )
3947 {
4048 _context = context ;
41- _settings = new ( ) ;
42-
43- if ( _context . GetExtensionConfiguration ( "PlantUml" ) is Dictionary < string , string > config )
44- _settings = new DocfxPlantUmlSettings ( config ) ;
49+ _settings = settings ?? new ( ) ;
4550 }
4651
4752 public void Setup ( MarkdownPipelineBuilder pipeline )
@@ -52,7 +57,7 @@ public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer)
5257 {
5358 if ( renderer is HtmlRenderer { ObjectRenderers : not null } htmlRenderer )
5459 {
55- var customRenderer = new CustomCodeBlockRenderer ( _context , _settings ) ;
60+ var customRenderer = new PlantUmlCodeBlockRenderer ( _context , _settings ) ;
5661 var renderers = htmlRenderer . ObjectRenderers ;
5762
5863 if ( renderers . Contains < CodeBlockRenderer > ( ) )
0 commit comments