fix: Table of Contents doesn't work correctly with Markdown Section in demo site/new components
See original GitHub issue🐛 Bug Report
Table of Contents cannot scan the content of Markdown Sections when interacting with the application in the usual way, specifically:
- When the
FluentTableOfContents.QueryDommethod is called byFluentTableOfContents.OnAfterRenderAsync, the contents of the Markdown Sections are not present, so the correct table of contents will not be obtained. - After changing the Location, the
FluentTableOfContents.QueryDommethod is called byFluentTableOfContents.LocationChanged, the same will happen.
The error occurs on pages like DesignTokens, CodeSetup, …
It is possible to get a Table of Contents as expected of the above pages with the following steps:
- Open/refresh the page DesignTokens, wait for the content of the Markdown Section to be present.
- According to issue #413, Navigation Menu’s selected is Home so we can navigate to DesignTokens to call
FluentTableOfContents.QueryDombyFluentTableOfContents.LocationChanged, then we will get a correct table of contents.
Doing the above with the MarkdownSection page, we get a table of contents but it also contains the content of DemoSection.
🤔 Expected Behavior
- Table of Contents can scan the content of Markdown Sections.
- Exceptions can be set for the scanned contents of the table of contents.
😯 Current Behavior
Can’t get a Table of Contents and How to get Table of Contents:
https://github.com/microsoft/fluentui-blazor/assets/72692627/6603f012-52e7-4a4e-b9f5-2cd5c601f0ed
Table of Contents scans the content of DemoSection:
https://github.com/microsoft/fluentui-blazor/assets/72692627/e7e27828-35f1-41ef-8a2c-815e224d9f0a
💁 Possible Solution
🔦 Context
🌍 Your Environment
- OS & Device: Windows 10
- Browser Microsoft Edge
Issue Analytics
- State:
- Created 4 months ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Right TOC does not include headings generated outside of ...
The right TOC for documentation pages does not include headings that were generated outside of the markdown syntax.
Read more >Help, I can't get the markdown previewer to work correctly
My problem is idk how to get the markdown styled, for example the code block and quote block are all the same. Besides...
Read more >How to link to part of the same document in Markdown?
I am writing a large Markdown document and would like to place a table of contents of sorts at the beginning that will...
Read more >A Perfect Table of Contents With HTML + CSS
Choosing the correct markup Fundamentally, a table of contents is about a title (chapter or subsection) being tied to a page number, almost ......
Read more >Markdown | IntelliJ IDEA Documentation
Markdown is a lightweight markup language for adding formatting elements to plain text. IntelliJ IDEA recognizes Markdown files, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

One other thing; the FluentMarkdownSection will not be part of the next version. It will just be a helper component in the demo.
We decided to remove it from the set as we don’t want to have external dependencies (in this case Markdig) in the library package
One more one other thing: The
TableOfContentswill also not be part of the next version. It too will be just an example component in the demo environment and not an out-of-the-box component.Reasoning behind this is actually because of this issue and fix. To make sure the ToC gets updated after new headings have been added to the DOM, we need to take quite a few steps to achieve that:
TableOfContentcomponent in theDemoMainLayoutcomponent (in razor and in code)DemoMainLayout.razor.csfile@Bodyparameter ofDemoMainLayoutIn this case the event needs to be raised from the page that contains a
MarkdownSectioncomponent that adds headings to the content of the page. TheMarkdownSectioncomponent has been extended with anEventCallback(OnContentConverted) which gets called after a conversion to HTML has been done.These are doable steps, but it is not something we can automate with installation or ServiceCollection extension or something like that. As there are too many manual steps involved, we do not want to include it in the box but supply code/example how someone can do this/use this in their own project. The demo environment has the steps mentioned above implemented and the documentation on the
TableOfContentspage has been extended.