Moved markdown parsing to separate function

This commit is contained in:
Mia Rose Winter 2024-01-17 14:04:59 +01:00
parent 68155ce15a
commit 3d966ac2dd
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E
2 changed files with 17 additions and 6 deletions

View file

@ -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) {

View 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);
}
}