From 0d56f79e0817e99029aabb43f473685da7e202f6 Mon Sep 17 00:00:00 2001 From: Yufei Huang Date: Wed, 3 Jan 2024 15:58:10 +0800 Subject: [PATCH] refactor: strongly type plantuml config --- .../MarkdownContext.cs | 16 +-- .../MarkdownExtensions.cs | 16 +-- .../PlantUml/PlantUmlCodeBlockRenderer.cs | 22 +++- .../PlantUml/PlantUmlExtension.cs | 57 +++++----- .../QuoteSectionNoteExtension.cs | 6 +- .../MarkdigMarkdownService.cs | 5 +- .../MarkdownServiceParameters.cs | 15 +-- .../PlantUmlTest.cs | 11 +- .../QuoteSectionNoteTest.cs | 2 +- .../TestUtility.cs | 10 +- test/docfx.Tests/Api.verified.cs | 106 ++++++++++-------- test/docfx.Tests/JsonConverterTest.cs | 45 -------- 12 files changed, 133 insertions(+), 178 deletions(-) rename src/{Docfx.Plugins => Docfx.MarkdigEngine}/MarkdownServiceParameters.cs (80%) diff --git a/src/Docfx.MarkdigEngine.Extensions/MarkdownContext.cs b/src/Docfx.MarkdigEngine.Extensions/MarkdownContext.cs index 4f5bac9fa8f..4b90214331c 100644 --- a/src/Docfx.MarkdigEngine.Extensions/MarkdownContext.cs +++ b/src/Docfx.MarkdigEngine.Extensions/MarkdownContext.cs @@ -36,13 +36,6 @@ public class MarkdownContext /// Image url bound to the path public delegate string GetImageLinkDelegate(string path, MarkdownObject origin, string altText); - /// - /// Allows configuration of extensions - /// - /// Name of the extension being configured - /// Object representing the configuration for the extension - public delegate object GetExtensionConfigurationDelegate(string extension); - /// /// Reads a file as text. /// @@ -58,11 +51,6 @@ public class MarkdownContext /// public GetImageLinkDelegate GetImageLink { get; } - /// - /// Get the configuration for a given extension - /// - public GetExtensionConfigurationDelegate GetExtensionConfiguration { get; } - /// /// Log info /// @@ -98,14 +86,12 @@ public MarkdownContext( LogActionDelegate logError = null, ReadFileDelegate readFile = null, GetLinkDelegate getLink = null, - GetImageLinkDelegate getImageLink = null, - GetExtensionConfigurationDelegate getConfig = null) + GetImageLinkDelegate getImageLink = null) { _getToken = getToken ?? (_ => null); ReadFile = readFile ?? ((a, b) => (a, a)); GetLink = getLink ?? ((a, b) => a); GetImageLink = getImageLink ?? ((a, b, c) => a); - GetExtensionConfiguration = getConfig ?? (_ => null); LogInfo = logInfo ?? ((a, b, c, d) => { }); LogSuggestion = logSuggestion ?? ((a, b, c, d) => { }); LogWarning = logWarning ?? ((a, b, c, d) => { }); diff --git a/src/Docfx.MarkdigEngine.Extensions/MarkdownExtensions.cs b/src/Docfx.MarkdigEngine.Extensions/MarkdownExtensions.cs index 8568f4655a9..38ef957323f 100644 --- a/src/Docfx.MarkdigEngine.Extensions/MarkdownExtensions.cs +++ b/src/Docfx.MarkdigEngine.Extensions/MarkdownExtensions.cs @@ -11,7 +11,9 @@ namespace Docfx.MarkdigEngine.Extensions; public static class MarkdownExtensions { - public static MarkdownPipelineBuilder UseDocfxExtensions(this MarkdownPipelineBuilder pipeline, MarkdownContext context) + public static MarkdownPipelineBuilder UseDocfxExtensions( + this MarkdownPipelineBuilder pipeline, MarkdownContext context, + Dictionary notes = null, PlantUmlOptions plantUml = null) { return pipeline .UseMathematics() @@ -24,7 +26,7 @@ public static MarkdownPipelineBuilder UseDocfxExtensions(this MarkdownPipelineBu .UseIncludeFile(context) .UseCodeSnippet(context) .UseDFMCodeInfoPrefix() - .UseQuoteSectionNote(context) + .UseQuoteSectionNote(context, notes) .UseXref() .UseEmojiAndSmiley(false) .UseTabGroup(context) @@ -35,7 +37,7 @@ public static MarkdownPipelineBuilder UseDocfxExtensions(this MarkdownPipelineBu .UseTripleColon(context) .UseNoloc() .UseResolveLink(context) - .UsePlantUml(context) + .UsePlantUml(context, plantUml) .RemoveUnusedExtensions(); } @@ -100,9 +102,9 @@ public static MarkdownPipelineBuilder UseDFMCodeInfoPrefix(this MarkdownPipeline return pipeline; } - public static MarkdownPipelineBuilder UseQuoteSectionNote(this MarkdownPipelineBuilder pipeline, MarkdownContext context) + public static MarkdownPipelineBuilder UseQuoteSectionNote(this MarkdownPipelineBuilder pipeline, MarkdownContext context, Dictionary notes = null) { - pipeline.Extensions.AddIfNotAlready(new QuoteSectionNoteExtension(context)); + pipeline.Extensions.AddIfNotAlready(new QuoteSectionNoteExtension(context, notes)); return pipeline; } @@ -112,9 +114,9 @@ public static MarkdownPipelineBuilder UseLineNumber(this MarkdownPipelineBuilder return pipeline; } - public static MarkdownPipelineBuilder UsePlantUml(this MarkdownPipelineBuilder pipeline, MarkdownContext context) + public static MarkdownPipelineBuilder UsePlantUml(this MarkdownPipelineBuilder pipeline, MarkdownContext context, PlantUmlOptions options = null) { - pipeline.Extensions.AddIfNotAlready(new PlantUmlExtension(context)); + pipeline.Extensions.AddIfNotAlready(new PlantUmlExtension(context, options)); return pipeline; } diff --git a/src/Docfx.MarkdigEngine.Extensions/PlantUml/PlantUmlCodeBlockRenderer.cs b/src/Docfx.MarkdigEngine.Extensions/PlantUml/PlantUmlCodeBlockRenderer.cs index 9adc78f3e95..0df8d1af379 100644 --- a/src/Docfx.MarkdigEngine.Extensions/PlantUml/PlantUmlCodeBlockRenderer.cs +++ b/src/Docfx.MarkdigEngine.Extensions/PlantUml/PlantUmlCodeBlockRenderer.cs @@ -11,10 +11,11 @@ namespace Docfx.MarkdigEngine.Extensions; /// An HTML renderer for a and . /// /// -public class CustomCodeBlockRenderer : CodeBlockRenderer +class PlantUmlCodeBlockRenderer : CodeBlockRenderer { private readonly MarkdownContext _context; - private readonly DocfxPlantUmlSettings _settings; + private readonly PlantUmlSettings _settings; + private readonly OutputFormat _outputFormat; private readonly RendererFactory rendererFactory; /// @@ -22,10 +23,19 @@ public class CustomCodeBlockRenderer : CodeBlockRenderer /// /// /// - public CustomCodeBlockRenderer(MarkdownContext context, DocfxPlantUmlSettings settings) + public PlantUmlCodeBlockRenderer(MarkdownContext context, PlantUmlOptions settings) { _context = context; - _settings = settings; + _settings = new() + { + Delimitor = settings.Delimitor, + RenderingMode = settings.RenderingMode, + RemoteUrl = settings.RemoteUrl, + JavaPath = settings.JavaPath, + LocalGraphvizDotPath = settings.LocalGraphvizDotPath, + LocalPlantUmlPath = settings.LocalPlantUmlPath, + }; + _outputFormat = settings.OutputFormat; rendererFactory = new RendererFactory(); } @@ -43,10 +53,10 @@ protected override void Write(HtmlRenderer renderer, CodeBlock obj) try { - byte[] output = plantUmlRenderer.Render(plantUmlCode, _settings.OutputFormat); + byte[] output = plantUmlRenderer.Render(plantUmlCode, _outputFormat); renderer.EnsureLine(); - renderer.Write(FormatOutput(_settings.OutputFormat, output)); + renderer.Write(FormatOutput(_outputFormat, output)); renderer.EnsureLine(); } catch (RenderingException ex) diff --git a/src/Docfx.MarkdigEngine.Extensions/PlantUml/PlantUmlExtension.cs b/src/Docfx.MarkdigEngine.Extensions/PlantUml/PlantUmlExtension.cs index 06820c87db0..3cf0d9d8f06 100644 --- a/src/Docfx.MarkdigEngine.Extensions/PlantUml/PlantUmlExtension.cs +++ b/src/Docfx.MarkdigEngine.Extensions/PlantUml/PlantUmlExtension.cs @@ -1,47 +1,52 @@ +using System.Text.Json.Serialization; using Markdig; using Markdig.Renderers; using Markdig.Renderers.Html; +using Newtonsoft.Json; using PlantUml.Net; namespace Docfx.MarkdigEngine.Extensions; -public class DocfxPlantUmlSettings : PlantUmlSettings +public class PlantUmlOptions { - public DocfxPlantUmlSettings() : base() - { - } + [JsonProperty("javaPath")] + [JsonPropertyName("javaPath")] + public string JavaPath { get; set; } - public DocfxPlantUmlSettings(IReadOnlyDictionary config) : this() - { - if (config.TryGetValue("remoteUrl", out var url)) - RemoteUrl = url; - if (config.TryGetValue("outputFormat", out var format)) - OutputFormat = Enum.Parse(format, true); - if (config.TryGetValue("javaPath", out var path)) - JavaPath = path; - if (config.TryGetValue("localPlantUmlPath", out path)) - LocalPlantUmlPath = path; - if (config.TryGetValue("localGraphvizDotPath", out path)) - LocalGraphvizDotPath = path; - if (config.TryGetValue("renderingMode", out var renderMode)) - RenderingMode = Enum.Parse(renderMode, true); - } + [JsonProperty("remoteUrl")] + [JsonPropertyName("remoteUrl")] + public string RemoteUrl { get; set; } + + [JsonProperty("localPlantUmlPath")] + [JsonPropertyName("localPlantUmlPath")] + public string LocalPlantUmlPath { get; set; } + [JsonProperty("localGraphvizDotPath")] + [JsonPropertyName("localGraphvizDotPath")] + public string LocalGraphvizDotPath { get; set; } + + [JsonProperty("renderingMode")] + [JsonPropertyName("renderingMode")] + public RenderingMode RenderingMode { get; set; } + + [JsonProperty("delimitor")] + [JsonPropertyName("delimitor")] + public string Delimitor { get; set; } + + [JsonProperty("outputFormat")] + [JsonPropertyName("outputFormat")] public OutputFormat OutputFormat { get; set; } = OutputFormat.Svg; } internal class PlantUmlExtension : IMarkdownExtension { private readonly MarkdownContext _context; - private readonly DocfxPlantUmlSettings _settings; + private readonly PlantUmlOptions _settings; - public PlantUmlExtension(MarkdownContext context) + public PlantUmlExtension(MarkdownContext context, PlantUmlOptions settings) { _context = context; - _settings = new(); - - if (_context.GetExtensionConfiguration("PlantUml") is Dictionary config) - _settings = new DocfxPlantUmlSettings(config); + _settings = settings ?? new(); } public void Setup(MarkdownPipelineBuilder pipeline) @@ -52,7 +57,7 @@ public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer) { if (renderer is HtmlRenderer { ObjectRenderers: not null } htmlRenderer) { - var customRenderer = new CustomCodeBlockRenderer(_context, _settings); + var customRenderer = new PlantUmlCodeBlockRenderer(_context, _settings); var renderers = htmlRenderer.ObjectRenderers; if (renderers.Contains()) diff --git a/src/Docfx.MarkdigEngine.Extensions/QuoteSectionNote/QuoteSectionNoteExtension.cs b/src/Docfx.MarkdigEngine.Extensions/QuoteSectionNote/QuoteSectionNoteExtension.cs index f478b1aa24c..1003fa608af 100644 --- a/src/Docfx.MarkdigEngine.Extensions/QuoteSectionNote/QuoteSectionNoteExtension.cs +++ b/src/Docfx.MarkdigEngine.Extensions/QuoteSectionNote/QuoteSectionNoteExtension.cs @@ -22,13 +22,13 @@ public class QuoteSectionNoteExtension : IMarkdownExtension ["CAUTION"] = "CAUTION", }; - public QuoteSectionNoteExtension(MarkdownContext context) + public QuoteSectionNoteExtension(MarkdownContext context, Dictionary notes) { _context = context; - if (_context.GetExtensionConfiguration("Alerts") is Dictionary config) + if (notes != null) { - foreach (var (key, value) in config) + foreach (var (key, value) in notes) _notes[key] = value; } } diff --git a/src/Docfx.MarkdigEngine/MarkdigMarkdownService.cs b/src/Docfx.MarkdigEngine/MarkdigMarkdownService.cs index be1150af0ed..d51e5d06067 100644 --- a/src/Docfx.MarkdigEngine/MarkdigMarkdownService.cs +++ b/src/Docfx.MarkdigEngine/MarkdigMarkdownService.cs @@ -34,8 +34,7 @@ public MarkdigMarkdownService( (code, message, origin, line) => Logger.LogError(message, null, InclusionContext.File.ToString(), line?.ToString(), code), ReadFile, GetLink, - GetImageLink, - GetExtensionConfiguration); + GetImageLink); } public MarkupResult Markup(string content, string filePath) @@ -187,8 +186,6 @@ private static string GetLink(string path, MarkdownObject origin) return path; } - private object GetExtensionConfiguration(string extension) => _parameters.GetExtensionConfiguration(extension); - private static string GetImageLink(string href, MarkdownObject origin, string altText) => GetLink(href, origin); private static void ReportDependency(RelativePath filePathToDocset, string parentFileDirectoryToDocset) diff --git a/src/Docfx.Plugins/MarkdownServiceParameters.cs b/src/Docfx.MarkdigEngine/MarkdownServiceParameters.cs similarity index 80% rename from src/Docfx.Plugins/MarkdownServiceParameters.cs rename to src/Docfx.MarkdigEngine/MarkdownServiceParameters.cs index 421f4f7f9b7..11a4f36f862 100644 --- a/src/Docfx.Plugins/MarkdownServiceParameters.cs +++ b/src/Docfx.MarkdigEngine/MarkdownServiceParameters.cs @@ -3,6 +3,7 @@ using System.Collections.Immutable; using System.Text.Json.Serialization; +using Docfx.MarkdigEngine.Extensions; using Newtonsoft.Json; namespace Docfx.Plugins; @@ -41,7 +42,7 @@ public class MarkdownServiceProperties /// [JsonProperty("plantUml")] [JsonPropertyName("plantUml")] - public Dictionary PlantUml { get; set; } + public PlantUmlOptions PlantUml { get; set; } } public class MarkdownServiceParameters @@ -50,16 +51,4 @@ public class MarkdownServiceParameters public string TemplateDir { get; set; } public MarkdownServiceProperties Extensions { get; set; } = new(); public ImmutableDictionary Tokens { get; set; } = ImmutableDictionary.Empty; - - public object GetExtensionConfiguration(string extension) - { - if (!string.IsNullOrEmpty(extension) && Extensions != null) - { - var property = typeof(MarkdownServiceProperties).GetProperty(extension); - if (property != null) - return property.GetValue(Extensions); - } - - return null; - } } diff --git a/test/Docfx.MarkdigEngine.Extensions.Tests/PlantUmlTest.cs b/test/Docfx.MarkdigEngine.Extensions.Tests/PlantUmlTest.cs index 5fb838631fd..16e1ee05d11 100644 --- a/test/Docfx.MarkdigEngine.Extensions.Tests/PlantUmlTest.cs +++ b/test/Docfx.MarkdigEngine.Extensions.Tests/PlantUmlTest.cs @@ -22,11 +22,10 @@ public void TestRenderSvg_SequenceDiagram()
BobBobAliceAlicehello
"""; - TestUtility.VerifyMarkup(source, expected, extensionConfiguration: - new Dictionary - { - { "outputFormat", "svg"}, - { "remoteUrl", "https://www.plantuml.com/plantuml" } - }); + TestUtility.VerifyMarkup(source, expected, plantUml: new() + { + OutputFormat = PlantUml.Net.OutputFormat.Svg, + RemoteUrl = "https://www.plantuml.com/plantuml", + }); } } diff --git a/test/Docfx.MarkdigEngine.Extensions.Tests/QuoteSectionNoteTest.cs b/test/Docfx.MarkdigEngine.Extensions.Tests/QuoteSectionNoteTest.cs index abfd1d8f6e5..d4fca425810 100644 --- a/test/Docfx.MarkdigEngine.Extensions.Tests/QuoteSectionNoteTest.cs +++ b/test/Docfx.MarkdigEngine.Extensions.Tests/QuoteSectionNoteTest.cs @@ -480,7 +480,7 @@ public void QuoteSectionNoteTest_ExtensionConfiguration()

This is a custom REVIEW section

"; - TestUtility.VerifyMarkup(source, expected, extensionConfiguration: + TestUtility.VerifyMarkup(source, expected, notes: new Dictionary { { "TODO", "alert alert-secondary" }, diff --git a/test/Docfx.MarkdigEngine.Extensions.Tests/TestUtility.cs b/test/Docfx.MarkdigEngine.Extensions.Tests/TestUtility.cs index b6bc6dca515..d0129598fd5 100644 --- a/test/Docfx.MarkdigEngine.Extensions.Tests/TestUtility.cs +++ b/test/Docfx.MarkdigEngine.Extensions.Tests/TestUtility.cs @@ -4,7 +4,6 @@ using Docfx.MarkdigEngine.Extensions; using Markdig; using Markdig.Syntax; -using Newtonsoft.Json.Linq; using Xunit; namespace Docfx.MarkdigEngine.Tests; @@ -20,9 +19,9 @@ public static void VerifyMarkup( string filePath = "test.md", Dictionary tokens = null, Dictionary files = null, - Action verifyAST = null, IEnumerable optionalExtensions = null, - object extensionConfiguration = null) + Dictionary notes = null, + PlantUmlOptions plantUml = null) { errors ??= Array.Empty(); tokens ??= new Dictionary(); @@ -38,11 +37,10 @@ public static void VerifyMarkup( logSuggestion: Log("suggestion"), logWarning: Log("warning"), logError: Log("error"), - readFile: ReadFile, - getConfig: _ => extensionConfiguration); + readFile: ReadFile); var pipelineBuilder = new MarkdownPipelineBuilder() - .UseDocfxExtensions(markdownContext) + .UseDocfxExtensions(markdownContext, notes, plantUml) .UseYamlFrontMatter() .UseOptionalExtensions(optionalExtensions); diff --git a/test/docfx.Tests/Api.verified.cs b/test/docfx.Tests/Api.verified.cs index 6a28ce300d9..c79fa61d103 100644 --- a/test/docfx.Tests/Api.verified.cs +++ b/test/docfx.Tests/Api.verified.cs @@ -3256,6 +3256,36 @@ public Docfx.Plugins.MarkupResult Render(Markdig.Syntax.MarkdownDocument documen public Docfx.Plugins.MarkupResult Render(Markdig.Syntax.MarkdownDocument document, bool isInline) { } } } +namespace Docfx.Plugins +{ + public class MarkdownServiceParameters + { + public MarkdownServiceParameters() { } + public string BasePath { get; set; } + public Docfx.Plugins.MarkdownServiceProperties Extensions { get; set; } + public string TemplateDir { get; set; } + public System.Collections.Immutable.ImmutableDictionary Tokens { get; set; } + } + public class MarkdownServiceProperties + { + public MarkdownServiceProperties() { } + [Newtonsoft.Json.JsonProperty("alerts")] + [System.Text.Json.Serialization.JsonPropertyName("alerts")] + public System.Collections.Generic.Dictionary Alerts { get; set; } + [Newtonsoft.Json.JsonProperty("enableSourceInfo")] + [System.Text.Json.Serialization.JsonPropertyName("enableSourceInfo")] + public bool EnableSourceInfo { get; set; } + [Newtonsoft.Json.JsonProperty("fallbackFolders")] + [System.Text.Json.Serialization.JsonPropertyName("fallbackFolders")] + public string[] FallbackFolders { get; set; } + [Newtonsoft.Json.JsonProperty("markdigExtensions")] + [System.Text.Json.Serialization.JsonPropertyName("markdigExtensions")] + public string[] MarkdigExtensions { get; set; } + [Newtonsoft.Json.JsonProperty("plantUml")] + [System.Text.Json.Serialization.JsonPropertyName("plantUml")] + public Docfx.MarkdigEngine.Extensions.PlantUmlOptions PlantUml { get; set; } + } +} namespace Docfx.MarkdigEngine.Extensions { public class ActiveAndVisibleRewriter : Docfx.MarkdigEngine.Extensions.IMarkdownObjectRewriter @@ -3351,17 +3381,6 @@ public class CodeSnippetParser : Markdig.Parsers.BlockParser public CodeSnippetParser() { } public override Markdig.Parsers.BlockState TryOpen(Markdig.Parsers.BlockProcessor processor) { } } - public class CustomCodeBlockRenderer : Markdig.Renderers.Html.CodeBlockRenderer - { - public CustomCodeBlockRenderer(Docfx.MarkdigEngine.Extensions.MarkdownContext context, Docfx.MarkdigEngine.Extensions.DocfxPlantUmlSettings settings) { } - protected override void Write(Markdig.Renderers.HtmlRenderer renderer, Markdig.Syntax.CodeBlock obj) { } - } - public class DocfxPlantUmlSettings : PlantUml.Net.PlantUmlSettings - { - public DocfxPlantUmlSettings() { } - public DocfxPlantUmlSettings(System.Collections.Generic.IReadOnlyDictionary config) { } - public PlantUml.Net.OutputFormat OutputFormat { get; set; } - } public static class ExtensionsHelper { public static readonly System.Text.RegularExpressions.Regex HtmlEscapeWithEncode; @@ -3543,8 +3562,7 @@ public void Setup(Markdig.MarkdownPipeline pipeline, Markdig.Renderers.IMarkdown } public class MarkdownContext { - public MarkdownContext(System.Func getToken = null, Docfx.MarkdigEngine.Extensions.MarkdownContext.LogActionDelegate logInfo = null, Docfx.MarkdigEngine.Extensions.MarkdownContext.LogActionDelegate logSuggestion = null, Docfx.MarkdigEngine.Extensions.MarkdownContext.LogActionDelegate logWarning = null, Docfx.MarkdigEngine.Extensions.MarkdownContext.LogActionDelegate logError = null, Docfx.MarkdigEngine.Extensions.MarkdownContext.ReadFileDelegate readFile = null, Docfx.MarkdigEngine.Extensions.MarkdownContext.GetLinkDelegate getLink = null, Docfx.MarkdigEngine.Extensions.MarkdownContext.GetImageLinkDelegate getImageLink = null, Docfx.MarkdigEngine.Extensions.MarkdownContext.GetExtensionConfigurationDelegate getConfig = null) { } - public Docfx.MarkdigEngine.Extensions.MarkdownContext.GetExtensionConfigurationDelegate GetExtensionConfiguration { get; } + public MarkdownContext(System.Func getToken = null, Docfx.MarkdigEngine.Extensions.MarkdownContext.LogActionDelegate logInfo = null, Docfx.MarkdigEngine.Extensions.MarkdownContext.LogActionDelegate logSuggestion = null, Docfx.MarkdigEngine.Extensions.MarkdownContext.LogActionDelegate logWarning = null, Docfx.MarkdigEngine.Extensions.MarkdownContext.LogActionDelegate logError = null, Docfx.MarkdigEngine.Extensions.MarkdownContext.ReadFileDelegate readFile = null, Docfx.MarkdigEngine.Extensions.MarkdownContext.GetLinkDelegate getLink = null, Docfx.MarkdigEngine.Extensions.MarkdownContext.GetImageLinkDelegate getImageLink = null) { } public Docfx.MarkdigEngine.Extensions.MarkdownContext.GetImageLinkDelegate GetImageLink { get; } public Docfx.MarkdigEngine.Extensions.MarkdownContext.GetLinkDelegate GetLink { get; } public Docfx.MarkdigEngine.Extensions.MarkdownContext.LogActionDelegate LogError { get; } @@ -3553,7 +3571,6 @@ public MarkdownContext(System.Func getToken = null, Docfx.Markdi public Docfx.MarkdigEngine.Extensions.MarkdownContext.LogActionDelegate LogWarning { get; } public Docfx.MarkdigEngine.Extensions.MarkdownContext.ReadFileDelegate ReadFile { get; } public string GetToken(string key) { } - public delegate object GetExtensionConfigurationDelegate(string extension); public delegate string GetImageLinkDelegate(string path, Markdig.Syntax.MarkdownObject origin, string altText); public delegate string GetLinkDelegate(string path, Markdig.Syntax.MarkdownObject origin); public delegate void LogActionDelegate(string code, string message, Markdig.Syntax.MarkdownObject origin, int? line = default); @@ -3576,7 +3593,7 @@ public static class MarkdownExtensions { public static Markdig.MarkdownPipelineBuilder UseCodeSnippet(this Markdig.MarkdownPipelineBuilder pipeline, Docfx.MarkdigEngine.Extensions.MarkdownContext context) { } public static Markdig.MarkdownPipelineBuilder UseDFMCodeInfoPrefix(this Markdig.MarkdownPipelineBuilder pipeline) { } - public static Markdig.MarkdownPipelineBuilder UseDocfxExtensions(this Markdig.MarkdownPipelineBuilder pipeline, Docfx.MarkdigEngine.Extensions.MarkdownContext context) { } + public static Markdig.MarkdownPipelineBuilder UseDocfxExtensions(this Markdig.MarkdownPipelineBuilder pipeline, Docfx.MarkdigEngine.Extensions.MarkdownContext context, System.Collections.Generic.Dictionary notes = null, Docfx.MarkdigEngine.Extensions.PlantUmlOptions plantUml = null) { } public static Markdig.MarkdownPipelineBuilder UseHeadingIdRewriter(this Markdig.MarkdownPipelineBuilder pipeline) { } public static Markdig.MarkdownPipelineBuilder UseIncludeFile(this Markdig.MarkdownPipelineBuilder pipeline, Docfx.MarkdigEngine.Extensions.MarkdownContext context) { } public static Markdig.MarkdownPipelineBuilder UseInlineOnly(this Markdig.MarkdownPipelineBuilder pipeline) { } @@ -3586,8 +3603,8 @@ public static Markdig.MarkdownPipelineBuilder UseMonikerRange(this Markdig.Markd public static Markdig.MarkdownPipelineBuilder UseNestedColumn(this Markdig.MarkdownPipelineBuilder pipeline, Docfx.MarkdigEngine.Extensions.MarkdownContext context) { } public static Markdig.MarkdownPipelineBuilder UseNoloc(this Markdig.MarkdownPipelineBuilder pipeline) { } public static Markdig.MarkdownPipelineBuilder UseOptionalExtensions(this Markdig.MarkdownPipelineBuilder pipeline, System.Collections.Generic.IEnumerable optionalExtensions) { } - public static Markdig.MarkdownPipelineBuilder UsePlantUml(this Markdig.MarkdownPipelineBuilder pipeline, Docfx.MarkdigEngine.Extensions.MarkdownContext context) { } - public static Markdig.MarkdownPipelineBuilder UseQuoteSectionNote(this Markdig.MarkdownPipelineBuilder pipeline, Docfx.MarkdigEngine.Extensions.MarkdownContext context) { } + public static Markdig.MarkdownPipelineBuilder UsePlantUml(this Markdig.MarkdownPipelineBuilder pipeline, Docfx.MarkdigEngine.Extensions.MarkdownContext context, Docfx.MarkdigEngine.Extensions.PlantUmlOptions options = null) { } + public static Markdig.MarkdownPipelineBuilder UseQuoteSectionNote(this Markdig.MarkdownPipelineBuilder pipeline, Docfx.MarkdigEngine.Extensions.MarkdownContext context, System.Collections.Generic.Dictionary notes = null) { } public static Markdig.MarkdownPipelineBuilder UseResolveLink(this Markdig.MarkdownPipelineBuilder pipeline, Docfx.MarkdigEngine.Extensions.MarkdownContext context) { } public static Markdig.MarkdownPipelineBuilder UseRow(this Markdig.MarkdownPipelineBuilder pipeline, Docfx.MarkdigEngine.Extensions.MarkdownContext context) { } public static Markdig.MarkdownPipelineBuilder UseTabGroup(this Markdig.MarkdownPipelineBuilder pipeline, Docfx.MarkdigEngine.Extensions.MarkdownContext context) { } @@ -3663,6 +3680,31 @@ public class NolocRender : Markdig.Renderers.Html.HtmlObjectRenderer notes) { } } public class QuoteSectionNoteParser : Markdig.Parsers.BlockParser { @@ -4151,34 +4193,6 @@ public ManifestItem() { } [System.Text.Json.Serialization.JsonPropertyName("version")] public string Version { get; set; } } - public class MarkdownServiceParameters - { - public MarkdownServiceParameters() { } - public string BasePath { get; set; } - public Docfx.Plugins.MarkdownServiceProperties Extensions { get; set; } - public string TemplateDir { get; set; } - public System.Collections.Immutable.ImmutableDictionary Tokens { get; set; } - public object GetExtensionConfiguration(string extension) { } - } - public class MarkdownServiceProperties - { - public MarkdownServiceProperties() { } - [Newtonsoft.Json.JsonProperty("alerts")] - [System.Text.Json.Serialization.JsonPropertyName("alerts")] - public System.Collections.Generic.Dictionary Alerts { get; set; } - [Newtonsoft.Json.JsonProperty("enableSourceInfo")] - [System.Text.Json.Serialization.JsonPropertyName("enableSourceInfo")] - public bool EnableSourceInfo { get; set; } - [Newtonsoft.Json.JsonProperty("fallbackFolders")] - [System.Text.Json.Serialization.JsonPropertyName("fallbackFolders")] - public string[] FallbackFolders { get; set; } - [Newtonsoft.Json.JsonProperty("markdigExtensions")] - [System.Text.Json.Serialization.JsonPropertyName("markdigExtensions")] - public string[] MarkdigExtensions { get; set; } - [Newtonsoft.Json.JsonProperty("plantUml")] - [System.Text.Json.Serialization.JsonPropertyName("plantUml")] - public System.Collections.Generic.Dictionary PlantUml { get; set; } - } public class MarkupResult { public MarkupResult() { } diff --git a/test/docfx.Tests/JsonConverterTest.cs b/test/docfx.Tests/JsonConverterTest.cs index dee39bef92f..49d264c5216 100644 --- a/test/docfx.Tests/JsonConverterTest.cs +++ b/test/docfx.Tests/JsonConverterTest.cs @@ -50,51 +50,6 @@ public void TestJObjectDictionaryToObjectDictionaryConverterSerializeAndDeserial Assert.Equal(jsonString, JsonConvert.SerializeObject(buildOptions, settings), ignoreLineEndingDifferences: true); } - [Fact] - [Trait("Related", "docfx")] - public void TestMarkdownEnginePropertiesSerializeAndDeserialize() - { - string jsonString = """ - { - "markdownEngineProperties": { - "enableSourceInfo": false, - "alerts": { - "TODO": "alert alert-secondary", - "REVIEW": "alert alert-primary" - }, - "plantUml": { - "outputFormat": "svg", - "remoteUrl": "https://www.plantuml.com/plantuml" - } - }, - "disableGitFeatures": true - } - """; - - BuildJsonConfig buildOptions = JsonConvert.DeserializeObject(jsonString); - - Assert.NotNull(buildOptions.MarkdownEngineProperties); - Assert.False(buildOptions.MarkdownEngineProperties.EnableSourceInfo); - Assert.NotNull(buildOptions.MarkdownEngineProperties.Alerts); - Assert.Equal(2, buildOptions.MarkdownEngineProperties.Alerts.Count); - Assert.NotNull(buildOptions.MarkdownEngineProperties.Alerts["TODO"]); - Assert.NotNull(buildOptions.MarkdownEngineProperties.Alerts["REVIEW"]); - Assert.NotNull(buildOptions.MarkdownEngineProperties.PlantUml); - Assert.Equal(2, buildOptions.MarkdownEngineProperties.PlantUml.Count); - Assert.NotNull(buildOptions.MarkdownEngineProperties.PlantUml["outputFormat"]); - Assert.NotNull(buildOptions.MarkdownEngineProperties.PlantUml["remoteUrl"]); - - JsonSerializerSettings settings = new() - { - NullValueHandling = NullValueHandling.Ignore, - Formatting = Formatting.Indented, - ContractResolver = new SkipEmptyOrNullContractResolver() - }; - - string json = JsonConvert.SerializeObject(buildOptions, settings); - Assert.Equal(jsonString, json, ignoreLineEndingDifferences: true); - } - [Fact] [Trait("Related", "docfx")] public void TestFileMetadataPairsConverterCouldSerializeAndDeserialize()