Skip to content

Commit 7ec2d91

Browse files
authored
Fix nested directives within a list (#421)
* Fix nested directives within a list * Add test * Move condition * remove whitespace
1 parent f2af906 commit 7ec2d91

File tree

3 files changed

+116
-2
lines changed

3 files changed

+116
-2
lines changed

Diff for: src/Elastic.Markdown/Myst/Directives/DirectiveBlockParser.cs

+3
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ public override BlockState TryContinue(BlockProcessor processor, Block block)
169169
if (!line.StartsWith(":"))
170170
return base.TryContinue(processor, block);
171171

172+
if (line.StartsWith(":::"))
173+
return base.TryContinue(processor, block);
174+
172175
if (block is not DirectiveBlock directiveBlock)
173176
return base.TryContinue(processor, block);
174177

Diff for: tests/Elastic.Markdown.Tests/Directives/AdmonitionTests.cs

+112
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,115 @@ A regular paragraph.
9999
[Fact]
100100
public void SetsDropdownOpen() => Block!.DropdownOpen.Should().BeTrue();
101101
}
102+
103+
104+
public class NestedDirectiveWithListTests(ITestOutputHelper output) : DirectiveTest<AdmonitionBlock>(output,
105+
"""
106+
# heading
107+
108+
:::::{note}
109+
110+
- List Item 1
111+
::::{note}
112+
Hello, World!
113+
::::
114+
115+
## What
116+
117+
:::::
118+
"""
119+
)
120+
{
121+
[Fact]
122+
public void Render() => Html.Should().Contain("""
123+
<li> List Item 1
124+
<div class="admonition note">
125+
<p class="admonition-title">Note</p>
126+
Hello, World!
127+
</div>
128+
</li>
129+
""");
130+
}
131+
132+
133+
public class NestedDirectiveWithListTests2(ITestOutputHelper output) : DirectiveTest<AdmonitionBlock>(output,
134+
"""
135+
# heading
136+
137+
:::{note}
138+
139+
- List Item 1
140+
:::{note}
141+
Hello, World!
142+
:::
143+
144+
## What
145+
146+
:::
147+
"""
148+
)
149+
{
150+
[Fact]
151+
public void Render() => Html.Should().Contain("""
152+
<li> List Item 1
153+
<div class="admonition note">
154+
<p class="admonition-title">Note</p>
155+
Hello, World!
156+
</div>
157+
</li>
158+
""");
159+
}
160+
161+
public class NestedDirectiveWithListTests3(ITestOutputHelper output) : DirectiveTest<AdmonitionBlock>(output,
162+
"""
163+
# heading
164+
165+
:::{note}
166+
167+
- List Item 1
168+
:::::{note}
169+
Hello, World!
170+
:::::
171+
172+
## What
173+
174+
:::
175+
"""
176+
)
177+
{
178+
[Fact]
179+
public void Render() => Html.Should().Contain("""
180+
<li> List Item 1
181+
<div class="admonition note">
182+
<p class="admonition-title">Note</p>
183+
Hello, World!
184+
</div>
185+
</li>
186+
""");
187+
}
188+
189+
190+
public class DirectiveInList(ITestOutputHelper output) : DirectiveTest<AdmonitionBlock>(output,
191+
"""
192+
# heading
193+
194+
- List Item 1
195+
:::::{note}
196+
Hello, World!
197+
:::::
198+
"""
199+
)
200+
{
201+
[Fact]
202+
public void Type() => Block!.Admonition.Should().Be("note");
203+
204+
[Fact]
205+
public void Render() => Html.Should().Contain("""
206+
<li> List Item 1
207+
<div class="admonition note">
208+
<p class="admonition-title">Note</p>
209+
Hello, World!
210+
</div>
211+
</li>
212+
""");
213+
}

Diff for: tests/Elastic.Markdown.Tests/Directives/DirectiveBaseTests.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ public override async Task InitializeAsync()
2323
{
2424
await base.InitializeAsync();
2525
Block = Document
26-
.Where(block => block is TDirective)
27-
.Cast<TDirective>()
26+
.Descendants<TDirective>()
2827
.FirstOrDefault();
2928
}
3029

0 commit comments

Comments
 (0)