2021-04-27 17:01:32 +08:00
|
|
|
// 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;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers.Markdown;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Containers.Markdown
|
|
|
|
{
|
|
|
|
public class OsuMarkdownFencedCodeBlock : MarkdownFencedCodeBlock
|
|
|
|
{
|
2021-05-06 18:05:41 +08:00
|
|
|
// TODO : change to monospace font for this component
|
2021-04-27 17:01:32 +08:00
|
|
|
public OsuMarkdownFencedCodeBlock(FencedCodeBlock fencedCodeBlock)
|
|
|
|
: base(fencedCodeBlock)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-05-06 18:05:41 +08:00
|
|
|
protected override Drawable CreateBackground() => new CodeBlockBackground();
|
2021-04-27 17:01:32 +08:00
|
|
|
|
2021-05-06 18:05:41 +08:00
|
|
|
public override MarkdownTextFlowContainer CreateTextFlow() => new CodeBlockTextFlowContainer();
|
|
|
|
|
|
|
|
private class CodeBlockBackground : Box
|
2021-04-27 17:01:32 +08:00
|
|
|
{
|
2021-05-06 18:05:41 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
2021-04-27 17:01:32 +08:00
|
|
|
{
|
2021-05-06 18:05:41 +08:00
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
Colour = colourProvider.Background6;
|
|
|
|
}
|
2021-04-27 17:01:32 +08:00
|
|
|
}
|
|
|
|
|
2021-05-06 18:05:41 +08:00
|
|
|
private class CodeBlockTextFlowContainer : OsuMarkdownTextFlowContainer
|
2021-04-27 17:01:32 +08:00
|
|
|
{
|
2021-05-06 18:05:41 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
|
|
|
{
|
|
|
|
Colour = colourProvider.Light1;
|
|
|
|
Margin = new MarginPadding(10);
|
|
|
|
}
|
2021-04-27 17:01:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|