feat: inject custom markdown pipeline

This commit is contained in:
Oliver Booth 2023-08-08 00:34:15 +01:00
parent d69ef231eb
commit 6524a4f618
Signed by: oliverbooth
GPG Key ID: 725DB725A0D9EE61
2 changed files with 20 additions and 2 deletions

View File

@ -1,3 +1,4 @@
using Markdig;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
@ -9,10 +10,12 @@ namespace OliverBooth.Pages.Blog;
public class Article : PageModel public class Article : PageModel
{ {
private readonly IDbContextFactory<BlogContext> _dbContextFactory; private readonly IDbContextFactory<BlogContext> _dbContextFactory;
private readonly MarkdownPipeline _markdownPipeline;
public Article(IDbContextFactory<BlogContext> dbContextFactory) public Article(IDbContextFactory<BlogContext> dbContextFactory, MarkdownPipeline markdownPipeline)
{ {
_dbContextFactory = dbContextFactory; _dbContextFactory = dbContextFactory;
_markdownPipeline = markdownPipeline;
} }
public Author Author { get; private set; } public Author Author { get; private set; }
@ -28,7 +31,7 @@ public class Article : PageModel
content = content.Replace("\n\n", "\n"); content = content.Replace("\n\n", "\n");
} }
return Markdig.Markdown.ToHtml(content.Trim()); return Markdown.ToHtml(content.Trim(), _markdownPipeline);
} }
public IActionResult OnGet(int year, int month, int day, string slug) public IActionResult OnGet(int year, int month, int day, string slug)

View File

@ -1,3 +1,4 @@
using Markdig;
using NLog.Extensions.Logging; using NLog.Extensions.Logging;
using OliverBooth.Data; using OliverBooth.Data;
using OliverBooth.Services; using OliverBooth.Services;
@ -9,6 +10,20 @@ builder.Configuration.AddTomlFile("data/config.toml", true, true);
builder.Logging.ClearProviders(); builder.Logging.ClearProviders();
builder.Logging.AddNLog(); builder.Logging.AddNLog();
builder.Services.AddHostedSingleton<LoggingService>(); builder.Services.AddHostedSingleton<LoggingService>();
builder.Services.AddSingleton(new MarkdownPipelineBuilder()
.UseAbbreviations()
.UseAdvancedExtensions()
.UseBootstrap()
.UseCitations()
.UseDiagrams()
.UseFigures()
.UseFooters()
.UseFootnotes()
.UseGlobalization()
.UseMathematics()
.UseAutoIdentifiers()
.UseAutoLinks()
.Build());
builder.Services.AddDbContextFactory<BlogContext>(); builder.Services.AddDbContextFactory<BlogContext>();
builder.Services.AddDbContextFactory<WebContext>(); builder.Services.AddDbContextFactory<WebContext>();