Render content with pandoc
This commit is contained in:
parent
83a1b082cd
commit
ec7e83ae55
3 changed files with 29 additions and 9 deletions
|
@ -4,6 +4,6 @@ use config::Config;
|
|||
|
||||
|
||||
pub fn build_input(config: Config, input: String) -> Result<String, String> {
|
||||
pandoc::render(config, input);
|
||||
return Ok("".into());
|
||||
let html = try!(pandoc::render(config, input));
|
||||
return Ok(html);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,31 @@
|
|||
use config::Config;
|
||||
use pandoc::Pandoc;
|
||||
use pandoc::{Pandoc, OutputFormat, InputFormat, InputKind, OutputKind, PandocOutput, PandocError,
|
||||
PandocOption};
|
||||
use std::env::{current_dir, current_exe};
|
||||
use std::path::PathBuf;
|
||||
use std::error::Error;
|
||||
|
||||
fn build_pandoc(config: Config) -> Pandoc {
|
||||
return Pandoc::new();
|
||||
fn execute_pandoc(config: Config, input: String) -> Result<PandocOutput, PandocError> {
|
||||
let mut pandoc = Pandoc::new();
|
||||
pandoc.add_pandoc_path_hint(¤t_dir().unwrap().join("lib"));
|
||||
pandoc.add_pandoc_path_hint(¤t_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);
|
||||
return pandoc.execute();
|
||||
}
|
||||
|
||||
|
||||
pub fn render(config: Config, input: String) {
|
||||
let renderer = build_pandoc(config);
|
||||
pub fn render(config: Config, input: String) -> Result<String, String> {
|
||||
let output = execute_pandoc(config, input);
|
||||
if output.is_err() {
|
||||
return Err(output.err().unwrap().description().into());
|
||||
}
|
||||
return match output.unwrap() {
|
||||
PandocOutput::ToBuffer(out) => Ok(out),
|
||||
_ => Err("Incorrect output type.".into()),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ use build::build_input;
|
|||
|
||||
pub fn build(config: Config) -> Result<(), String> {
|
||||
let input = try!(read_input_files(config.input.clone()));
|
||||
println!("{}", input);
|
||||
build_input(config.clone(), input);
|
||||
let raw_html = try!(build_input(config.clone(), input));
|
||||
println!("{}", raw_html);
|
||||
return Ok(());
|
||||
}
|
||||
|
|
Reference in a new issue