Skip to content

Commit

Permalink
Fix nested directives within a list (#421)
Browse files Browse the repository at this point in the history
* Fix nested directives within a list

* Add test

* Move condition

* remove whitespace
  • Loading branch information
reakaleek authored Feb 5, 2025
1 parent f2af906 commit 7ec2d91
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Elastic.Markdown/Myst/Directives/DirectiveBlockParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ public override BlockState TryContinue(BlockProcessor processor, Block block)
if (!line.StartsWith(":"))
return base.TryContinue(processor, block);

if (line.StartsWith(":::"))
return base.TryContinue(processor, block);

if (block is not DirectiveBlock directiveBlock)
return base.TryContinue(processor, block);

Expand Down
112 changes: 112 additions & 0 deletions tests/Elastic.Markdown.Tests/Directives/AdmonitionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,115 @@ A regular paragraph.
[Fact]
public void SetsDropdownOpen() => Block!.DropdownOpen.Should().BeTrue();
}


public class NestedDirectiveWithListTests(ITestOutputHelper output) : DirectiveTest<AdmonitionBlock>(output,
"""
# heading
:::::{note}
- List Item 1
::::{note}
Hello, World!
::::
## What
:::::
"""
)
{
[Fact]
public void Render() => Html.Should().Contain("""
<li> List Item 1
<div class="admonition note">
<p class="admonition-title">Note</p>
Hello, World!
</div>
</li>
""");
}


public class NestedDirectiveWithListTests2(ITestOutputHelper output) : DirectiveTest<AdmonitionBlock>(output,
"""
# heading
:::{note}
- List Item 1
:::{note}
Hello, World!
:::
## What
:::
"""
)
{
[Fact]
public void Render() => Html.Should().Contain("""
<li> List Item 1
<div class="admonition note">
<p class="admonition-title">Note</p>
Hello, World!
</div>
</li>
""");
}

public class NestedDirectiveWithListTests3(ITestOutputHelper output) : DirectiveTest<AdmonitionBlock>(output,
"""
# heading
:::{note}
- List Item 1
:::::{note}
Hello, World!
:::::
## What
:::
"""
)
{
[Fact]
public void Render() => Html.Should().Contain("""
<li> List Item 1
<div class="admonition note">
<p class="admonition-title">Note</p>
Hello, World!
</div>
</li>
""");
}


public class DirectiveInList(ITestOutputHelper output) : DirectiveTest<AdmonitionBlock>(output,
"""
# heading
- List Item 1
:::::{note}
Hello, World!
:::::
"""
)
{
[Fact]
public void Type() => Block!.Admonition.Should().Be("note");

[Fact]
public void Render() => Html.Should().Contain("""
<li> List Item 1
<div class="admonition note">
<p class="admonition-title">Note</p>
Hello, World!
</div>
</li>
""");
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public override async Task InitializeAsync()
{
await base.InitializeAsync();
Block = Document
.Where(block => block is TDirective)
.Cast<TDirective>()
.Descendants<TDirective>()
.FirstOrDefault();
}

Expand Down

0 comments on commit 7ec2d91

Please sign in to comment.