Skip to content

Add table of contents scope management and refactor diagnostics #774

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

Merged
merged 4 commits into from
Mar 19, 2025

Conversation

Mpdreamz
Copy link
Member

@Mpdreamz Mpdreamz commented Mar 19, 2025

Introduced ITableOfContentsScope to manage scope boundaries, improving link validation and table of contents processing. Updated diagnostics to emit hints for images outside the ToC scope and refactored functions for better reusability. Adjusted related tests and internal structures accordingly.

This attaches the scope (defining toc/docset.yml file)'s directory to MarkdownFile and others.

Use case for this is that we want to error when folks include content on a page that does not live in the scope directory.

Since the scope directory may be relocated by the assembler it will lead to breaks.

image

Implemented as a hint for now to not break anyones builds while we work to update all repositories.

cc @shainaraskas @colleenmcginnis @lcawl

Introduced `ITableOfContentsScope` to manage scope boundaries, improving link validation and table of contents processing. Updated diagnostics to emit hints for images outside the ToC scope and refactored functions for better reusability. Adjusted related tests and internal structures accordingly.
@Copilot Copilot AI review requested due to automatic review settings March 19, 2025 09:19
@Mpdreamz Mpdreamz requested a review from a team as a code owner March 19, 2025 09:19
@Mpdreamz Mpdreamz self-assigned this Mar 19, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces an interface to manage table of contents (ToC) scope and refactors several components to improve link processing, diagnostics, and overall code reusability.

  • Introduces ITableOfContentsScope and propagates it through configuration, file, and navigation objects.
  • Updates the link parser to emit hints for images referenced outside the ToC scope and refines diagnostic and detection rules logic.
  • Refactors naming and method signatures to support the new ToC scope management.

Reviewed Changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs Added image scope check and updated ProcessLinkText signature for enhanced diagnostics.
docs/development/index.md Added a sample image to validate ToC scope checking.
src/Elastic.Markdown/IO/Configuration/TableOfContentsConfiguration.cs Implemented ITableOfContentsScope and refactored related toc configuration logic.
src/Elastic.Markdown/Diagnostics/ProcessorDiagnosticExtensions.cs Centralized diagnostic emission by refactoring error/warning methods.
src/Elastic.Markdown/IO/Configuration/ConfigurationFile.cs Updated to implement ITableOfContentsScope and pass scope to the toc configuration.
src/Elastic.Markdown/IO/MarkdownFile.cs Revised ToC properties and integrated ScopeDirectory mutation.
src/Elastic.Markdown/IO/Configuration/ITocItem.cs Modified ITocItem records to include ToC scope information.
src/Elastic.Markdown/IO/Navigation/DocumentationGroup.cs Updated file reference handling to use the new toc scope.
src/Elastic.Markdown/Slices/HtmlWriter.cs Adjusted ToC item retrieval to reference PageTableOfContent.
src/Elastic.Markdown/Extensions/DetectionRules/DetectionRulesReference.cs Revised detection rule records to include the ToC scope.
src/Elastic.Markdown/Extensions/DetectionRules/DetectionRulesDocsBuilderExtension.cs Modified instantiation of detection references to use configuration as the scope provider.
Files not reviewed (1)
  • tests/authoring/Directives/IncludeBlocks.fs: Language not supported
Comments suppressed due to low confidence (1)

src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs:197

  • Consider normalizing both 'file.Directory.FullName' and 'currentMarkdown.ScopeDirectory.FullName' (e.g., using Path.GetFullPath) to ensure consistent path comparisons across different platforms.
if (!file.Directory!.FullName.StartsWith(currentMarkdown.ScopeDirectory.FullName + Path.DirectorySeparatorChar))

Copy link
Member

@reakaleek reakaleek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -224,9 +230,9 @@ protected void ReadDocumentInstructions(MarkdownDocument document)

var toc = GetAnchors(_set, MarkdownParser, YamlFrontMatter, document, subs, out var anchors);

_tableOfContent.Clear();
_pageTableOfContent.Clear();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While reading some navigation UX patterns I encountered the the term "On Page Table of Contents", which I think is very clear.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it removes a lot of ambiguity, since in the HTML it also says "On this page"

@Mpdreamz Mpdreamz merged commit de857f7 into main Mar 19, 2025
10 checks passed
@Mpdreamz Mpdreamz deleted the feature/warn-on-referencing-out-of-scope branch March 19, 2025 09:35
Mpdreamz added a commit that referenced this pull request Mar 19, 2025
* Add table of contents scope management and refactor diagnostics

