Skip to content

Commit

Permalink
添加对Mermaid,nomnoml;Math的渲染支持
Browse files Browse the repository at this point in the history
  • Loading branch information
niltor committed Apr 1, 2024
1 parent dc510df commit a1704fb
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 202 deletions.
8 changes: 0 additions & 8 deletions Content/Markdown支持示例.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,3 @@ $$
\label{eq:sample}
\end{equation}
$$
.
<div class="math">
\[
\begin{equation}
\int_0^\infty \frac{x^3}{e^x-1}\,dx = \frac{\pi^4}{15}
\label{eq:sample}
\end{equation}
\]</div>
25 changes: 25 additions & 0 deletions Lib/BuildSite/HtmlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public void BuildBlogs()
MarkdownPipeline pipeline = new MarkdownPipelineBuilder()
.UseAlertBlocks()
.UseFigures()
.UseCitations()
.UseFigures()
.UseEmphasisExtras()
.UseMathematics()
.UseMediaLinks()
.UseListExtras()
Expand Down Expand Up @@ -247,9 +250,31 @@ private static string GetTitleFromMarkdown(string content)
}
private string AddHtmlTags(string content, string title = "", string toc = "")
{
string extensionHead = "";
if (content.Contains("<div class=\"mermaid\">"))
{
extensionHead += "<script src=\"https://cdn.jsdelivr.net/npm/mermaid@10.9.0/dist/mermaid.min.js\"></script>" + Environment.NewLine;
}
if (content.Contains("<div class=\"math\">"))
{
extensionHead += """
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3.0.1/es5/tex-mml-chtml.js"></script>
""";
}
if (content.Contains("<div class=\"nomnoml\">"))
{
extensionHead += """
<script src="//unpkg.com/graphre/dist/graphre.js"></script>
<script src="//unpkg.com/nomnoml/dist/nomnoml.js"></script>
""";
}

var tplContent = TemplateHelper.GetTplContent("blog.html");
tplContent = tplContent.Replace("@{Title}", title)
.Replace("@{BaseUrl}", BaseUrl)
.Replace("@{ExtensionHead}", extensionHead)
.Replace("@{toc}", toc)
.Replace("@{content}", content);
return tplContent;
Expand Down
1 change: 1 addition & 0 deletions Lib/BuildSite/template/blog.html.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<link rel="icon" type="image/png" href="@{BaseUrl}favicon.png" />
<script src="@{BaseUrl}js/markdown.js"></script>
<title>@{Title}</title>
@{ExtensionHead}
</head>
<body class="container mx-auto px-4 sm:px-6 lg:px-8 dark:bg-neutral-900 pb-4">
<div class="flex mt-2">
Expand Down
Loading

0 comments on commit a1704fb

Please sign in to comment.