add OsuMarkdownContainer

All of the markdown file in osu-wiki have YAML frontmatter. This YAML is
parsed as common markdown paragraph. So we add `UseYamlFrontMatter()` in
markdown pipeline builder to parse YAML as `YamlFrontMatterBlock`.
This commit is contained in:
Gagah Pangeran Rosfatiputra 2021-04-27 14:09:58 +07:00
parent 42c82cea68
commit b75b9a97ed
No known key found for this signature in database
GPG Key ID: 25F6F17FD29031E2
1 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,35 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Markdig;
using Markdig.Extensions.AutoIdentifiers;
using Markdig.Extensions.Yaml;
using Markdig.Syntax;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Containers.Markdown;
namespace osu.Game.Graphics.Containers.Markdown
{
public class OsuMarkdownContainer : MarkdownContainer
{
protected override void AddMarkdownComponent(IMarkdownObject markdownObject, FillFlowContainer container, int level)
{
switch (markdownObject)
{
case YamlFrontMatterBlock _:
// Don't parse YAML Frontmatter
break;
default:
base.AddMarkdownComponent(markdownObject, container, level);
break;
}
}
protected override MarkdownPipeline CreateBuilder()
=> new MarkdownPipelineBuilder().UseAutoIdentifiers(AutoIdentifierOptions.GitHub)
.UseEmojiAndSmiley()
.UseYamlFrontMatter()
.UseAdvancedExtensions().Build();
}
}