mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 17:07:38 +08:00
use heading block to get title string
This commit is contained in:
parent
6d6c03eafe
commit
8883d5e2d1
@ -2,9 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Markdig.Syntax;
|
||||
using Markdig.Syntax.Inlines;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Containers.Markdown;
|
||||
@ -62,14 +60,13 @@ namespace osu.Game.Overlays.Wiki
|
||||
|
||||
private class ArticleMarkdownContainer : WikiMarkdownContainer
|
||||
{
|
||||
public Action<string, MarkdownHeading, int> OnAddHeading;
|
||||
public Action<HeadingBlock, MarkdownHeading> OnAddHeading;
|
||||
|
||||
protected override MarkdownHeading CreateHeading(HeadingBlock headingBlock)
|
||||
{
|
||||
var heading = base.CreateHeading(headingBlock);
|
||||
var title = ((LiteralInline)headingBlock.Inline.First(i => i is LiteralInline)).Content.ToString();
|
||||
|
||||
OnAddHeading(title, heading, headingBlock.Level);
|
||||
OnAddHeading(headingBlock, heading);
|
||||
|
||||
return heading;
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Markdig.Syntax;
|
||||
using Markdig.Syntax.Inlines;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -38,17 +40,35 @@ namespace osu.Game.Overlays.Wiki
|
||||
},
|
||||
};
|
||||
|
||||
public void AddToc(string title, MarkdownHeading heading, int level)
|
||||
public void AddToc(HeadingBlock headingBlock, MarkdownHeading heading)
|
||||
{
|
||||
switch (level)
|
||||
switch (headingBlock.Level)
|
||||
{
|
||||
case 2:
|
||||
case 3:
|
||||
tableOfContents.Add(new TocTitle(title, heading, level == 3));
|
||||
string title = getTitle(headingBlock.Inline);
|
||||
tableOfContents.Add(new TocTitle(title, heading, headingBlock.Level == 3));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private string getTitle(ContainerInline containerInline)
|
||||
{
|
||||
foreach (var inline in containerInline)
|
||||
{
|
||||
switch (inline)
|
||||
{
|
||||
case LiteralInline literalInline:
|
||||
return literalInline.Content.ToString();
|
||||
|
||||
case LinkInline { IsImage: false } linkInline:
|
||||
return getTitle(linkInline);
|
||||
}
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private class TocTitle : OsuHoverContainer
|
||||
{
|
||||
[Resolved]
|
||||
|
Loading…
Reference in New Issue
Block a user