2021-04-27 15:09:58 +08:00
|
|
|
// 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;
|
2021-04-28 11:53:12 +08:00
|
|
|
using Markdig.Extensions.Tables;
|
2021-04-27 15:09:58 +08:00
|
|
|
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;
|
|
|
|
|
2021-04-30 10:43:21 +08:00
|
|
|
case ListItemBlock listItemBlock:
|
|
|
|
var childContainer = CreateListItem(listItemBlock);
|
|
|
|
container.Add(childContainer);
|
|
|
|
foreach (var single in listItemBlock)
|
|
|
|
base.AddMarkdownComponent(single, childContainer, level);
|
|
|
|
break;
|
|
|
|
|
2021-04-27 15:09:58 +08:00
|
|
|
default:
|
|
|
|
base.AddMarkdownComponent(markdownObject, container, level);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-27 17:01:32 +08:00
|
|
|
public override MarkdownTextFlowContainer CreateTextFlow() => new OsuMarkdownTextFlowContainer();
|
|
|
|
|
|
|
|
protected override MarkdownFencedCodeBlock CreateFencedCodeBlock(FencedCodeBlock fencedCodeBlock) => new OsuMarkdownFencedCodeBlock(fencedCodeBlock);
|
|
|
|
|
2021-04-28 10:23:05 +08:00
|
|
|
protected override MarkdownSeparator CreateSeparator(ThematicBreakBlock thematicBlock) => new OsuMarkdownSeparator();
|
|
|
|
|
2021-04-28 11:11:29 +08:00
|
|
|
protected override MarkdownQuoteBlock CreateQuoteBlock(QuoteBlock quoteBlock) => new OsuMarkdownQuoteBlock(quoteBlock);
|
|
|
|
|
2021-04-28 11:53:12 +08:00
|
|
|
protected override MarkdownTable CreateTable(Table table) => new OsuMarkdownTable(table);
|
|
|
|
|
2021-04-30 10:43:21 +08:00
|
|
|
protected virtual OsuMarkdownListItem CreateListItem(ListItemBlock listItemBlock) => new OsuMarkdownListItem();
|
|
|
|
|
2021-04-27 15:09:58 +08:00
|
|
|
protected override MarkdownPipeline CreateBuilder()
|
|
|
|
=> new MarkdownPipelineBuilder().UseAutoIdentifiers(AutoIdentifierOptions.GitHub)
|
|
|
|
.UseEmojiAndSmiley()
|
|
|
|
.UseYamlFrontMatter()
|
|
|
|
.UseAdvancedExtensions().Build();
|
|
|
|
}
|
|
|
|
}
|