Skip to content

Commit 3a1d112

Browse files
Copilotreakaleek
andauthored
Fix right-side navigation order when snippets are included (#1906)
* Initial plan * Fix heading order issue when snippets are included - Modified GetAnchors method to preserve line number from include directive - Included snippet headings now appear at the correct position in TOC - Changed from assigning line 0 to using actual include block line number - This ensures right-side navigation respects document order Co-authored-by: reakaleek <[email protected]> * Final fix and test for snippet heading order issue - Updated test to properly verify heading order in PageTableOfContent - Verified fix works correctly with manual testing - Snippet headings now appear in correct document order Co-authored-by: reakaleek <[email protected]> * Add comprehensive tests for include directive positioning - Added test for include before headings (IncludeBeforeHeadingsOrderTests) - Added test for include in middle of headings (IncludeInMiddleOfHeadingsOrderTests) - Tests verify correct heading order for all include positions - All 598 unit tests pass successfully Co-authored-by: reakaleek <[email protected]> * Add comprehensive tests for stepper components with includes - Added IncludeWithStepperOrderTests: Tests stepper components combined with include directives - Added StepperBeforeIncludeOrderTests: Tests stepper components before include directives - Tests verify correct TOC ordering for stepper steps from both main document and included snippets - All 604 unit tests pass successfully (6 new tests added) Co-authored-by: reakaleek <[email protected]> * Refactor tests to use numbered words as headings - Changed all realistic headings to numbered words (One, Two, Three, etc.) - Updated all expected TOC orders to follow sequential numbering - Makes it easy to verify correct heading order in test output - All 604 unit tests pass successfully Co-authored-by: reakaleek <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: reakaleek <[email protected]>
1 parent dc3f9c3 commit 3a1d112

File tree

2 files changed

+412
-4
lines changed

2 files changed

+412
-4
lines changed

src/Elastic.Markdown/IO/MarkdownFile.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,16 @@ public static List<PageTocItem> GetAnchors(
253253
|| file is not SnippetFile snippet)
254254
return null;
255255

256-
return snippet.GetAnchors(set, parser, frontMatter);
256+
var anchors = snippet.GetAnchors(set, parser, frontMatter);
257+
return new { Block = i, Anchors = anchors };
257258
})
258259
.Where(i => i is not null)
259260
.ToArray();
260261

261-
var includedTocs = includes.SelectMany(i => i!.TableOfContentItems).ToArray();
262+
var includedTocs = includes
263+
.SelectMany(i => i!.Anchors!.TableOfContentItems
264+
.Select(item => new { TocItem = item, i.Block.Line }))
265+
.ToArray();
262266

263267
// Collect headings from standard markdown
264268
var headingTocs = document
@@ -308,7 +312,7 @@ public static List<PageTocItem> GetAnchors(
308312

309313
var toc = headingTocs
310314
.Concat(stepperTocs)
311-
.Concat(includedTocs.Select(item => new { TocItem = item, Line = 0 }))
315+
.Concat(includedTocs)
312316
.OrderBy(item => item.Line)
313317
.Select(item => item.TocItem)
314318
.Select(toc => subs.Count == 0
@@ -318,7 +322,7 @@ public static List<PageTocItem> GetAnchors(
318322
: toc)
319323
.ToList();
320324

321-
var includedAnchors = includes.SelectMany(i => i!.Anchors).ToArray();
325+
var includedAnchors = includes.SelectMany(i => i!.Anchors!.Anchors).ToArray();
322326
anchors =
323327
[
324328
..document.Descendants<DirectiveBlock>()

0 commit comments

Comments
 (0)