mirror of https://github.com/ppy/osu
Add markdown country flag support
This commit is contained in:
parent
098a56a784
commit
a9aba74351
|
@ -3,6 +3,9 @@
|
|||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Markdig.Extensions.CustomContainers;
|
||||
using Markdig.Syntax.Inlines;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
|
@ -11,6 +14,9 @@
|
|||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Users;
|
||||
using osu.Game.Users.Drawables;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Graphics.Containers.Markdown
|
||||
{
|
||||
|
@ -33,6 +39,27 @@ protected override void AddCodeInLine(CodeInline codeInline) => AddDrawable(new
|
|||
protected override SpriteText CreateEmphasisedSpriteText(bool bold, bool italic)
|
||||
=> CreateSpriteText().With(t => t.Font = t.Font.With(weight: bold ? FontWeight.Bold : FontWeight.Regular, italics: italic));
|
||||
|
||||
protected override void AddCustomComponent(CustomContainerInline inline)
|
||||
{
|
||||
if (!(inline.FirstChild is LiteralInline literal))
|
||||
{
|
||||
base.AddCustomComponent(inline);
|
||||
return;
|
||||
}
|
||||
|
||||
string[] attributes = literal.Content.ToString().Trim(' ', '{', '}').Split();
|
||||
string flagAttribute = attributes.SingleOrDefault(a => a.StartsWith(@"flag", StringComparison.Ordinal));
|
||||
|
||||
if (flagAttribute == null)
|
||||
{
|
||||
base.AddCustomComponent(inline);
|
||||
return;
|
||||
}
|
||||
|
||||
string flag = flagAttribute.Split('=').Last().Trim('"');
|
||||
AddDrawable(new DrawableFlag(Enum.Parse<CountryCode>(flag)) { Size = new Vector2(20, 15) });
|
||||
}
|
||||
|
||||
private class OsuMarkdownInlineCode : Container
|
||||
{
|
||||
[Resolved]
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#nullable disable
|
||||
|
||||
using System.Linq;
|
||||
using Markdig.Extensions.CustomContainers;
|
||||
using Markdig.Extensions.Yaml;
|
||||
using Markdig.Syntax;
|
||||
using Markdig.Syntax.Inlines;
|
||||
|
@ -16,6 +17,7 @@ namespace osu.Game.Overlays.Wiki.Markdown
|
|||
public class WikiMarkdownContainer : OsuMarkdownContainer
|
||||
{
|
||||
protected override bool Footnotes => true;
|
||||
protected override bool CustomContainers => true;
|
||||
|
||||
public string CurrentPath
|
||||
{
|
||||
|
@ -26,6 +28,11 @@ protected override void AddMarkdownComponent(IMarkdownObject markdownObject, Fil
|
|||
{
|
||||
switch (markdownObject)
|
||||
{
|
||||
case CustomContainer:
|
||||
// infoboxes are parsed into CustomContainer objects, but we don't have support for infoboxes yet.
|
||||
// todo: add support for infobox.
|
||||
break;
|
||||
|
||||
case YamlFrontMatterBlock yamlFrontMatterBlock:
|
||||
container.Add(new WikiNoticeContainer(yamlFrontMatterBlock));
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue