2021-05-16 18:08:02 +00: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.
|
|
|
|
|
|
2021-05-26 12:22:33 +00:00
|
|
|
|
using System.Linq;
|
2022-10-08 18:26:20 +00:00
|
|
|
|
using Markdig.Extensions.CustomContainers;
|
2021-05-21 09:04:08 +00:00
|
|
|
|
using Markdig.Extensions.Yaml;
|
|
|
|
|
using Markdig.Syntax;
|
2021-05-25 05:14:07 +00:00
|
|
|
|
using Markdig.Syntax.Inlines;
|
2021-05-21 09:04:08 +00:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-05-02 15:02:06 +00:00
|
|
|
|
using osu.Framework.Graphics.Containers.Markdown;
|
2021-05-16 18:08:02 +00:00
|
|
|
|
using osu.Game.Graphics.Containers.Markdown;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Wiki.Markdown
|
|
|
|
|
{
|
|
|
|
|
public partial class WikiMarkdownContainer : OsuMarkdownContainer
|
|
|
|
|
{
|
2022-12-19 19:16:36 +00:00
|
|
|
|
protected override OsuMarkdownContainerOptions Options => new OsuMarkdownContainerOptions
|
|
|
|
|
{
|
|
|
|
|
Footnotes = true,
|
2022-12-19 19:23:01 +00:00
|
|
|
|
CustomContainers = true,
|
|
|
|
|
BlockAttributes = true
|
2022-12-19 19:16:36 +00:00
|
|
|
|
};
|
2022-09-09 23:55:20 +00:00
|
|
|
|
|
2021-05-16 18:08:02 +00:00
|
|
|
|
public string CurrentPath
|
|
|
|
|
{
|
2021-06-01 04:32:52 +00:00
|
|
|
|
set => DocumentUrl = value;
|
2021-05-16 18:08:02 +00:00
|
|
|
|
}
|
2021-05-21 09:04:08 +00:00
|
|
|
|
|
|
|
|
|
protected override void AddMarkdownComponent(IMarkdownObject markdownObject, FillFlowContainer container, int level)
|
|
|
|
|
{
|
|
|
|
|
switch (markdownObject)
|
|
|
|
|
{
|
2022-10-08 18:26:20 +00: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 09:04:08 +00:00
|
|
|
|
case YamlFrontMatterBlock yamlFrontMatterBlock:
|
2021-05-26 08:01:16 +00:00
|
|
|
|
container.Add(new WikiNoticeContainer(yamlFrontMatterBlock));
|
2021-05-26 12:22:33 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ParagraphBlock paragraphBlock:
|
|
|
|
|
// Check if paragraph only contains an image
|
2021-06-07 07:08:44 +00:00
|
|
|
|
if (paragraphBlock.Inline?.Count() == 1 && paragraphBlock.Inline.FirstChild is LinkInline { IsImage: true } linkInline)
|
2021-05-26 12:22:33 +00:00
|
|
|
|
{
|
|
|
|
|
container.Add(new WikiMarkdownImageBlock(linkInline));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
2021-05-21 09:04:08 +00:00
|
|
|
|
}
|
2021-05-26 05:43:59 +00:00
|
|
|
|
|
|
|
|
|
base.AddMarkdownComponent(markdownObject, container, level);
|
2021-05-21 09:04:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-02 15:02:06 +00:00
|
|
|
|
public override MarkdownTextFlowContainer CreateTextFlow() => new WikiMarkdownTextFlowContainer();
|
|
|
|
|
|
2021-05-25 05:14:07 +00:00
|
|
|
|
private partial class WikiMarkdownTextFlowContainer : OsuMarkdownTextFlowContainer
|
|
|
|
|
{
|
|
|
|
|
protected override void AddImage(LinkInline linkInline) => AddDrawable(new WikiMarkdownImage(linkInline));
|
|
|
|
|
}
|
2021-05-16 18:08:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|