mirror of
https://github.com/lise-henry/crowbook
synced 2024-09-28 02:59:45 +02:00
Make rendering.inline_toc.name a template that can use {{{loc_toc}}}
This commit is contained in:
parent
6c5c716755
commit
b84f470ea2
@ -1,4 +1,5 @@
|
||||
menu: Table of contents
|
||||
toc: Table of contents
|
||||
chapter: Chapter
|
||||
|
||||
display_all: Display all chapters
|
||||
|
@ -1,4 +1,5 @@
|
||||
menu: Table des matières
|
||||
toc: Table des matières
|
||||
chapter: Chapitre
|
||||
|
||||
display_all: Afficher tous les chapitres
|
||||
|
@ -38,7 +38,7 @@ input.yaml_blocks:bool:false # Enable inline YAML blocks to override optio
|
||||
# Rendering options
|
||||
rendering.initials:bool:false # Use initals ('lettrines') for first letter of a chapter (experimental)
|
||||
rendering.inline_toc:bool:false # Display a table of content in the document
|
||||
rendering.inline_toc.name:str:Table of contents # Name of the table of contents if it is displayed in document
|
||||
rendering.inline_toc.name:str:\"{{{loc_toc}}}\" # Name of the table of contents if it is displayed in document
|
||||
rendering.num_depth:int:1 # The maximum heading levels that should be numbered (0: no numbering, 1: only chapters, ..., 6: all)
|
||||
rendering.chapter_template:str:\"{{{number}}}. {{{chapter_title}}}\" # Format of numbered titles
|
||||
|
||||
|
@ -420,6 +420,18 @@ impl<'a> HtmlRenderer<'a> {
|
||||
template.render_data(&mut res, &data);
|
||||
Ok(String::from_utf8_lossy(&res).into_owned())
|
||||
}
|
||||
|
||||
/// Renders the toc name
|
||||
#[doc(hidden)]
|
||||
pub fn get_toc_name(&mut self) -> Result<String> {
|
||||
let data = try!(self.book.get_metadata(|s| self.render_vec(&try!(Parser::new().parse_inline(s)))))
|
||||
.build();
|
||||
let template = self.book.options.get_str("rendering.inline_toc.name").unwrap();
|
||||
let template = try!(compile_str(template, &self.book.source, "could not compile template 'rendering.inline_toc'"));
|
||||
let mut res = vec!();
|
||||
template.render_data(&mut res, &data);
|
||||
Ok(String::from_utf8_lossy(&res).into_owned())
|
||||
}
|
||||
|
||||
|
||||
/// Renders a footer, which can include a "Generated by Crowboook" link
|
||||
|
@ -227,6 +227,20 @@ impl<'a> HtmlDirRenderer<'a> {
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
|
||||
// Insert toc inline if option is set
|
||||
if self.html.book.options.get_bool("rendering.inline_toc").unwrap() {
|
||||
|
||||
content.push_str(&format!(
|
||||
"<h1>{}</h1>
|
||||
<div id = \"toc\">
|
||||
{}
|
||||
</div>
|
||||
",
|
||||
try!(self.html.get_toc_name()),
|
||||
&toc));
|
||||
}
|
||||
|
||||
if titles.len() > 1 {
|
||||
content.push_str(&format!("<p class = \"next_chapter\">
|
||||
<a href = \"{}\">
|
||||
|
@ -140,18 +140,19 @@ impl<'a> HtmlSingleRenderer<'a> {
|
||||
titles[i + 1]));
|
||||
}
|
||||
}
|
||||
|
||||
let toc = self.html.toc.render();
|
||||
|
||||
let toc = self.html.toc.render();
|
||||
// If display_toc, display the toc inline
|
||||
println!("inline_toc: {}",self.html.book.options.get_bool("rendering.inline_toc").unwrap());
|
||||
if self.html.book.options.get_bool("rendering.inline_toc").unwrap() {
|
||||
|
||||
content = format!(
|
||||
"<h1>{}</h1>
|
||||
<div id = \"toc\">
|
||||
{}
|
||||
</div>
|
||||
{}",
|
||||
self.html.book.options.get_str("rendering.inline_toc.name").unwrap(),
|
||||
try!(self.html.get_toc_name()),
|
||||
&toc,
|
||||
content);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user