osu/osu.Game/Overlays/Wiki/Markdown/WikiMarkdownParagraph.cs
2021-05-02 22:22:22 +07:00

41 lines
1.3 KiB
C#

// 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 System.Linq;
using Markdig.Syntax;
using Markdig.Syntax.Inlines;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers.Markdown;
using osuTK;
namespace osu.Game.Overlays.Wiki.Markdown
{
public class WikiMarkdownParagraph : MarkdownParagraph
{
private readonly ParagraphBlock paragraphBlock;
public WikiMarkdownParagraph(ParagraphBlock paragraphBlock)
: base(paragraphBlock)
{
this.paragraphBlock = paragraphBlock;
}
[BackgroundDependencyLoader]
private void load()
{
MarkdownTextFlowContainer textFlow;
InternalChild = textFlow = CreateTextFlow();
textFlow.AddInlineText(paragraphBlock.Inline);
// Check if paragraph only contains an image.
if (paragraphBlock.Inline.Count() == 1 && paragraphBlock.Inline.FirstChild is LinkInline { IsImage: true } linkInline)
{
textFlow.TextAnchor = Anchor.TopCentre;
textFlow.Spacing = new Vector2(0, 5);
textFlow.AddText($"\n{linkInline.Title}");
}
}
}
}