Compare commits

...

11 Commits

Author SHA1 Message Date
Trivernis 0f2bd16d28
Merge pull request #23 from Trivernis/develop
Develop
3 years ago
trivernis 3eb11e03e8
Add chromium requirement to README
closes #21

Signed-off-by: trivernis <trivernis@protonmail.com>
3 years ago
trivernis 659ca55e2c
Merge branch 'main' into develop 3 years ago
trivernis 7da9f5b338
Bump version
Signed-off-by: trivernis <trivernis@protonmail.com>
3 years ago
Trivernis 83734aa530
Merge pull request #22 from silentbat/main
add style.css to init
3 years ago
trivernis c7694d39e0
Change path of temporary file to be absolute
Signed-off-by: trivernis <trivernis@protonmail.com>
3 years ago
trivernis 0495855d91
Fix problems with creating temp file for pdf rendering
Signed-off-by: trivernis <trivernis@protonmail.com>
3 years ago
trivernis cdbfe8c195
Update dependencies
Signed-off-by: trivernis <trivernis@protonmail.com>
3 years ago
trivernis 0e608e255a
Add fetch feature to headless_chromium dep
Signed-off-by: trivernis <trivernis@protonmail.com>
3 years ago
silentbat 995a3b0582
add style.css to init
when calling `snekdown init`, you should get a default (empty) style.css file now
3 years ago
trivernis 8181119f4a
Update README badge links
Signed-off-by: trivernis <trivernis@protonmail.com>
3 years ago

@ -30,4 +30,13 @@ jobs:
run: cargo build --verbose --all-features
- name: Run tests
run: cargo test --verbose --all-features
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 }

@ -6,10 +6,18 @@
<i>More than just Markdown</i>
</p>
<p align="center">
<img src="https://img.shields.io/github/workflow/status/trivernis/snekdown/Build%20and%20Test/main?style=for-the-badge">
<img src="https://img.shields.io/crates/v/snekdown?style=for-the-badge">
<img src="https://img.shields.io/aur/version/snekdown?style=for-the-badge">
<img src="https://img.shields.io/discord/729250668162056313?style=for-the-badge">
<a href="https://github.com/Trivernis/snekdown/actions">
<img src="https://img.shields.io/github/workflow/status/trivernis/snekdown/Build%20and%20Test/main?style=for-the-badge">
</a>
<a href="https://crates.io/crates/snekdown">
<img src="https://img.shields.io/crates/v/snekdown?style=for-the-badge">
</a>
<a href="https://aur.archlinux.org/packages/snekdown">
<img src="https://img.shields.io/aur/version/snekdown?style=for-the-badge">
</a>
<a href="https://discord.gg/vGAXW9nxUv">
<img src="https://img.shields.io/discord/729250668162056313?style=for-the-badge">
</a>
<br/>
<br/>
<a href="https://trivernis.net/snekdown/">Documentation</a> |
@ -31,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