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
17.87k stars 1.62k forks source link

Include part and chapter titles when printing html #2257

Open lieskjur opened 10 months ago

lieskjur commented 10 months ago

Problem

When printing the output to a pdf only contents of the individual markdown files are included. This means that part and chapter titles defined in the summary are excluded from the resulting document.

With chapters this not as big of a problem, because you can simply add the title from the summary to the beginning of the corresponding markdown file manually, although you are still missing the automatic numbering. On the other hand with part titles this problem is much more significant as there are no corresponding files where they could be added.

Proposed Solution

The solution could be to automatically add a headings based on the level of the file and a special type heading for parts when rendering the pdf output. It could also be nice to have the part title optionally on a separate page.

Notes

No response

KFearsoff commented 10 months ago

This seems unexpectedly hard to do. Right now, the rendering in mdbook just doesn't look for part titles at all, and providing chapter titles is painful as well. Chapter titles get rendered to h1 tag in HTML, and using multiple h1 tags in a single page is discouraged, but then you also have to consider that part titles should probably take more priority...

Essentially, this makes a print page a pile of questionable HTML decisions. There's no hope of fixing it too, because decrementing header levels will lead to gigantic pain in CSS.

Unfortunately, there's also the fact that the source code that is responsible for generating print page is kinda... ugly? It is not the best, and touching it is scary.

@rustbot label +A-Print