1 Talk about purpose
前几天上线了一个在线 Icon 转换工具,为了让大家使用放心,改了点代码,在转换下载 Icon 图标后立即删除临时文件,并在工具下面贴上了工具的开发步骤和代码,大家看这样改是否合适,见Issue 1。
这篇不讲代码修改过程(因为工具和网站博文已经同步更新),本文讲讲在工具下方展示 Markdown 文件的实现方式,先看效果:

** Why add this function? **
My idea is that in addition to providing the tool for free use, we can also let everyone understand how this tool was developed. This should be more convenient:
- 默认是不显示的,点击
如何开发的?的按钮加载开发文章说明。 - 评论功能目前没有(不排除后面加上),需要点击
我要建议(吐槽)按钮跳转到Dotnet9网站同篇博文留言。 - 旁边有个按钮
我要浏览源码可以点击浏览工具源码。
Let's talk about how to display the Markdown file in Blazor, first explaining the functions completed so far:
- Just display the Markdown file as html.
- Highlight is not currently added.
2 Development steps
- introduced with the
<PackageReference Include="BlazorMarkdown" Version="1.0.0" />
<PackageReference Include="HtmlSanitizer" Version="7.1.488" />
- injection assembly
Program.cs
builder.Services.AddScoped<IHtmlSanitizer, HtmlSanitizer>(x =>
{
// Configure sanitizer rules as needed here.
// For now, just use default rules + allow class attributes
var sanitizer = new HtmlSanitizer();
sanitizer.AllowedAttributes.Add("class");
return sanitizer;
});
- reference namespace
_Imports.razor
@using BlazorMarkdown
- use
Prepare the Markdown file, for example, if I put it under wwwroot:

在IcoTool.razor中就可以直接使用了:
<Markdown FilePath="wwwroot/2022/02/2022-02-22_02.md" />
summary
It's over, it's as simple as that. See the beginning of the article for the effect. I won't be wordy today.
Forget that there are multimedia files such as pictures in markdown, remember to add these styles to achieve adaptability:
<style>
h3 {
border-bottom: 1px solid #eee;
margin-top: 50px;
padding-bottom: 10px;
}
pre {
background: #1E1E1E;
color: #eee;
overflow-x: auto;
padding: 0.5em !important;
white-space: pre;
word-break: normal;
word-wrap: normal;
}
img, video, source { max-width: 100% }
pre > code { white-space: pre; }
</style>