From c4811a6a9126c4e2e16cdbf9170376059535d55e Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Thu, 30 Jan 2025 13:43:46 +0100 Subject: [PATCH] Add support for single paragraph between code and list Enhanced the logic to allow a single paragraph between annotated code blocks and a follow-up list. Added new test cases to confirm this behavior and ensure proper error handling for invalid cases. --- .../EnhancedCodeBlockHtmlRenderer.cs | 8 ++- .../CodeBlocks/CallOutTests.cs | 58 +++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/Elastic.Markdown/Myst/CodeBlocks/EnhancedCodeBlockHtmlRenderer.cs b/src/Elastic.Markdown/Myst/CodeBlocks/EnhancedCodeBlockHtmlRenderer.cs index 8dfcc0571..04315ebbc 100644 --- a/src/Elastic.Markdown/Myst/CodeBlocks/EnhancedCodeBlockHtmlRenderer.cs +++ b/src/Elastic.Markdown/Myst/CodeBlocks/EnhancedCodeBlockHtmlRenderer.cs @@ -129,7 +129,13 @@ protected override void Write(HtmlRenderer renderer, EnhancedCodeBlock block) { var siblingBlock = block.Parent[index + 1]; if (siblingBlock is not ListBlock) - block.EmitError("Code block with annotations is not followed by a list"); + { + //allow one block of content in between + if (index + 2 <= (block.Parent!.Count - 1)) + siblingBlock = block.Parent[index + 2]; + if (siblingBlock is not ListBlock) + block.EmitError("Code block with annotations is not followed by a list"); + } if (siblingBlock is ListBlock l && l.Count < callOuts.Count) { block.EmitError( diff --git a/tests/Elastic.Markdown.Tests/CodeBlocks/CallOutTests.cs b/tests/Elastic.Markdown.Tests/CodeBlocks/CallOutTests.cs index b63c12e6f..e2779d220 100644 --- a/tests/Elastic.Markdown.Tests/CodeBlocks/CallOutTests.cs +++ b/tests/Elastic.Markdown.Tests/CodeBlocks/CallOutTests.cs @@ -94,6 +94,64 @@ public void RequiresContentToFollow() => Collector.Diagnostics.Should().HaveCoun .And.OnlyContain(c => c.Message.StartsWith("Code block with annotations is not followed by a list")); } + +public class ClassicCallOutsFollowedByAListWithOneParagraph(ITestOutputHelper output) : CodeBlockCallOutTests(output, "csharp", +""" +var x = 1; <1> +var y = x - 2; +var z = y - 2; <2> +""", +""" + +**OUTPUT:** + +1. Marking the first callout +2. Marking the second callout +""" + + ) +{ + [Fact] + public void ParsesMagicCallOuts() => Block!.CallOuts + .Should().NotBeNullOrEmpty() + .And.HaveCount(2) + .And.OnlyContain(c => c.Text.StartsWith("<")); + + [Fact] + public void AllowsAParagraphInBetween() => Collector.Diagnostics.Should().BeEmpty(); +} + +public class ClassicCallOutsFollowedByListButWithTwoParagraphs(ITestOutputHelper output) : CodeBlockCallOutTests(output, "csharp", +""" +var x = 1; <1> +var y = x - 2; +var z = y - 2; <2> +""", +""" + +**OUTPUT:** + +BLOCK TWO + +1. Marking the first callout +2. Marking the second callout +""" + + ) +{ + [Fact] + public void ParsesMagicCallOuts() => Block!.CallOuts + .Should().NotBeNullOrEmpty() + .And.HaveCount(2) + .And.OnlyContain(c => c.Text.StartsWith("<")); + + [Fact] + public void RequiresContentToFollow() => Collector.Diagnostics.Should().HaveCount(1) + .And.OnlyContain(c => c.Message.StartsWith("Code block with annotations is not followed by a list")); +} + + + public class ClassicCallOutsFollowedByListWithWrongCoung(ITestOutputHelper output) : CodeBlockCallOutTests(output, "csharp", """ var x = 1; <1>