Skip to content

Commit f7b4340

Browse files
authored
Add support for single paragraph between code and list (#379)
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.
1 parent a771e8c commit f7b4340

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

src/Elastic.Markdown/Myst/CodeBlocks/EnhancedCodeBlockHtmlRenderer.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,13 @@ protected override void Write(HtmlRenderer renderer, EnhancedCodeBlock block)
129129
{
130130
var siblingBlock = block.Parent[index + 1];
131131
if (siblingBlock is not ListBlock)
132-
block.EmitError("Code block with annotations is not followed by a list");
132+
{
133+
//allow one block of content in between
134+
if (index + 2 <= (block.Parent!.Count - 1))
135+
siblingBlock = block.Parent[index + 2];
136+
if (siblingBlock is not ListBlock)
137+
block.EmitError("Code block with annotations is not followed by a list");
138+
}
133139
if (siblingBlock is ListBlock l && l.Count < callOuts.Count)
134140
{
135141
block.EmitError(

tests/Elastic.Markdown.Tests/CodeBlocks/CallOutTests.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,64 @@ public void RequiresContentToFollow() => Collector.Diagnostics.Should().HaveCoun
9494
.And.OnlyContain(c => c.Message.StartsWith("Code block with annotations is not followed by a list"));
9595
}
9696

97+
98+
public class ClassicCallOutsFollowedByAListWithOneParagraph(ITestOutputHelper output) : CodeBlockCallOutTests(output, "csharp",
99+
"""
100+
var x = 1; <1>
101+
var y = x - 2;
102+
var z = y - 2; <2>
103+
""",
104+
"""
105+
106+
**OUTPUT:**
107+
108+
1. Marking the first callout
109+
2. Marking the second callout
110+
"""
111+
112+
)
113+
{
114+
[Fact]
115+
public void ParsesMagicCallOuts() => Block!.CallOuts
116+
.Should().NotBeNullOrEmpty()
117+
.And.HaveCount(2)
118+
.And.OnlyContain(c => c.Text.StartsWith("<"));
119+
120+
[Fact]
121+
public void AllowsAParagraphInBetween() => Collector.Diagnostics.Should().BeEmpty();
122+
}
123+
124+
public class ClassicCallOutsFollowedByListButWithTwoParagraphs(ITestOutputHelper output) : CodeBlockCallOutTests(output, "csharp",
125+
"""
126+
var x = 1; <1>
127+
var y = x - 2;
128+
var z = y - 2; <2>
129+
""",
130+
"""
131+
132+
**OUTPUT:**
133+
134+
BLOCK TWO
135+
136+
1. Marking the first callout
137+
2. Marking the second callout
138+
"""
139+
140+
)
141+
{
142+
[Fact]
143+
public void ParsesMagicCallOuts() => Block!.CallOuts
144+
.Should().NotBeNullOrEmpty()
145+
.And.HaveCount(2)
146+
.And.OnlyContain(c => c.Text.StartsWith("<"));
147+
148+
[Fact]
149+
public void RequiresContentToFollow() => Collector.Diagnostics.Should().HaveCount(1)
150+
.And.OnlyContain(c => c.Message.StartsWith("Code block with annotations is not followed by a list"));
151+
}
152+
153+
154+
97155
public class ClassicCallOutsFollowedByListWithWrongCoung(ITestOutputHelper output) : CodeBlockCallOutTests(output, "csharp",
98156
"""
99157
var x = 1; <1>

0 commit comments

Comments
 (0)