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

implement support for book parts #1171

Merged
merged 6 commits into from
May 20, 2020
Merged

implement support for book parts #1171

merged 6 commits into from
May 20, 2020

Conversation

mark-i-m
Copy link
Member

@mark-i-m mark-i-m commented Mar 21, 2020

Implements support for breaking the list of chapters in SUMMARY.md into parts. This is useful for really long books that (e.g. rustc-dev-guide).

Some notable things:

  • I think this makes breaking changes to some public APIs of the mdbook crate.
  • I did some refactoring on the SUMMARY.md parser that I think cleans things up a bit. In particular, I gave the parser the ability to lookahead 1 token, which got rid of some edge cases and prevents every combinator from having to figure out if they are missing their first token. The new convention is that if your combinator discovers it has gone too far, it puts back the last token it read.

Here is a sample of what it looks like:

image

@mark-i-m
Copy link
Member Author

All tests are passing locally for me.

@ehuss ehuss modified the milestones: 0.3, 0.4 Mar 25, 2020
@terretta
Copy link

terretta commented May 9, 2020

+1 -- looking for this.

Currently, mdbook knows about this SUMMARY.md syntax but doesn't leverage:
https://github.com/rust-lang/book/blob/2c942dc094f4ddcdc7aba7564f80782801197c99/second-edition/src/SUMMARY.md#basic-rust-literacy

Using ## to indicate parts in SUMMARY.md is used at GitBook as well. This PR allows rendering of a matching Nav, while the current code drops the part names entirely.

‌# Summary​

## Use headings to create page groups like this one​

* [First page's title](page1/README.md)    
    * [Some child page](page1/page1-1.md)    
    * [Some other child page](part1/page1-2.md)
    
* [Second page's title](page2/README.md)    
    * [Some child page](page2/page2-1.md)    
    * [Some other child page](part2/page2-2.md)    
    
## A second-page group​

* [Yet another page](another-page.md)

GitBook doc: https://docs.gitbook.com/integrations/github/content-configuration#summary

@mark-i-m
Copy link
Member Author

mark-i-m commented May 9, 2020

It's been a while -- I don't exactly remember, but I think I only implemented 1 level of headers in this PR...

@ehuss
Copy link
Contributor

ehuss commented May 17, 2020

Thanks for your patience!

I can't quite see why summary chapters are split into separate Parts. Like, why couldn't headers be just another variant of SummaryItem and treated similarly to SummaryItem::Separator? Is there somewhere that structure is necessary?

Also, this will need some documentation (probably in https://github.com/rust-lang/mdBook/blob/master/book-example/src/format/summary.md).

@mark-i-m
Copy link
Member Author

@ehuss I don't really remember why I did that; I don't think it occurred to me when I was modifying the summary parser. It doesn't look that hard to change, if you would like me to.

I can also update the documentation you pointed to. Does the comment on parse_summary look roughly like what you want in the documentation?

@ehuss
Copy link
Contributor

ehuss commented May 18, 2020

I don't know if there will be any problems, but I would probably prefer using SummaryItem. The BookItem is designed to be recursive, but AFAICT the part titles are not. And, it doesn't really change the "structure" of the book, so I think it would be good to avoid changing the API in that way.

@mark-i-m
Copy link
Member Author

@ehuss Done. I think it was a good idea, it reduced the diff somewhat.

Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I pushed a small tweak to the documentation wording.

@ehuss ehuss merged commit 5d5c55e into rust-lang:master May 20, 2020
Ruin0x11 pushed a commit to Ruin0x11/mdBook that referenced this pull request Aug 30, 2020
implement support for book parts
72636c added a commit to 72636c/mdbook-svgbob that referenced this pull request Jan 4, 2021
This allows the preprocessor to parse a `SUMMARY.md` that contains book
parts, a feature added in 0.4.0:

- rust-lang/mdBook#1171
- https://github.com/rust-lang/mdBook/blob/master/CHANGELOG.md#mdbook-040

This seems to work locally without any code changes.
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.

3 participants