1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-15 04:12:57 +08:00

add markdown paragraph with image block

This commit is contained in:
Gagah Pangeran Rosfatiputra 2021-05-02 22:22:22 +07:00
parent ef707bd099
commit b78ec8307d
No known key found for this signature in database
GPG Key ID: 25F6F17FD29031E2
2 changed files with 42 additions and 0 deletions

View File

@ -32,6 +32,8 @@ namespace osu.Game.Overlays.Wiki.Markdown
public override MarkdownTextFlowContainer CreateTextFlow() => new WikiMarkdownTextFlowContainer();
protected override MarkdownParagraph CreateParagraph(ParagraphBlock paragraphBlock, int level) => new WikiMarkdownParagraph(paragraphBlock);
protected virtual FillFlowContainer CreateNotice(YamlFrontMatterBlock yamlFrontMatterBlock) => new WikiNoticeContainer(yamlFrontMatterBlock);
}
}

View File

@ -0,0 +1,40 @@
// 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}");
}
}
}
}