1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 17:07:38 +08:00

Add markdown country flag support

This commit is contained in:
Salman Ahmed 2022-10-08 21:26:20 +03:00
parent 098a56a784
commit a9aba74351
2 changed files with 34 additions and 0 deletions

View File

@ -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.Containers.Markdown;
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 @@ namespace osu.Game.Graphics.Containers.Markdown
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]

View File

@ -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 @@ namespace osu.Game.Overlays.Wiki.Markdown
{
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;