lib/lib.rs
1#[macro_use]
2extern crate log;
3
4mod error;
5mod example;
6mod file;
7mod libreoffice;
8mod metadata;
9mod pandoc;
10mod tera;
11mod util;
12
13use example::Example;
14use file::File;
15
16
17/// Defines the possible output formats for rsmooth.
18pub enum OutputFormat {
19 /// Portable Document Format.
20 Pdf,
21 /// OpenDocument Text format.
22 Odt,
23 /// Office Open XML Document format.
24 Docx,
25 /// OpenDocument Text format and accompanying PDF file.
26 OdtPdf,
27 /// Reveal.js output.
28 Reveal,
29}
30
31/// Converts a given markdown file and saves the result to the same path with the same file name.
32/// The keep_temp parameter states whether the temporary pandoc input file should be kept for
33/// debugging purposes.
34pub fn convert<'a>(
35 path: &'a str,
36 output: Option<&'a str>,
37 keep_temp: bool,
38 format: OutputFormat,
39) -> Result<(), error::SmoothError<'a>> {
40 let f = File::new(path, output, format)?;
41 f.convert(keep_temp)?;
42 Ok(())
43}
44
45/// Provides a example markdown document showcasing the key concepts of rsmooth. If no path is
46/// given, the method will return the document as a string otherwise the content will be saved
47/// to the given path.
48pub fn example<'a>(path: Option<&'a str>) -> Result<Option<&'a str>, error::SmoothError<'a>> {
49 match path {
50 Some(x) => {
51 Example::save_to_file(x)?;
52 Ok(None)
53 }
54 None => Ok(Some(Example::as_string()?)),
55 }
56}