mirror of
https://github.com/ppy/osu
synced 2025-02-18 11:26:57 +00:00
Add markdown country flag support
This commit is contained in:
parent
098a56a784
commit
a9aba74351
@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using Markdig.Extensions.CustomContainers;
|
||||||
using Markdig.Syntax.Inlines;
|
using Markdig.Syntax.Inlines;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
@ -11,6 +14,9 @@ using osu.Framework.Graphics.Containers.Markdown;
|
|||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
|
using osu.Game.Users;
|
||||||
|
using osu.Game.Users.Drawables;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Graphics.Containers.Markdown
|
namespace osu.Game.Graphics.Containers.Markdown
|
||||||
{
|
{
|
||||||
@ -33,6 +39,27 @@ namespace osu.Game.Graphics.Containers.Markdown
|
|||||||
protected override SpriteText CreateEmphasisedSpriteText(bool bold, bool italic)
|
protected override SpriteText CreateEmphasisedSpriteText(bool bold, bool italic)
|
||||||
=> CreateSpriteText().With(t => t.Font = t.Font.With(weight: bold ? FontWeight.Bold : FontWeight.Regular, italics: 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
|
private class OsuMarkdownInlineCode : Container
|
||||||
{
|
{
|
||||||
[Resolved]
|
[Resolved]
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Markdig.Extensions.CustomContainers;
|
||||||
using Markdig.Extensions.Yaml;
|
using Markdig.Extensions.Yaml;
|
||||||
using Markdig.Syntax;
|
using Markdig.Syntax;
|
||||||
using Markdig.Syntax.Inlines;
|
using Markdig.Syntax.Inlines;
|
||||||
@ -16,6 +17,7 @@ namespace osu.Game.Overlays.Wiki.Markdown
|
|||||||
public class WikiMarkdownContainer : OsuMarkdownContainer
|
public class WikiMarkdownContainer : OsuMarkdownContainer
|
||||||
{
|
{
|
||||||
protected override bool Footnotes => true;
|
protected override bool Footnotes => true;
|
||||||
|
protected override bool CustomContainers => true;
|
||||||
|
|
||||||
public string CurrentPath
|
public string CurrentPath
|
||||||
{
|
{
|
||||||
@ -26,6 +28,11 @@ namespace osu.Game.Overlays.Wiki.Markdown
|
|||||||
{
|
{
|
||||||
switch (markdownObject)
|
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:
|
case YamlFrontMatterBlock yamlFrontMatterBlock:
|
||||||
container.Add(new WikiNoticeContainer(yamlFrontMatterBlock));
|
container.Add(new WikiNoticeContainer(yamlFrontMatterBlock));
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user