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

Fix nested directives within a list #421

Merged
merged 4 commits into from
Feb 5, 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
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