File tree Expand file tree Collapse file tree 3 files changed +39
-10
lines changed
tests/Elastic.Markdown.Tests/SiteMap Expand file tree Collapse file tree 3 files changed +39
-10
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,19 @@ public string? NavigationTitle
5454
5555 private bool _instructionsParsed ;
5656
57+ public MarkdownFile [ ] YieldParents ( )
58+ {
59+ var parents = new List < MarkdownFile > ( ) ;
60+ var parent = Parent ;
61+ do
62+ {
63+ if ( parent is { Index : not null } && parent . Index != this )
64+ parents . Add ( parent . Index ) ;
65+ parent = parent ? . Parent ;
66+ } while ( parent != null ) ;
67+ return parents . ToArray ( ) ;
68+ }
69+
5770 public async Task < MarkdownDocument > MinimalParse ( Cancel ctx )
5871 {
5972 var document = await MarkdownParser . MinimalParseAsync ( SourceFile , ctx ) ;
Original file line number Diff line number Diff line change @@ -35,16 +35,7 @@ public MarkdownFile[] Parents
3535 if ( _parents is not null )
3636 return _parents ;
3737
38- var parents = new List < MarkdownFile > ( ) ;
39- var current = CurrentDocument . Parent ;
40- do
41- {
42- if ( current is { Index : not null } && current . Index != CurrentDocument )
43- parents . Add ( current . Index ) ;
44- current = current ? . Parent ;
45- } while ( current != null ) ;
46-
47- _parents = [ .. parents ] ;
38+ _parents = [ .. CurrentDocument . YieldParents ( ) ] ;
4839 return _parents ;
4940 }
5041 }
Original file line number Diff line number Diff line change 1+ // Licensed to Elasticsearch B.V under one or more agreements.
2+ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+ // See the LICENSE file in the project root for more information
4+
5+ using Elastic . Markdown . IO ;
6+ using FluentAssertions ;
7+ using Xunit . Abstractions ;
8+
9+ namespace Elastic . Markdown . Tests . SiteMap ;
10+
11+ public class BreadCrumbTests ( ITestOutputHelper output ) : NavigationTestsBase ( output )
12+ {
13+ [ Fact ]
14+ public void ParsesATableOfContents ( )
15+ {
16+ var doc = Generator . DocumentationSet . Files . FirstOrDefault ( f => f . RelativePath == "testing/nested/index.md" ) as MarkdownFile ;
17+
18+ doc . Should ( ) . NotBeNull ( ) ;
19+
20+ doc ! . Parent . Should ( ) . NotBeNull ( ) ;
21+
22+ doc . YieldParents ( ) . Should ( ) . HaveCount ( 2 ) ;
23+
24+ }
25+ }
You can’t perform that action at this time.
0 commit comments