upload
This commit is contained in:
67
Services/MarkdownService.cs
Normal file
67
Services/MarkdownService.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using Markdig;
|
||||
|
||||
namespace SimpleWiki.Services;
|
||||
|
||||
public static class MarkdownService
|
||||
{
|
||||
private static readonly MarkdownPipeline Pipeline = new MarkdownPipelineBuilder()
|
||||
.UseAdvancedExtensions()
|
||||
.Build();
|
||||
|
||||
public static string ToHtmlDocument(string title, string markdown)
|
||||
{
|
||||
var htmlBody = Markdown.ToHtml(markdown ?? string.Empty, Pipeline);
|
||||
|
||||
return $@"<!DOCTYPE html>
|
||||
<html style='background:#1E1E2E; color:#CDD6F4;'>
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
<meta http-equiv='X-UA-Compatible' content='IE=edge' />
|
||||
<meta name='color-scheme' content='dark' />
|
||||
<style>
|
||||
html, body {{
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
min-height: 100%;
|
||||
background: #1E1E2E !important;
|
||||
background-color: #1E1E2E !important;
|
||||
color: #CDD6F4 !important;
|
||||
font-family: 'Segoe UI', sans-serif;
|
||||
}}
|
||||
body {{
|
||||
box-sizing: border-box;
|
||||
padding: 0 !important;
|
||||
line-height: 1.65;
|
||||
}}
|
||||
.page {{
|
||||
min-height: 100vh;
|
||||
padding: 24px;
|
||||
background: #1E1E2E !important;
|
||||
color: #CDD6F4 !important;
|
||||
}}
|
||||
* {{ box-sizing: border-box; }}
|
||||
h1, h2, h3, h4, h5, h6 {{ color: #B4BEFE !important; margin-top: 0; }}
|
||||
p, ul, ol, blockquote, table, pre {{ margin-top: 0; margin-bottom: 16px; color: #CDD6F4; }}
|
||||
li, span, div {{ color: inherit; }}
|
||||
a {{ color: #89B4FA !important; }}
|
||||
a:visited {{ color: #B4BEFE !important; }}
|
||||
code {{ background: #11111B; color: #F5E0DC; padding: 3px 6px; border-radius: 8px; }}
|
||||
pre {{ background: #11111B; color: #F5E0DC; padding: 14px 16px; border-radius: 12px; overflow-x: auto; }}
|
||||
pre code {{ background: transparent; padding: 0; }}
|
||||
blockquote {{ border-left: 4px solid #89B4FA; padding-left: 12px; color: #A6ADC8 !important; }}
|
||||
table {{ border-collapse: collapse; width: 100%; background: #181825; border-radius: 12px; overflow: hidden; }}
|
||||
th, td {{ border: 1px solid #45475A; padding: 10px 12px; text-align: left; color: #CDD6F4; }}
|
||||
th {{ background: #313244; color: #CDD6F4; }}
|
||||
hr {{ border: none; border-top: 1px solid #45475A; margin: 24px 0; }}
|
||||
img {{ max-width: 100%; height: auto; border-radius: 10px; }}
|
||||
</style>
|
||||
<title>{System.Net.WebUtility.HtmlEncode(title)}</title>
|
||||
</head>
|
||||
<body bgcolor='#1E1E2E' text='#CDD6F4'>
|
||||
<div class='page'>
|
||||
{htmlBody}
|
||||
</div>
|
||||
</body>
|
||||
</html>";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user