Traverse up tree for path hints

This commit is contained in:
Jake Howard 2017-08-16 00:21:53 +01:00
parent c36f3987d1
commit 47f78b94cf
Signed by: jake
GPG key ID: 57AFB45680EDD477

View file

@ -5,16 +5,25 @@ use std::env::{current_dir, current_exe};
use std::path::PathBuf;
use std::error::Error;
fn add_path_hints(pandoc: &mut Pandoc, path: &mut PathBuf) {
let mut out = true;
while out {
pandoc.add_pandoc_path_hint(&path.join("lib"));
out = path.pop();
}
}
fn execute_pandoc(config: Config, input: String) -> Result<PandocOutput, PandocError> {
let mut pandoc = Pandoc::new();
pandoc.add_pandoc_path_hint(&current_dir().unwrap().join("lib"));
pandoc.add_pandoc_path_hint(&current_exe().unwrap().parent().unwrap().join("lib"));
pandoc.set_output_format(OutputFormat::Html5, vec![]);
pandoc.set_input_format(InputFormat::Markdown, vec![]);
pandoc.set_input(InputKind::Pipe(input));
pandoc.set_output(OutputKind::Pipe);
pandoc.add_option(PandocOption::Smart);
pandoc.add_option(PandocOption::Standalone);
add_path_hints(&mut pandoc, &mut current_exe().unwrap());
add_path_hints(&mut pandoc, &mut current_dir().unwrap());
return pandoc.execute();
}