-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
137 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
namespace Elastic.Markdown.Myst.CodeBlocks; | ||
|
||
public record CallOut | ||
{ | ||
public required int Index { get; init; } | ||
public required string Text { get; init; } | ||
public required bool InlineCodeAnnotation { get; init; } | ||
|
||
public required int SliceStart { get; init; } | ||
|
||
public required int Line { get; init; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
using System.Text.RegularExpressions; | ||
|
||
namespace Elastic.Markdown.Myst.CodeBlocks; | ||
|
||
public static partial class CallOutParser | ||
{ | ||
[GeneratedRegex(@"^.+\S+.*?\s<\d+>$", RegexOptions.IgnoreCase, "en-US")] | ||
public static partial Regex CallOutNumber(); | ||
|
||
[GeneratedRegex(@"^.+\S+.*?\s(?:\/\/|#)\s[^""]+$", RegexOptions.IgnoreCase, "en-US")] | ||
public static partial Regex MathInlineAnnotation(); | ||
|
||
[GeneratedRegex(@"\{\{[^\r\n}]+?\}\}", RegexOptions.IgnoreCase, "en-US")] | ||
public static partial Regex MatchSubstitutions(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
using System.IO.Abstractions; | ||
using Elastic.Markdown.Myst.Directives; | ||
using Markdig.Parsers; | ||
using Markdig.Syntax; | ||
|
||
namespace Elastic.Markdown.Myst.CodeBlocks; | ||
|
||
public class EnhancedCodeBlock(BlockParser parser, ParserContext context) | ||
: FencedCodeBlock(parser), IBlockExtension | ||
{ | ||
public BuildContext Build { get; } = context.Build; | ||
|
||
public IFileInfo CurrentFile { get; } = context.Path; | ||
|
||
public bool SkipValidation { get; } = context.SkipValidation; | ||
|
||
public int OpeningLength => Info?.Length ?? 0 + 3; | ||
|
||
public List<CallOut>? CallOuts { get; set; } | ||
|
||
public bool InlineAnnotations { get; set; } | ||
|
||
public string Language { get; set; } = "unknown"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/Elastic.Markdown/Myst/CodeBlocks/EnhancedCodeMarkdownExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
using Elastic.Markdown.Myst.Directives; | ||
using Markdig; | ||
using Markdig.Parsers; | ||
using Markdig.Renderers; | ||
using Markdig.Renderers.Html; | ||
|
||
namespace Elastic.Markdown.Myst.CodeBlocks; | ||
|
||
public static class EnhancedCodeBuilderExtensions | ||
{ | ||
public static MarkdownPipelineBuilder UseEnhancedCodeBlocks(this MarkdownPipelineBuilder pipeline) | ||
{ | ||
pipeline.Extensions.AddIfNotAlready<EnhancedCodeBlockExtension>(); | ||
return pipeline; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Extension to allow custom containers. | ||
/// </summary> | ||
/// <seealso cref="IMarkdownExtension" /> | ||
public class EnhancedCodeBlockExtension : IMarkdownExtension | ||
{ | ||
public void Setup(MarkdownPipelineBuilder pipeline) => | ||
pipeline.BlockParsers.Replace<FencedCodeBlockParser>(new EnhancedCodeBlockParser()); | ||
|
||
public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer) => | ||
renderer.ObjectRenderers.Replace<CodeBlockRenderer>(new EnhancedCodeBlockHtmlRenderer()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters