pass references data into pandoc
This commit is contained in:
parent
1b395a8f60
commit
0e03bc0740
2 changed files with 10 additions and 4 deletions
|
@ -5,7 +5,7 @@ use config::Config;
|
||||||
|
|
||||||
|
|
||||||
pub fn build_input(config: Config, input: String) -> Result<String, String> {
|
pub fn build_input(config: Config, input: String) -> Result<String, String> {
|
||||||
let html = try!(pandoc::render(input));
|
let html = try!(pandoc::render(config.clone(), input));
|
||||||
let rendered = try!(process::render(config.clone(), html));
|
let rendered = try!(process::render(config.clone(), html));
|
||||||
return Ok(rendered);
|
return Ok(rendered);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,10 @@ use pandoc::{self, Pandoc, PandocOutput, PandocError};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use utils::get_exe_dir;
|
use utils::get_exe_dir;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use config::{Config, References};
|
||||||
|
|
||||||
|
|
||||||
fn execute_pandoc(input: String, csl_dir: Option<PathBuf>) -> Result<PandocOutput, PandocError> {
|
fn execute_pandoc(input: String, references: Option<References>) -> Result<PandocOutput, PandocError> {
|
||||||
let mut renderer = Pandoc::new();
|
let mut renderer = Pandoc::new();
|
||||||
renderer.set_output_format(pandoc::OutputFormat::Html, vec![]);
|
renderer.set_output_format(pandoc::OutputFormat::Html, vec![]);
|
||||||
renderer.set_input_format(pandoc::InputFormat::Markdown, vec![]);
|
renderer.set_input_format(pandoc::InputFormat::Markdown, vec![]);
|
||||||
|
@ -13,12 +14,17 @@ fn execute_pandoc(input: String, csl_dir: Option<PathBuf>) -> Result<PandocOutpu
|
||||||
renderer.add_option(pandoc::PandocOption::Smart);
|
renderer.add_option(pandoc::PandocOption::Smart);
|
||||||
renderer.add_option(pandoc::PandocOption::Standalone);
|
renderer.add_option(pandoc::PandocOption::Standalone);
|
||||||
renderer.add_pandoc_path_hint(&get_exe_dir());
|
renderer.add_pandoc_path_hint(&get_exe_dir());
|
||||||
|
if references.is_some() {
|
||||||
|
let References { csl, bibliography } = references.unwrap();
|
||||||
|
renderer.set_bibliography(&bibliography);
|
||||||
|
renderer.set_csl(&csl);
|
||||||
|
}
|
||||||
return renderer.execute();
|
return renderer.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn render(input: String) -> Result<String, String> {
|
pub fn render(config: Config, input: String) -> Result<String, String> {
|
||||||
let output = execute_pandoc(input, None);
|
let output = execute_pandoc(input, config.references);
|
||||||
if output.is_err() {
|
if output.is_err() {
|
||||||
return Err(output.err().unwrap().description().into());
|
return Err(output.err().unwrap().description().into());
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue