render markdown in make_data()

This commit is contained in:
Gambhiro 2017-01-12 06:48:21 +00:00
parent 2a033de001
commit 5ca380f5a2
3 changed files with 16 additions and 14 deletions

View File

@ -220,9 +220,7 @@ impl Chapter {
debug!("[*]: Reading file");
try!(f.read_to_string(&mut content));
// Render markdown using the pulldown-cmark crate
content = utils::strip_toml_header(&content);
content = utils::render_markdown(&content);
Ok(content)
}

View File

@ -50,8 +50,8 @@ pub struct MDBook {
render_intent: RenderIntent,
/// The book, or books in case of translations, accessible with a String
/// key. The keys can be two-letter codes of the translation such as 'en' or
/// 'fr', but this is not enforced.
/// key. The keys are expected to be the same as the two-letter codes of the
/// language, such as 'en' or 'fr'.
///
/// The String keys will be sub-folders where the translation's Markdown
/// sources are expected.

View File

@ -125,6 +125,10 @@ impl Renderer for HtmlHandlebars {
&book_project.get_dest_base()));
}
// Concatenate the content (as rendered from Markdown) of each chapter
// for writing print.html in the end
let mut print_content: String = String::new();
debug!("[fn]: render");
let mut handlebars = Handlebars::new();
@ -204,7 +208,7 @@ impl Renderer for HtmlHandlebars {
content = helpers::playpen::render_playpen(&content, p);
}
let mut data = try!(make_data(&book, &chapter, &content, &book_project.livereload_script));
let mut data = try!(make_data(&book, &chapter, &book_project.livereload_script));
data.remove("path_to_root");
data.insert("path_to_root".to_owned(), "".to_json());
@ -279,14 +283,7 @@ impl HtmlHandlebars {
handlebars: &Handlebars)
-> Result<(), Box<Error>> {
let mut content = try!(chapter.read_content_using(&book.config.src));
// Parse for playpen links
if let Some(p) = book.config.get_src().join(&chapter.path).parent() {
content = helpers::playpen::render_playpen(&content, p);
}
let data = try!(make_data(book, chapter, &content, livereload_script));
let data = try!(make_data(book, chapter, livereload_script));
// Rendere the handlebars template with the data
debug!("[*]: Render template");
@ -313,7 +310,6 @@ impl HtmlHandlebars {
fn make_data(book: &Book,
chapter: &Chapter,
content: &str,
livereload_script: &Option<String>)
-> Result<serde_json::Map<String, serde_json::Value>, Box<Error>> {
@ -356,6 +352,14 @@ fn make_data(book: &Book,
},
}
let mut content = try!(chapter.read_content_using(&book.config.src));
content = utils::render_markdown(&content);
// Parse for playpen links
if let Some(p) = book.config.get_src().join(&chapter.path).parent() {
content = helpers::playpen::render_playpen(&content, p);
}
data.insert("content".to_owned(), content.to_json());
data.insert("path_to_root".to_owned(), utils::fs::path_to_root(&path).to_json());