mirror of
https://github.com/ppy/osu.git
synced 2025-02-06 01:43:01 +08:00
Enable generic attribute support for wiki markdown containers
This commit is contained in:
parent
12aa2e96db
commit
7c282d9def
@ -0,0 +1,34 @@
|
|||||||
|
// 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;
|
||||||
|
using Markdig.Extensions.GenericAttributes;
|
||||||
|
using Markdig.Renderers;
|
||||||
|
using Markdig.Syntax;
|
||||||
|
|
||||||
|
namespace osu.Game.Graphics.Containers.Markdown.Extensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A variant of <see cref="Markdig.Extensions.GenericAttributes.GenericAttributesExtension"/>
|
||||||
|
/// which only handles generic attributes in the current markdown <see cref="Block"/> and ignores inline generic attributes.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// For rationale, see implementation of <see cref="Setup(Markdig.MarkdownPipelineBuilder)"/>.
|
||||||
|
/// </remarks>
|
||||||
|
public class BlockAttributeExtension : IMarkdownExtension
|
||||||
|
{
|
||||||
|
private readonly GenericAttributesExtension genericAttributesExtension = new GenericAttributesExtension();
|
||||||
|
|
||||||
|
public void Setup(MarkdownPipelineBuilder pipeline)
|
||||||
|
{
|
||||||
|
genericAttributesExtension.Setup(pipeline);
|
||||||
|
|
||||||
|
// GenericAttributesExtension registers a GenericAttributesParser in pipeline.InlineParsers.
|
||||||
|
// this conflicts with the CustomContainerExtension, leading to some custom containers (e.g. flags) not displaying.
|
||||||
|
// as a workaround, remove the inline parser here before it can do damage.
|
||||||
|
pipeline.InlineParsers.RemoveAll(parser => parser is GenericAttributesParser);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer) => genericAttributesExtension.Setup(pipeline, renderer);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
// 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;
|
||||||
|
|
||||||
|
namespace osu.Game.Graphics.Containers.Markdown.Extensions
|
||||||
|
{
|
||||||
|
public static class OsuMarkdownExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Uses the block attributes extension.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pipeline">The pipeline.</param>
|
||||||
|
/// <returns>The modified pipeline.</returns>
|
||||||
|
public static MarkdownPipelineBuilder UseBlockAttributes(this MarkdownPipelineBuilder pipeline)
|
||||||
|
{
|
||||||
|
pipeline.Extensions.AddIfNotAlready<BlockAttributeExtension>();
|
||||||
|
return pipeline;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ using Markdig.Extensions.AutoLinks;
|
|||||||
using Markdig.Extensions.CustomContainers;
|
using Markdig.Extensions.CustomContainers;
|
||||||
using Markdig.Extensions.EmphasisExtras;
|
using Markdig.Extensions.EmphasisExtras;
|
||||||
using Markdig.Extensions.Footnotes;
|
using Markdig.Extensions.Footnotes;
|
||||||
|
using osu.Game.Graphics.Containers.Markdown.Extensions;
|
||||||
|
|
||||||
namespace osu.Game.Graphics.Containers.Markdown
|
namespace osu.Game.Graphics.Containers.Markdown
|
||||||
{
|
{
|
||||||
@ -32,6 +33,12 @@ namespace osu.Game.Graphics.Containers.Markdown
|
|||||||
/// <seealso cref="CustomContainerExtension"/>
|
/// <seealso cref="CustomContainerExtension"/>
|
||||||
public bool CustomContainers { get; init; }
|
public bool CustomContainers { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allows the <see cref="OsuMarkdownContainer"/> to parse custom attributes in block elements (used e.g. for custom anchor names in the wiki).
|
||||||
|
/// </summary>
|
||||||
|
/// <seealso cref="BlockAttributeExtension"/>
|
||||||
|
public bool BlockAttributes { get; init; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a prepared <see cref="MarkdownPipeline"/> according to the options specified by the current <see cref="OsuMarkdownContainerOptions"/> instance.
|
/// Returns a prepared <see cref="MarkdownPipeline"/> according to the options specified by the current <see cref="OsuMarkdownContainerOptions"/> instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -53,7 +60,10 @@ namespace osu.Game.Graphics.Containers.Markdown
|
|||||||
pipeline = pipeline.UseAutoLinks();
|
pipeline = pipeline.UseAutoLinks();
|
||||||
|
|
||||||
if (CustomContainers)
|
if (CustomContainers)
|
||||||
pipeline.UseCustomContainers();
|
pipeline = pipeline.UseCustomContainers();
|
||||||
|
|
||||||
|
if (BlockAttributes)
|
||||||
|
pipeline = pipeline.UseBlockAttributes();
|
||||||
|
|
||||||
return pipeline.Build();
|
return pipeline.Build();
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,8 @@ namespace osu.Game.Overlays.Wiki.Markdown
|
|||||||
protected override OsuMarkdownContainerOptions Options => new OsuMarkdownContainerOptions
|
protected override OsuMarkdownContainerOptions Options => new OsuMarkdownContainerOptions
|
||||||
{
|
{
|
||||||
Footnotes = true,
|
Footnotes = true,
|
||||||
CustomContainers = true
|
CustomContainers = true,
|
||||||
|
BlockAttributes = true
|
||||||
};
|
};
|
||||||
|
|
||||||
public string CurrentPath
|
public string CurrentPath
|
||||||
|
Loading…
Reference in New Issue
Block a user