Moved markdown parsing to separate function
This commit is contained in:
parent
68155ce15a
commit
3d966ac2dd
|
@ -6,6 +6,7 @@
|
||||||
@using Markdig
|
@using Markdig
|
||||||
@using Microsoft.AspNetCore.Authorization
|
@using Microsoft.AspNetCore.Authorization
|
||||||
@using Microsoft.AspNetCore.Identity
|
@using Microsoft.AspNetCore.Identity
|
||||||
|
@using Wave.Utilities
|
||||||
|
|
||||||
@attribute [Authorize(Policy = "ArticleEditPermissions")]
|
@attribute [Authorize(Policy = "ArticleEditPermissions")]
|
||||||
@inject IDbContextFactory<ApplicationDbContext> ContextFactory
|
@inject IDbContextFactory<ApplicationDbContext> ContextFactory
|
||||||
|
@ -156,12 +157,7 @@
|
||||||
}
|
}
|
||||||
article.LastModified = DateTimeOffset.UtcNow;
|
article.LastModified = DateTimeOffset.UtcNow;
|
||||||
|
|
||||||
var pipeline = new MarkdownPipelineBuilder()
|
article.BodyHtml = MarkdownUtilities.Parse(article.Body);
|
||||||
.UsePipeTables()
|
|
||||||
.UseEmphasisExtras()
|
|
||||||
.DisableHtml()
|
|
||||||
.Build();
|
|
||||||
article.BodyHtml = Markdown.ToHtml(article.Body, pipeline);
|
|
||||||
|
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
if (article.Status >= ArticleStatus.Published && article.PublishDate <= DateTimeOffset.UtcNow) {
|
if (article.Status >= ArticleStatus.Published && article.PublishDate <= DateTimeOffset.UtcNow) {
|
||||||
|
|
15
Wave/Utilities/MarkdownUtilities.cs
Normal file
15
Wave/Utilities/MarkdownUtilities.cs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
using Markdig;
|
||||||
|
using Wave.Data;
|
||||||
|
|
||||||
|
namespace Wave.Utilities;
|
||||||
|
|
||||||
|
public static class MarkdownUtilities {
|
||||||
|
public static string Parse(string markdown) {
|
||||||
|
var pipeline = new MarkdownPipelineBuilder()
|
||||||
|
.UsePipeTables()
|
||||||
|
.UseEmphasisExtras()
|
||||||
|
.DisableHtml()
|
||||||
|
.Build();
|
||||||
|
return Markdown.ToHtml(markdown, pipeline);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue