-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Document Module - Render Table Of Contents on server-side #23666
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
Conversation
Replaces client-side TOC generation with a new ITocGeneratorService and TocGeneratorService using HtmlAgilityPack. Updates the project page to render the TOC from the server, removes bootstrap-toc dependencies, and adjusts related JS and CSS for the new TOC structure. Adds HtmlAgilityPack as a dependency.
Introduces a Heading record to replace tuple usage for TOC headings, improving code readability and maintainability. Updates related logic in TocGeneratorService to use the new Heading type and adds constants for heading levels.
Replaces the previous HTML-based table of contents (TOC) extraction using HtmlAgilityPack with a Markdig-based approach. Introduces custom Markdig extensions and renderers to extract headings directly from markdown, updates the TOC service and interface, and removes the HtmlAgilityPack dependency from the project.
Replaces HTML-based TOC generation with a model-based approach by extracting heading data from markdown and rendering the table of contents via a new partial view. Removes the custom Markdig extension and related classes, updates the service interface, and adapts the page model and views to use the new heading list.
Replaces the internal Heading record in TocGeneratorService with a new public TocHeading record class. Updates all references and method signatures to use TocHeading, improving code clarity and reusability.
<nav id="docs-sticky-index" class="navbar index-scroll"> | ||
@Html.Raw(Model.TocHtml) | ||
<nav id="toc" class="navbar index-scroll"> | ||
<partial name="TableOfContents" model="Model" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<partial name="TableOfContents" model="Model" /> | |
<partial name="TableOfContents" model="Model.TocHeadings" /> |
@@ -0,0 +1,73 @@ | |||
@model Volo.Docs.Pages.Documents.Project.IndexModel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@model Volo.Docs.Pages.Documents.Project.IndexModel | |
@model List<Heading> | |
@@ -0,0 +1,73 @@ | |||
@model Volo.Docs.Pages.Documents.Project.IndexModel | |||
@{ | |||
if (Model.TocHeadings == null ||Model.TocHeadings.Count == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (Model.TocHeadings == null ||Model.TocHeadings.Count == 0) | |
if (Model == null || Model.Count == 0) | |
return; | ||
} | ||
|
||
var relevantHeadings = Model.TocHeadings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var relevantHeadings = Model.TocHeadings | |
var relevantHeadings = Model | |
|
||
if (relevantHeadings.Count == 0) | ||
{ | ||
relevantHeadings = Model.TocHeadings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
relevantHeadings = Model.TocHeadings | |
relevantHeadings = Model | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete this file
Updated the TableOfContents partial to accept a List<TocHeading> instead of the full IndexModel, simplifying its interface. Adjusted the Index.cshtml to pass Model.TocHeadings directly. Removed the unused TableOfContents.cshtml.cs code-behind file.
Replaces flat TocHeading list with hierarchical TocItem structure for document table of contents. Updates rendering logic, service interface, and implementation to support nested headings and configurable levels.
Enhanced TocGeneratorService by refactoring heading parsing, optimizing inline text extraction, and improving handling of empty or invalid markdown. Added helper methods for pipeline creation, heading construction, and inline processing for better readability and maintainability.
Replaces the use of a fixed max TOC level with a level count parameter in TOC generation methods and logic. This change improves flexibility by allowing the number of heading levels included in the TOC to be specified, rather than a maximum heading level value.
Description
Resolves #23643
Checklist
How to test it?
This PR should be tested in conjunction with the corresponding vs-internal PR.