Skip to content

Commit 20a79c9

Browse files
authored
Find every HeadingBlock in a document (#349)
* Find every HeadingBlock in a document * Add test
1 parent 3c0da5f commit 20a79c9

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/Elastic.Markdown/IO/MarkdownFile.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ private void ReadDocumentInstructions(MarkdownDocument document)
162162
}
163163

164164
var contents = document
165-
.Where(block => block is HeadingBlock { Level: >= 2 })
166-
.Cast<HeadingBlock>()
165+
.Descendants<HeadingBlock>()
166+
.Where(block => block is { Level: >= 2 })
167167
.Select(h => (h.GetData("header") as string, h.GetData("anchor") as string))
168168
.Select(h => new PageTocItem
169169
{

tests/Elastic.Markdown.Tests/Inline/AnchorLinkTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ protected override void AddToFileSystem(MockFileSystem fileSystem)
3434
3535
## New Requirements [#new-reqs]
3636
37+
38+
:::{dropdown} Nested heading
39+
40+
##### Heading inside dropdown [#heading-inside-dropdown]
41+
42+
:::
43+
3744
These are new requirements
3845
""";
3946
fileSystem.AddFile(@"docs/testing/req.md", inclusion);
@@ -147,3 +154,21 @@ public void GeneratesHtml() =>
147154
public void HasError() => Collector.Diagnostics.Should().HaveCount(1)
148155
.And.Contain(d => d.Message.Contains("`sub-requirements2` does not exist"));
149156
}
157+
158+
159+
public class NestedHeadingTest(ITestOutputHelper output) : AnchorLinkTestBase(output,
160+
"""
161+
[Heading inside dropdown](testing/req.md#heading-inside-dropdown)
162+
"""
163+
)
164+
{
165+
[Fact]
166+
public void GeneratesHtml() =>
167+
// language=html
168+
Html.Should().Contain(
169+
"""<a href="testing/req.html#heading-inside-dropdown">Heading inside dropdown</a>"""
170+
);
171+
172+
[Fact]
173+
public void HasError() => Collector.Diagnostics.Should().HaveCount(0);
174+
}

0 commit comments

Comments
 (0)