Skip to content
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

[Feature] expandable sidebar sections (ToC collapse) #1027

Merged
merged 7 commits into from
Oct 19, 2019
Merged

[Feature] expandable sidebar sections (ToC collapse) #1027

merged 7 commits into from
Oct 19, 2019

Conversation

weihanglo
Copy link
Member

@weihanglo weihanglo commented Sep 15, 2019

What

Implementation of foldable table of contents.

Related issues #25 #187

How

By comparing values of chapter.section, one can determine whether current path is a subpath. For example 1.2.3. is a subpath of 1.2., so we can expand the whole ancestor section at once.

Features

  • Foldable Section of Sidebar: When output.html.fold.enable is set to true. You can toggle section to expand/collapse in sidebar. See Screenshots for more.
  • output.html.fold Subtable config: This config behaves like vim's foldenable and foldlevel, an is aimed at configuring sidebar section-folding behavior.
    • fold.enable: Enable section-folding. When off, all folds are open.
      Defaults to false.
    • fold.evel: The higher the more folded regions are open. When level is 0, all
      folds are closed. Defaults to 0.
  • Documentation update

Breaking Changes

No. output.html.fold.enable defaults to false, so no any changes before enabling it.

Screenshots

mdBook User Guide

TRPL

Open to see more behaviors

enable = false

enable = true, level = 0

enable = true, level = 1

enable = true, level = 2

@weihanglo weihanglo marked this pull request as ready for review September 17, 2019 13:56
@weihanglo weihanglo changed the title [Feature] expandable table of contents [Feature] expandable table of contents (toc collapse) Sep 17, 2019
@weihanglo weihanglo changed the title [Feature] expandable table of contents (toc collapse) [Feature] expandable sidebar sections (ToC collapse) Sep 17, 2019
@weihanglo
Copy link
Member Author

@ehuss Pardon me. Would you mind take a look? I think this is a very helpful enhancement without breaking changes.

@ehuss
Copy link
Contributor

ehuss commented Sep 26, 2019

This seems fine to me. @Dylan-DPC do you have any input?

src/config.rs Outdated Show resolved Hide resolved
src/renderer/html_handlebars/hbs_renderer.rs Outdated Show resolved Hide resolved
- Derive default for `Fold`.
- Use `is_empty` instead of checking the length of chapters.
@Dylan-DPC-zz Dylan-DPC-zz merged commit 6af6219 into rust-lang:master Oct 19, 2019
@weihanglo weihanglo deleted the feat/expandable-toc branch October 19, 2019 09:03
Ruin0x11 pushed a commit to Ruin0x11/mdBook that referenced this pull request Aug 30, 2020
* render(toc): render expandable toc toggle

* ui(toc): js/css logic to toggle toc

* test: update rendered output css selector

* config: add `html.fold.[enable|level]`

* renderer: fold according to configs

* doc: add `output.html.fold`

* refactor: tidy fold config

- Derive default for `Fold`.
- Use `is_empty` instead of checking the length of chapters.
@insaaniManav
Copy link

where is the configuration supposed to be set ? Doesnt work for me when I set it in config.toml

@sunface
Copy link

sunface commented Dec 1, 2021

@insaaniManav

Append content below to book.toml file which can be found in the root directory of your book:

[output.html.fold]
enable = true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants