Hide pdf behind features flag

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/2/head
trivernis 4 years ago
parent 2f16c69c39
commit e5d021a571
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -16,6 +16,10 @@ crate-type = ["lib"]
name = "snekdown"
path = "src/main.rs"
[features]
pdf = ["headless_chrome", "failure"]
[dependencies]
charred = "0.3.3"
asciimath-rs = "0.5.7"
@ -44,5 +48,5 @@ log = "0.4.11"
env_logger = "0.7.1"
indicatif = "0.15.0"
platform-dirs = "0.2.0"
headless_chrome = "0.9.0"
failure = "0.1.8"
headless_chrome = {version = "0.9.0", optional = true}
failure = {version = "0.1.8", optional = true}

@ -324,12 +324,13 @@ The end goal is to have a markup language with features similar to LaTeX.
- [x] Metadata files
- [x] Bibliography
- [x] Math
- [ ] Text sizes
- [ ] Title pages
- [x] Glossary
- [ ] Cross References
- [ ] Figures
- [ ] EPUB Rendering (PDF is too hard)
- [ ] Custom Elements via templates (50%)
- [x] Chromium based pdf rendering
- [x] Custom Stylesheets
- [x] Smart arrows
- [ ] Custom Elements via templates (50%)
- [ ] Cross References
- [ ] Figures
- [ ] EPUB Rendering
- [ ] Text sizes
- [ ] Title pages

@ -1,6 +1,7 @@
use regex::Regex;
use std::collections::HashMap;
#[cfg(feature = "pdf")]
pub mod chromium_pdf;
pub mod html;

@ -2,12 +2,12 @@ use colored::Colorize;
use env_logger::Env;
use log::{Level, LevelFilter};
use notify::{watcher, RecursiveMode, Watcher};
use snekdown::format::chromium_pdf::render_to_pdf;
use snekdown::elements::Document;
use snekdown::format::html::html_writer::HTMLWriter;
use snekdown::format::html::to_html::ToHtml;
use snekdown::parser::ParserOptions;
use snekdown::Parser;
use std::fs::OpenOptions;
use std::fs::{File, OpenOptions};
use std::io::{BufWriter, Write};
use std::path::PathBuf;
use std::sync::mpsc::channel;
@ -135,21 +135,41 @@ fn render(opt: &Opt) -> Parser {
.unwrap();
let mut writer = BufWriter::new(file);
render_format(opt, document, writer);
log::info!("Rendering took: {:?}", start_render.elapsed());
log::info!("Total: {:?}", start.elapsed());
parser
}
#[cfg(not(feature = "pdf"))]
fn render_format(opt: &Opt, document: Document, mut writer: BufWriter<File>) {
match opt.format.as_str() {
"html" => {
"html" => render_html(document, writer),
_ => log::error!("Unknown format {}", opt.format),
}
}
#[cfg(feature = "pdf")]
fn render_format(opt: &Opt, document: Document, mut writer: BufWriter<File>) {
match opt.format.as_str() {
"html" => render_html(document, writer),
"pdf" => render_pdf(document, writer),
_ => log::error!("Unknown format {}", opt.format),
}
}
fn render_html(document: Document, mut writer: BufWriter<File>) {
let mut writer = HTMLWriter::new(Box::new(writer));
document.to_html(&mut writer).unwrap();
writer.flush().unwrap();
}
"pdf" => {
#[cfg(feature = "pdf")]
fn render_pdf(document: Document, mut writer: BufWriter<File>) {
use snekdown::format::chromium_pdf::render_to_pdf;
let result = render_to_pdf(document).expect("Failed to render pdf!");
writer.write_all(&result).unwrap();
writer.flush().unwrap();
}
_ => log::error!("Unknown format {}", opt.format),
}
log::info!("Rendering took: {:?}", start_render.elapsed());
log::info!("Total: {:?}", start.elapsed());
parser
}

Loading…
Cancel
Save