Skip to content

Commit ebf431c

Browse files
authored
Merge pull request rust-lang#1171 from mark-i-m/master
implement support for book parts
2 parents 8414cee + 5391207 commit ebf431c

File tree

7 files changed

+221
-80
lines changed

7 files changed

+221
-80
lines changed

book-example/src/format/summary.md

+16-4
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,27 @@ allow for easy parsing. Let's see how you should format your `SUMMARY.md` file.
2222
[Title of prefix element](relative/path/to/markdown.md)
2323
```
2424

25-
3. ***Numbered Chapter*** Numbered chapters are the main content of the book,
25+
3. ***Part Title:*** Headers can be used as a title for the following numbered
26+
chapters. This can be used to logically separate different sections
27+
of book. The title is rendered as unclickable text.
28+
Titles are optional, and the numbered chapters can be broken into as many
29+
parts as desired.
30+
31+
4. ***Numbered Chapter*** Numbered chapters are the main content of the book,
2632
they will be numbered and can be nested, resulting in a nice hierarchy
2733
(chapters, sub-chapters, etc.)
2834
```markdown
35+
# Title of Part
36+
2937
- [Title of the Chapter](relative/path/to/markdown.md)
38+
39+
# Title of Another Part
40+
41+
- [More Chapters](relative/path/to/markdown2.md)
3042
```
3143
You can either use `-` or `*` to indicate a numbered chapter.
3244

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

@@ -50,5 +62,5 @@ error.
5062
of contents, as you can see for the next chapter in the table of contents on the left.
5163
Draft chapters are written like normal chapters but without writing the path to the file
5264
```markdown
53-
- [Draft chapter]()
54-
```
65+
- [Draft chapter]()
66+
```

src/book/book.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ pub enum BookItem {
133133
Chapter(Chapter),
134134
/// A section separator.
135135
Separator,
136+
/// A part title.
137+
PartTitle(String),
136138
}
137139

138140
impl From<Chapter> for BookItem {
@@ -229,11 +231,12 @@ fn load_summary_item<P: AsRef<Path> + Clone>(
229231
src_dir: P,
230232
parent_names: Vec<String>,
231233
) -> Result<BookItem> {
232-
match *item {
234+
match item {
233235
SummaryItem::Separator => Ok(BookItem::Separator),
234236
SummaryItem::Link(ref link) => {
235237
load_chapter(link, src_dir, parent_names).map(BookItem::Chapter)
236238
}
239+
SummaryItem::PartTitle(title) => Ok(BookItem::PartTitle(title.clone())),
237240
}
238241
}
239242

@@ -569,6 +572,7 @@ And here is some \
569572
location: Some(PathBuf::from("")),
570573
..Default::default()
571574
})],
575+
572576
..Default::default()
573577
};
574578

src/book/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ impl MDBook {
132132
/// match *item {
133133
/// BookItem::Chapter(ref chapter) => {},
134134
/// BookItem::Separator => {},
135+
/// BookItem::PartTitle(ref title) => {}
135136
/// }
136137
/// }
137138
///

0 commit comments

Comments
 (0)