Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for single paragraph between code and list #379

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
58 changes: 58 additions & 0 deletions tests/Elastic.Markdown.Tests/CodeBlocks/CallOutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down