1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 02:37:25 +08:00
osu-lazer/osu.Game/Overlays/Wiki/Markdown/WikiMarkdownContainer.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

62 lines
2.2 KiB
C#
Raw Normal View History

2021-05-17 02:08:02 +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.
2022-06-17 15:37:17 +08:00
#nullable disable
2021-05-26 20:22:33 +08:00
using System.Linq;
2022-10-09 02:26:20 +08:00
using Markdig.Extensions.CustomContainers;
2021-05-21 17:04:08 +08:00
using Markdig.Extensions.Yaml;
using Markdig.Syntax;
using Markdig.Syntax.Inlines;
2021-05-21 17:04:08 +08:00
using osu.Framework.Graphics.Containers;
2021-05-02 23:02:06 +08:00
using osu.Framework.Graphics.Containers.Markdown;
2021-05-17 02:08:02 +08:00
using osu.Game.Graphics.Containers.Markdown;
namespace osu.Game.Overlays.Wiki.Markdown
{
public partial class WikiMarkdownContainer : OsuMarkdownContainer
{
protected override bool Footnotes => true;
2022-10-09 02:26:20 +08:00
protected override bool CustomContainers => true;
2021-05-17 02:08:02 +08:00
public string CurrentPath
{
set => DocumentUrl = value;
2021-05-17 02:08:02 +08:00
}
2021-05-21 17:04:08 +08:00
protected override void AddMarkdownComponent(IMarkdownObject markdownObject, FillFlowContainer container, int level)
{
switch (markdownObject)
{
2022-10-09 02:26:20 +08:00
case CustomContainer:
// infoboxes are parsed into CustomContainer objects, but we don't have support for infoboxes yet.
// todo: add support for infobox.
break;
2021-05-21 17:04:08 +08:00
case YamlFrontMatterBlock yamlFrontMatterBlock:
container.Add(new WikiNoticeContainer(yamlFrontMatterBlock));
2021-05-26 20:22:33 +08:00
break;
case ParagraphBlock paragraphBlock:
// Check if paragraph only contains an image
if (paragraphBlock.Inline?.Count() == 1 && paragraphBlock.Inline.FirstChild is LinkInline { IsImage: true } linkInline)
2021-05-26 20:22:33 +08:00
{
container.Add(new WikiMarkdownImageBlock(linkInline));
return;
}
break;
2021-05-21 17:04:08 +08:00
}
base.AddMarkdownComponent(markdownObject, container, level);
2021-05-21 17:04:08 +08:00
}
2021-05-02 23:02:06 +08:00
public override MarkdownTextFlowContainer CreateTextFlow() => new WikiMarkdownTextFlowContainer();
private partial class WikiMarkdownTextFlowContainer : OsuMarkdownTextFlowContainer
{
protected override void AddImage(LinkInline linkInline) => AddDrawable(new WikiMarkdownImage(linkInline));
}
2021-05-17 02:08:02 +08:00
}
}