Fix warnings and update Readme

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

@ -4,6 +4,20 @@
This projects goal is to implement a fast markdown parser with an extended syntax fitted This projects goal is to implement a fast markdown parser with an extended syntax fitted
for my needs. for my needs.
## Installation
You need a working rust installation, for example by using [rustup](http://rustup.rs).
```sh
cargo install snekdown
```
With pdf rendering
```sh
cargo install snekdown --features pdf
```
## Usage ## Usage
``` ```

@ -6,12 +6,9 @@ use crate::references::configuration::keys::INCLUDE_MATHJAX;
use crate::utils::downloads::get_cached_path; use crate::utils::downloads::get_cached_path;
use headless_chrome::protocol::page::PrintToPdfOptions; use headless_chrome::protocol::page::PrintToPdfOptions;
use headless_chrome::{Browser, LaunchOptionsBuilder, Tab}; use headless_chrome::{Browser, LaunchOptionsBuilder, Tab};
use std::error::Error; use std::fs::OpenOptions;
use std::fs::{File, OpenOptions};
use std::io;
use std::io::BufWriter; use std::io::BufWriter;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use std::thread; use std::thread;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
@ -40,7 +37,7 @@ pub fn render_to_pdf(document: Document) -> PdfRenderingResult<Vec<u8>> {
.open(file_path)?, .open(file_path)?,
); );
let mut html_writer = HTMLWriter::new(Box::new(writer)); let mut html_writer = HTMLWriter::new(Box::new(writer));
document.to_html(&mut html_writer); document.to_html(&mut html_writer)?;
log::debug!("Successfully rendered temporary html file!"); log::debug!("Successfully rendered temporary html file!");
html_writer.flush() html_writer.flush()
} }

@ -54,7 +54,6 @@ fn main() {
.filter_module("mio", LevelFilter::Warn) .filter_module("mio", LevelFilter::Warn)
.filter_module("want", LevelFilter::Warn) .filter_module("want", LevelFilter::Warn)
.format(|buf, record| { .format(|buf, record| {
use std::io::Write;
let color = get_level_style(record.level()); let color = get_level_style(record.level());
writeln!( writeln!(
buf, buf,
@ -133,7 +132,7 @@ fn render(opt: &Opt) -> Parser {
.create(true) .create(true)
.open(&opt.output) .open(&opt.output)
.unwrap(); .unwrap();
let mut writer = BufWriter::new(file); let writer = BufWriter::new(file);
render_format(opt, document, writer); render_format(opt, document, writer);
log::info!("Rendering took: {:?}", start_render.elapsed()); log::info!("Rendering took: {:?}", start_render.elapsed());
@ -143,7 +142,7 @@ fn render(opt: &Opt) -> Parser {
} }
#[cfg(not(feature = "pdf"))] #[cfg(not(feature = "pdf"))]
fn render_format(opt: &Opt, document: Document, mut writer: BufWriter<File>) { fn render_format(opt: &Opt, document: Document, writer: BufWriter<File>) {
match opt.format.as_str() { match opt.format.as_str() {
"html" => render_html(document, writer), "html" => render_html(document, writer),
_ => log::error!("Unknown format {}", opt.format), _ => log::error!("Unknown format {}", opt.format),
@ -151,7 +150,7 @@ fn render_format(opt: &Opt, document: Document, mut writer: BufWriter<File>) {
} }
#[cfg(feature = "pdf")] #[cfg(feature = "pdf")]
fn render_format(opt: &Opt, document: Document, mut writer: BufWriter<File>) { fn render_format(opt: &Opt, document: Document, writer: BufWriter<File>) {
match opt.format.as_str() { match opt.format.as_str() {
"html" => render_html(document, writer), "html" => render_html(document, writer),
"pdf" => render_pdf(document, writer), "pdf" => render_pdf(document, writer),
@ -159,7 +158,7 @@ fn render_format(opt: &Opt, document: Document, mut writer: BufWriter<File>) {
} }
} }
fn render_html(document: Document, mut writer: BufWriter<File>) { fn render_html(document: Document, writer: BufWriter<File>) {
let mut writer = HTMLWriter::new(Box::new(writer)); let mut writer = HTMLWriter::new(Box::new(writer));
document.to_html(&mut writer).unwrap(); document.to_html(&mut writer).unwrap();
writer.flush().unwrap(); writer.flush().unwrap();

Loading…
Cancel
Save