mdBook icon indicating copy to clipboard operation
mdBook copied to clipboard

Hide section from the nav sidebar but still generate the HTML files

Open schungx opened this issue 3 years ago • 9 comments

Is it possible to mark a section as "hidden" from the nav sidebar, but still generate the files?

Or have a section automatically collapsed in the sidebar?

schungx avatar Jun 18 '22 14:06 schungx

You can have sections automatically collapsed by setting an appropriate folding level.

ISSOtm avatar Jun 22 '22 17:06 ISSOtm

You can have sections automatically collapsed by setting an appropriate folding level.

But I only want a particular section tree collapsed by default, not the others. Setting a folding level will collapse all sections beyond that level.

schungx avatar Jun 23 '22 00:06 schungx

Alright, that makes sense; what syntax should we use to specify this? I think it would be more appropriate to do this in SUMMARY.md than in book.toml.

ISSOtm avatar Jun 23 '22 06:06 ISSOtm

Actually I think it can be a specific case under the general feature request to put CSS classes or options on individual links in SUMMARY.md (I remember an issue talking about this before, but not sure).

Say, we have the following extension to add configuration to individual lines for SUMMARY.md:

[My Chapter](chapter.md)
[My Hidden Chapter](hidden.md)    { #my-hidden-chapter, hidden=true }

or maybe a CSS class that is automatically recognized:

[My Chapter](chapter.md)
[My Hidden Chapter](hidden.md)    { #my-hidden-chapter.hidden }

schungx avatar Jun 23 '22 06:06 schungx

Collapsing is not simply done via a class, and I'm not certain we would like to expose such a class. I'll investigate if that's possible, especially if that syntax can be used in cmark; in the meantime, do you have any ideas for alternative syntax?

ISSOtm avatar Jun 23 '22 07:06 ISSOtm

do you have any ideas for alternative syntax?

Without attaching options to a particular line, then the only options are: 1) modifiers on the title text, 2) modifiers on the link.

It might be easier to modify the link, e.g. via a prefix (but of course we must have an escape hatch to allow the actual link to start with that prefix).

For example:

[My Hidden Chapter](@hidden.md)
[Not Hidden Chapter](@@hidden.md)

or, to leverage the optional title on links (this is legal MarkDown):

[My Hidden Chapter](hidden.md "collapsed")

schungx avatar Jun 23 '22 07:06 schungx

I would love to have this feature. I though I could achieve it with this plugin:

  • https://github.com/ankitrgadiya/mdbook-hide

But it turns out it doesn't hide chapters, it just stops them from being built.

jakubgs avatar Oct 17 '23 08:10 jakubgs

I did a workaround using some really ugly CSS. I'm essentially hiding the last sub-elements from the last top level element of SUMMARY.md:

ol.chapter > li:not(.chapter-item):last-child {
    visibility: hidden;
}

This would be so much simpler if the li elements had id attribute based off of the title.

jakubgs avatar Oct 24 '23 14:10 jakubgs

This would enable mdbook to handle a more wikibooks/wiki like document, which can be useful for things like technical documentations that don't necessarily have a well defined order of sections

poscat0x04 avatar Jun 02 '24 10:06 poscat0x04