mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 09:42:54 +08:00
add WikiMarkdownImage
This commit is contained in:
parent
6585dd3a3e
commit
ef707bd099
@ -4,6 +4,7 @@
|
|||||||
using Markdig.Extensions.Yaml;
|
using Markdig.Extensions.Yaml;
|
||||||
using Markdig.Syntax;
|
using Markdig.Syntax;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Containers.Markdown;
|
||||||
using osu.Game.Graphics.Containers.Markdown;
|
using osu.Game.Graphics.Containers.Markdown;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Wiki.Markdown
|
namespace osu.Game.Overlays.Wiki.Markdown
|
||||||
@ -29,6 +30,8 @@ namespace osu.Game.Overlays.Wiki.Markdown
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override MarkdownTextFlowContainer CreateTextFlow() => new WikiMarkdownTextFlowContainer();
|
||||||
|
|
||||||
protected virtual FillFlowContainer CreateNotice(YamlFrontMatterBlock yamlFrontMatterBlock) => new WikiNoticeContainer(yamlFrontMatterBlock);
|
protected virtual FillFlowContainer CreateNotice(YamlFrontMatterBlock yamlFrontMatterBlock) => new WikiNoticeContainer(yamlFrontMatterBlock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
38
osu.Game/Overlays/Wiki/Markdown/WikiMarkdownImage.cs
Normal file
38
osu.Game/Overlays/Wiki/Markdown/WikiMarkdownImage.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// 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 Markdig.Syntax.Inlines;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Containers.Markdown;
|
||||||
|
using osu.Framework.Graphics.Cursor;
|
||||||
|
using osu.Game.Online.API;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Wiki.Markdown
|
||||||
|
{
|
||||||
|
public class WikiMarkdownImage : MarkdownImage, IHasTooltip
|
||||||
|
{
|
||||||
|
private readonly string url;
|
||||||
|
|
||||||
|
public string TooltipText { get; }
|
||||||
|
|
||||||
|
public WikiMarkdownImage(LinkInline linkInline)
|
||||||
|
: base(linkInline.Url)
|
||||||
|
{
|
||||||
|
url = linkInline.Url;
|
||||||
|
TooltipText = linkInline.Title;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(IAPIProvider api)
|
||||||
|
{
|
||||||
|
// The idea is replace "{api.WebsiteRootUrl}/wiki/{path-to-image}" to "{api.WebsiteRootUrl}/wiki/images/{path-to-image}"
|
||||||
|
// "/wiki/images/*" is route to fetch wiki image from osu!web server (see: https://github.com/ppy/osu-web/blob/4205eb66a4da86bdee7835045e4bf28c35456e04/routes/web.php#L289)
|
||||||
|
// Currently all image in dev server (https://dev.ppy.sh/wiki/image/*) is 404
|
||||||
|
// So for now just replace "{api.WebsiteRootUrl}/wiki/*" to "https://osu.ppy.sh/wiki/images/*" for simplicity
|
||||||
|
var imageUrl = url.Replace($"{api.WebsiteRootUrl}/wiki", "https://osu.ppy.sh/wiki/images");
|
||||||
|
|
||||||
|
InternalChild = new DelayedLoadWrapper(CreateImageContainer(imageUrl));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
// 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 Markdig.Syntax.Inlines;
|
||||||
|
using osu.Game.Graphics.Containers.Markdown;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Wiki.Markdown
|
||||||
|
{
|
||||||
|
public class WikiMarkdownTextFlowContainer : OsuMarkdownTextFlowContainer
|
||||||
|
{
|
||||||
|
protected override void AddImage(LinkInline linkInline) => AddDrawable(new WikiMarkdownImage(linkInline));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user