Merge pull request #23 from Trivernis/develop

Develop
main v0.33.4
Trivernis 4 years ago committed by GitHub
commit 0f2bd16d28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -31,3 +31,12 @@ jobs:
- name: Run tests
run: cargo test --verbose --all-features
- name: Test init
run: cargo run -- init
- name: Test HTML
run: cargo run -- render README.md README.html --format html
- name: Test PDF
run: cargo run --all-features -- render README.md README.pdf --format pdf

746
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -1,6 +1,6 @@
[package]
name = "snekdown"
version = "0.33.3"
version = "0.33.4"
authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018"
license = "GPL-3.0"
@ -53,5 +53,5 @@ sha2 = "0.9.2"
config = "0.10.1"
rsass = "0.16.0"
headless_chrome = { version = "0.9.0", optional = true }
headless_chrome = { version = "0.9.0", optional = true, features = ["fetch"] }
failure = { version = "0.1.8", optional = true }

@ -39,6 +39,9 @@ for my needs.
- Placeholders
- Advanced Images
## Prerequisites
- Google Chrome/Chromium (for PDF rendering)
## Installation

@ -12,7 +12,8 @@ use crate::settings::Settings;
use crate::utils::caching::CacheStorage;
use bibliographix::Mutex;
use headless_chrome::protocol::page::PrintToPdfOptions;
use headless_chrome::{Browser, LaunchOptionsBuilder, Tab};
use headless_chrome::{Browser, Tab};
use std::env;
use std::fs;
use std::fs::OpenOptions;
use std::io::BufWriter;
@ -26,8 +27,14 @@ pub mod result;
/// Renders the document to pdf and returns the resulting bytes
pub fn render_to_pdf(document: Document) -> PdfRenderingResult<Vec<u8>> {
let cache = CacheStorage::new();
let mut file_path = PathBuf::from(format!("tmp-document.html"));
let mut file_path = PathBuf::from("tmp-document.html");
file_path = cache.get_file_path(&file_path);
if !file_path.parent().map(|p| p.exists()).unwrap_or(false) {
file_path = env::current_dir()?;
file_path.push(PathBuf::from(".tmp-document.html"))
}
let config = document.config.clone();
let mathjax = config.lock().features.include_mathjax;
@ -50,7 +57,7 @@ pub fn render_to_pdf(document: Document) -> PdfRenderingResult<Vec<u8>> {
}
});
let browser = Browser::new(LaunchOptionsBuilder::default().build().unwrap())?;
let browser = Browser::default()?;
let tab = browser.wait_for_initial_tab()?;
handle.join().unwrap()?;
tab.navigate_to(format!("file:///{}", file_path.to_string_lossy()).as_str())?;

@ -128,6 +128,7 @@ fn init() {
let manifest_path = PathBuf::from("Manifest.toml");
let bibliography_path = PathBuf::from("Bibliography.toml");
let glossary_path = PathBuf::from("Glossary.toml");
let css_path = PathBuf::from("style.css");
if !manifest_path.exists() {
let mut file = OpenOptions::new()
@ -145,6 +146,9 @@ fn init() {
if !glossary_path.exists() {
File::create("Glossary.toml".to_string()).unwrap();
}
if !css_path.exists() {
File::create("style.css".to_string()).unwrap();
}
}
/// Watches a file with all of its imports and renders on change

@ -35,6 +35,7 @@ impl CacheStorage {
if let Some(extension) = path.extension() {
file_name.set_extension(extension);
}
log::trace!("Cache path is {:?}", path);
return self.location.join(PathBuf::from(file_name));
}

Loading…
Cancel
Save