markdown-it mit highlight.js in ASP.NET MVC als reines JavaScript
https://highlightjs.org/
https://markdown-it.github.io/
C# Code für das Posting
``` C#
@section Scripts{
<script type="text/javascript" >
$(document).ready(function() {
postingsMD = {};
@foreach(var posting in Model)
{
@Html.Raw("postingsMD[" + posting.Id + "] = $(\'.blog-content" + posting.Id + "').html().replace(/&/g, \"&\").replace(/</g, \"<\").replace(/>/g, \">\").replace(/"/g, \"\\\"\").replace(/'/g, \"'\");")
}
var md = window.markdownit({
html: true,
linkify: true,
typographer: true
});
$.map( postingsMD, function( val, i ) {
$('.blog-content' + i).html(md.render(val))
});
hljs.highlightAll();
});
</script>
}
<p class="@Html.Raw("blog-content" + posting.Id)">@posting.Text</p>
```
HTML Code im Header
``` HTML
<link href="/lib/highlightjs/styles/default.min.css" rel="stylesheet" >
```
HTML Code am Ende
``` HTML
<script src="/js/jquery.min.js"></script>
<script src="/lib/markdown-it-13.0.1/markdown-it.js"></script>
<script src="/lib/highlightjs/highlight.min.js"></script>
@await RenderSectionAsync("Scripts", required: false)
</body>
</html>
```
... <a href="/Blog/ViewPosting/7/markdown-it-and-highlightjs-in-mvc-apsnetcore-.net6.0">(Weiterlesen)</a>
7/6/2022 10:22:21 PM
by Chris 1157