Introduced `ITableOfContentsScope` to manage scope boundaries, improving link validation and table of contents processing. Updated diagnostics to emit hints for images outside the ToC scope and refactored functions for better reusability. Adjusted related tests and internal structures accordingly.

* Add TODO to make this an error

* post merge build fixes
Mpdreamz added a commit that referenced this pull request Mar 19, 2025
* Add global navigation and improve diagnostic handling

This commit introduces a GlobalNavigation feature, parsing the new `navigation.yml` file to handle global navigation references. It also replaces `BuildContext` with `DiagnosticsCollector` for diagnostics, ensuring clearer separation of concerns. Additionally, it includes new tests and updates project files for better testing and navigation handling.

* Use navigation.yml to control url path prefixes for resolving

* path_prefix is mandatory except for top level docs-content references

* stage commit

* stage commit

* File copy now in a decent place

* temporary home for in flux paths

* fix failing test

* remove not referenced test project

* Restrict docset.yml configs that define toc.yml sections to ONLY link to sub toc.yml files (#767)

* Restrict docset.yml configs that define toc.yml sections to ONLY link to sub toc.yml files

* relax check for narrative docs too, plays by different rules

* dotnet format

* reference Project directly

* Fix layout and horizontal scrollable tables (#772)

* Fix layout and horizontal scrollable tables

mend

* Use spacing var

* Add custom scrollbar

* tweaks

* Add table of contents scope management and refactor diagnostics (#774)

* Add table of contents scope management and refactor diagnostics

Introduced `ITableOfContentsScope` to manage scope boundaries, improving link validation and table of contents processing. Updated diagnostics to emit hints for images outside the ToC scope and refactored functions for better reusability. Adjusted related tests and internal structures accordingly.

* Add TODO to make this an error

* post merge build fixes

* good enough state

---------

Co-authored-by: Jan Calanog <[email protected]>
colleenmcginnis added a commit to elastic/docs-content that referenced this pull request Mar 20, 2025
Moves images per elastic/docs-builder#774 in
preparation for docs-assembler.
florent-leborgne pushed a commit to elastic/docs-content that referenced this pull request Mar 21, 2025
Moves images per elastic/docs-builder#774 in
preparation for docs-assembler.
colleenmcginnis added a commit to elastic/docs-content that referenced this pull request Mar 21, 2025
Moves images per elastic/docs-builder#774 in
preparation for docs-assembler.
colleenmcginnis added a commit to elastic/docs-content that referenced this pull request Mar 21, 2025
Moves images per elastic/docs-builder#774 in
preparation for docs-assembler.
colleenmcginnis added a commit to elastic/docs-content that referenced this pull request Mar 21, 2025
Moves images per elastic/docs-builder#774 in
preparation for docs-assembler.
colleenmcginnis added a commit to elastic/docs-content that referenced this pull request Mar 21, 2025
Moves images per elastic/docs-builder#774 in
preparation for docs-assembler.
colleenmcginnis added a commit to elastic/ecs-dotnet that referenced this pull request Mar 24, 2025
Miscellaneous docs clean up including: 

* [x] Removing unused substitutions
* [x] Moving images per elastic/docs-builder#774
* [x] ~~Clean up redirecting links~~
* [x] ~~Fix remaining asciidoc-style links~~
colleenmcginnis added a commit to elastic/docs-content that referenced this pull request Mar 24, 2025
Moves images per elastic/docs-builder#774 in
preparation for docs-assembler.
colleenmcginnis added a commit to elastic/kibana that referenced this pull request Mar 25, 2025
Miscellaneous docs clean up including: 

* [x] Removing unused substitutions
* [x] Moving images per elastic/docs-builder#774
* [x] ~~Clean up redirecting links~~
* [x] ~~Clean up asciidoc-style links~~
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Mar 25, 2025
Miscellaneous docs clean up including:

* [x] Removing unused substitutions
* [x] Moving images per elastic/docs-builder#774
* [x] ~~Clean up redirecting links~~
* [x] ~~Clean up asciidoc-style links~~

(cherry picked from commit 5e5aff3)
colleenmcginnis added a commit to elastic/apm-agent-dotnet that referenced this pull request Mar 25, 2025
Miscellaneous docs clean up including: 

* [x] Removing unused substitutions
* [x] Moving images per elastic/docs-builder#774
* [x] Clean up redirecting links
* [x] ~~Clean up asciidoc-style links~~
cqliu1 pushed a commit to cqliu1/kibana that referenced this pull request Mar 31, 2025
Miscellaneous docs clean up including: 

* [x] Removing unused substitutions
* [x] Moving images per elastic/docs-builder#774
* [x] ~~Clean up redirecting links~~
* [x] ~~Clean up asciidoc-style links~~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants