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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions book-example/src/format/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,27 @@ allow for easy parsing. Let's see how you should format your `SUMMARY.md` file.
[Title of prefix element](relative/path/to/markdown.md)
```

3. ***Numbered Chapter*** Numbered chapters are the main content of the book,
3. ***Part Title:*** Headers can be used as a title for the following numbered
chapters. This can be used to logically separate different sections
of book. The title is rendered as unclickable text.
Titles are optional, and the numbered chapters can be broken into as many
parts as desired.

4. ***Numbered Chapter*** Numbered chapters are the main content of the book,
they will be numbered and can be nested, resulting in a nice hierarchy
(chapters, sub-chapters, etc.)
```markdown
# Title of Part

- [Title of the Chapter](relative/path/to/markdown.md)

# Title of Another Part

- [More Chapters](relative/path/to/markdown2.md)
```
You can either use `-` or `*` to indicate a numbered chapter.

4. ***Suffix Chapter*** After the numbered chapters you can add a couple of
5. ***Suffix Chapter*** After the numbered chapters you can add a couple of
non-numbered chapters. They are the same as prefix chapters but come after
the numbered chapters instead of before.

Expand All @@ -50,5 +62,5 @@ error.
of contents, as you can see for the next chapter in the table of contents on the left.
Draft chapters are written like normal chapters but without writing the path to the file
```markdown
- [Draft chapter]()
```
- [Draft chapter]()
```
6 changes: 5 additions & 1 deletion src/book/book.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ pub enum BookItem {
Chapter(Chapter),
/// A section separator.
Separator,
/// A part title.
PartTitle(String),
}

impl From<Chapter> for BookItem {
Expand Down Expand Up @@ -229,11 +231,12 @@ fn load_summary_item<P: AsRef<Path> + Clone>(
src_dir: P,
parent_names: Vec<String>,
) -> Result<BookItem> {
match *item {
match item {
SummaryItem::Separator => Ok(BookItem::Separator),
SummaryItem::Link(ref link) => {
load_chapter(link, src_dir, parent_names).map(BookItem::Chapter)
}
SummaryItem::PartTitle(title) => Ok(BookItem::PartTitle(title.clone())),
}
}

Expand Down Expand Up @@ -569,6 +572,7 @@ And here is some \
location: Some(PathBuf::from("")),
..Default::default()
})],

..Default::default()
};

Expand Down
1 change: 1 addition & 0 deletions src/book/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ impl MDBook {
/// match *item {
/// BookItem::Chapter(ref chapter) => {},
/// BookItem::Separator => {},
/// BookItem::PartTitle(ref title) => {}
/// }
/// }
///
Expand Down
Loading