1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-26 22:22:53 +08:00
osu-lazer/osu.Game/Graphics/Containers/Markdown/OsuMarkdownContainer.cs

100 lines
3.9 KiB
C#
Raw Normal View History

// 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.
2022-06-17 15:37:17 +08:00
#nullable disable
using Markdig;
using Markdig.Extensions.Footnotes;
2021-04-28 11:53:12 +08:00
using Markdig.Extensions.Tables;
using Markdig.Extensions.Yaml;
using Markdig.Syntax;
2022-12-17 03:59:14 +08:00
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Containers.Markdown;
2022-12-17 04:26:13 +08:00
using osu.Framework.Graphics.Containers.Markdown.Footnotes;
using osu.Framework.Graphics.Sprites;
2022-12-17 04:26:13 +08:00
using osu.Game.Graphics.Containers.Markdown.Footnotes;
using osu.Game.Graphics.Sprites;
2022-12-17 04:26:13 +08:00
using osuTK;
namespace osu.Game.Graphics.Containers.Markdown
{
2022-12-17 03:59:14 +08:00
[Cached]
2022-11-24 13:32:20 +08:00
public partial class OsuMarkdownContainer : MarkdownContainer
{
public OsuMarkdownContainer()
{
LineSpacing = 21;
}
protected override void AddMarkdownComponent(IMarkdownObject markdownObject, FillFlowContainer container, int level)
{
switch (markdownObject)
{
2022-06-24 20:25:23 +08:00
case YamlFrontMatterBlock:
// Don't parse YAML Frontmatter
break;
case ListItemBlock listItemBlock:
bool isOrdered = ((ListBlock)listItemBlock.Parent)?.IsOrdered == true;
OsuMarkdownListItem childContainer = CreateListItem(listItemBlock, level, isOrdered);
container.Add(childContainer);
foreach (var single in listItemBlock)
base.AddMarkdownComponent(single, childContainer.Content, level);
break;
default:
base.AddMarkdownComponent(markdownObject, container, level);
break;
}
}
public override SpriteText CreateSpriteText() => new OsuSpriteText
{
2021-08-03 23:14:44 +08:00
Font = OsuFont.GetFont(Typeface.Inter, size: 14, weight: FontWeight.Regular),
};
public override MarkdownTextFlowContainer CreateTextFlow() => new OsuMarkdownTextFlowContainer();
2021-05-03 10:35:55 +08:00
protected override MarkdownHeading CreateHeading(HeadingBlock headingBlock) => new OsuMarkdownHeading(headingBlock);
protected override MarkdownFencedCodeBlock CreateFencedCodeBlock(FencedCodeBlock fencedCodeBlock) => new OsuMarkdownFencedCodeBlock(fencedCodeBlock);
protected override MarkdownSeparator CreateSeparator(ThematicBreakBlock thematicBlock) => new OsuMarkdownSeparator();
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);
protected override MarkdownList CreateList(ListBlock listBlock) => new MarkdownList
{
Padding = new MarginPadding(0)
};
protected virtual OsuMarkdownListItem CreateListItem(ListItemBlock listItemBlock, int level, bool isOrdered)
{
if (isOrdered)
return new OsuMarkdownOrderedListItem(listItemBlock.Order);
return new OsuMarkdownUnorderedListItem(level);
}
2022-12-17 04:26:13 +08:00
protected override MarkdownFootnoteGroup CreateFootnoteGroup(FootnoteGroup footnoteGroup) => base.CreateFootnoteGroup(footnoteGroup).With(g => g.Spacing = new Vector2(5));
protected override MarkdownFootnote CreateFootnote(Footnote footnote) => new OsuMarkdownFootnote(footnote);
2022-12-20 03:16:36 +08:00
protected sealed override MarkdownPipeline CreateBuilder()
=> Options.BuildPipeline();
2022-12-20 03:16:36 +08:00
/// <summary>
/// Creates a <see cref="OsuMarkdownContainerOptions"/> instance which is used to determine
/// which CommonMark/Markdig extensions should be enabled for this <see cref="OsuMarkdownContainer"/>.
/// </summary>
protected virtual OsuMarkdownContainerOptions Options => new OsuMarkdownContainerOptions();
}
}