1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 17:17:24 +08:00
osu-lazer/osu.Game/Overlays/Wiki/WikiArticlePage.cs
2021-06-04 11:35:23 +07:00

78 lines
2.4 KiB
C#

// 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 System;
using Markdig.Syntax;
using Markdig.Syntax.Inlines;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Containers.Markdown;
using osu.Game.Overlays.Wiki.Markdown;
namespace osu.Game.Overlays.Wiki
{
public class WikiArticlePage : GridContainer
{
public Container SidebarContainer { get; }
public WikiArticlePage(string currentPath, string markdown)
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
};
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
};
WikiSidebar sidebar;
Content = new[]
{
new Drawable[]
{
SidebarContainer = new Container
{
AutoSizeAxes = Axes.X,
Child = sidebar = new WikiSidebar(),
},
new ArticleMarkdownContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
CurrentPath = currentPath,
Text = markdown,
DocumentMargin = new MarginPadding(0),
DocumentPadding = new MarginPadding
{
Vertical = 20,
Left = 30,
Right = 50,
},
OnAddHeading = sidebar.AddToc,
}
},
};
}
private class ArticleMarkdownContainer : WikiMarkdownContainer
{
public Action<string, MarkdownHeading, int> OnAddHeading;
protected override MarkdownHeading CreateHeading(HeadingBlock headingBlock)
{
var heading = base.CreateHeading(headingBlock);
var title = ((LiteralInline)headingBlock.Inline.FirstChild).Content.ToString();
OnAddHeading(title, heading, headingBlock.Level);
return heading;
}
}
}
}