Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions ICSharpCode.ILSpyX/MermaidDiagrammer/Generator.Run.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;

using ICSharpCode.Decompiler.Documentation;
using ICSharpCode.ILSpyX.MermaidDiagrammer.Extensions;
Expand All @@ -31,6 +33,18 @@ namespace ICSharpCode.ILSpyX.MermaidDiagrammer
{
partial class GenerateHtmlDiagrammer
{
internal static string RenderTemplate(string template, ClassDiagrammer model, string modelJson)
{
return Regex.Replace(template, @"\{\{(?:SourceAssemblyName|SourceAssemblyVersion|BuilderVersion|RepoUrl|Model)\}\}", match => match.Value switch {
"{{SourceAssemblyName}}" => WebUtility.HtmlEncode(model.SourceAssemblyName),
"{{SourceAssemblyVersion}}" => WebUtility.HtmlEncode(model.SourceAssemblyVersion),
"{{BuilderVersion}}" => DecompilerVersionInfo.FullVersionWithCommitHash,
"{{RepoUrl}}" => RepoUrl,
"{{Model}}" => modelJson,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain why these other fields don't also need to be encoded.

_ => match.Value
});
}

public void Run()
{
var assemblyPath = Assembly;
Expand Down Expand Up @@ -116,12 +130,7 @@ private void GenerateOutput(string assemblyPath, ClassDiagrammer model)
{
var htmlTemplate = EmbeddedResource.ReadText("template.html");

var html = htmlTemplate
.Replace("{{SourceAssemblyName}}", model.SourceAssemblyName)
.Replace("{{SourceAssemblyVersion}}", model.SourceAssemblyVersion)
.Replace("{{BuilderVersion}}", DecompilerVersionInfo.FullVersionWithCommitHash)
.Replace("{{RepoUrl}}", RepoUrl)
.Replace("{{Model}}", modelJson);
var html = RenderTemplate(htmlTemplate, model, modelJson);

File.WriteAllText(Path.Combine(outputFolder, "index.html"), html);

Expand All @@ -148,4 +157,4 @@ private void GenerateOutput(string assemblyPath, ClassDiagrammer model)
internal partial class DiagrammerJsonContext : JsonSerializerContext
{
}
}
}
Loading