pub struct Chapter {
pub name: String,
pub content: String,
pub number: Option<SectionNumber>,
pub sub_items: Vec<BookItem>,
pub path: Option<PathBuf>,
pub source_path: Option<PathBuf>,
pub parent_names: Vec<String>,
}
Expand description
The representation of a “chapter”, usually mapping to a single file on disk however it may contain multiple sub-chapters.
Fields§
§name: String
The chapter’s name.
content: String
The chapter’s contents.
number: Option<SectionNumber>
The chapter’s section number, if it has one.
sub_items: Vec<BookItem>
Nested items.
path: Option<PathBuf>
The chapter’s location, relative to the SUMMARY.md
file.
Note: After the index preprocessor runs, any README files will be
modified to be index.md
. If you need access to the actual filename
on disk, use Chapter::source_path
instead.
This is None
for a draft chapter.
source_path: Option<PathBuf>
The chapter’s source file, relative to the SUMMARY.md
file.
Note: Beware that README files will internally be treated as
index.md
via the Chapter::path
field. The source_path
field
exists if you need access to the true file path.
This is None
for a draft chapter.
parent_names: Vec<String>
An ordered list of the names of each chapter above this one in the hierarchy.
Implementations§
Source§impl Chapter
impl Chapter
Sourcepub fn new<P: Into<PathBuf>>(
name: &str,
content: String,
p: P,
parent_names: Vec<String>,
) -> Chapter
pub fn new<P: Into<PathBuf>>( name: &str, content: String, p: P, parent_names: Vec<String>, ) -> Chapter
Create a new chapter with the provided content.
Sourcepub fn new_draft(name: &str, parent_names: Vec<String>) -> Self
pub fn new_draft(name: &str, parent_names: Vec<String>) -> Self
Create a new draft chapter that is not attached to a source markdown file (and thus has no content).
Sourcepub fn is_draft_chapter(&self) -> bool
pub fn is_draft_chapter(&self) -> bool
Check if the chapter is a draft chapter, meaning it has no path to a source markdown file.