rust-lang / mdBook

Create book from markdown files. Like Gitbook but implemented in Rust
https://rust-lang.github.io/mdBook/
Mozilla Public License 2.0
18.31k stars 1.64k forks source link

Markdown page table of contents #1263

Open JorelAli opened 4 years ago

JorelAli commented 4 years ago

Expanding from the idea of @ishitatsuyuki, I think mdbook should have the option to have a right-hand sidebar with a table of contents for a page.

Screenshot example ![image](https://user-images.githubusercontent.com/4613171/85430460-0c94c200-b578-11ea-8c28-81d10ddbe0ec.png)

Examples of similar documents:

This could be implemented as an option in the book.toml file, or could be a YAML front matter setting at the top of a page, such as:

---
toc: true
---

Page content here...
JorelAli commented 4 years ago

For anyone still reading this (@aidan-fitz @tshepang @maniyar1), I've made a temporary workaround here.

Sebas-h commented 3 years ago

Thanks @JorelAli 👍

I've used the CSS/JS you wrote and put it in a Userscript here (to be run by the browser). This way we can have a page ToC on deployed mdBooks that do not have one yet.

Hopefully this is somewhat useful :)

Evian-Zhang commented 1 year ago

Come across this issue when I tried to find a solution for in-page tocs. This is such a great job and I wonder why not file a PR to merge this into mdbook's main stream so that everyone can use this feature out-of-box?

Leroy-X commented 1 year ago

wow, this is exactly what I need, I spent a lot of time looking for it, I really look forward to merging it into mdbook soon. Pleeeeeaaaaase!!! It will save users a lot of time out of the box. Big thanks!!!

2bndy5 commented 2 months ago

It would be nice if the solution to this didn't involve JS because that just offloads the needed changes in mdbooks source to end-users (doc readers) on page load.