From d815ae9a20e7bca20542dbee20ea0a8cf9102333 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sat, 30 May 2020 22:55:22 +0200 Subject: [PATCH] Add minifier for html and improve style --- Cargo.lock | 7 +++++++ Cargo.toml | 3 ++- src/format/assets/style.css | 41 +++++++++++++++++++++++++++++++++++++ src/format/html.rs | 11 +++++----- 4 files changed, 56 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 93cc2e8..97bfbbb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -83,6 +83,11 @@ name = "libc" version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "minify" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "numtoa" version = "0.1.0" @@ -146,6 +151,7 @@ name = "snekdown" version = "0.1.0" dependencies = [ "crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "minify 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "structopt 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -272,6 +278,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum hermit-abi 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "91780f809e750b0a89f5544be56617ff6b1227ee485bcb06ebe10cdf89bd3b71" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" "checksum libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)" = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49" +"checksum minify 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2ef7c582bd7587da887914eaf294897e82f2f5c98b741f137f2a918cd26a885b" "checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" "checksum proc-macro-error 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "98e9e4b82e0ef281812565ea4751049f1bdcdfccda7d3f459f2e138a40c08678" "checksum proc-macro-error-attr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4f5444ead4e9935abd7f27dc51f7e852a0569ac888096d5ec2499470794e2e53" diff --git a/Cargo.toml b/Cargo.toml index a756287..39baf96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,4 +9,5 @@ edition = "2018" [dependencies] crossbeam-utils = "0.7.2" structopt = "0.3.14" -termion = "1.5.5" \ No newline at end of file +termion = "1.5.5" +minify = "1.1.1" \ No newline at end of file diff --git a/src/format/assets/style.css b/src/format/assets/style.css index 8c595e9..5e462a8 100644 --- a/src/format/assets/style.css +++ b/src/format/assets/style.css @@ -18,10 +18,51 @@ img { height: auto; } +code pre { + font-family: "Fira Code", monospace; + padding: 0.8em 0.2em; + background-color: #DDD; + border-radius: 0.25em; +} + +table { + border-collapse: collapse; +} + +table tr:nth-child(odd) { + background-color: #DDD; +} + +table tr:nth-child(1) { + background-color: white; + font-weight: bold; + border-bottom: 1px solid black; +} + +table td, table th { + border-left: 1px solid black; + padding: 0.2em +} + +table tr td:first-child, table tr th:first-child { + border-left: none; +} + blockquote { + margin-left: 0 +} + +.quote { border-left: 0.3em solid gray; border-radius: 0.2em; + padding-left: 1em; + margin-left: 0 +} + +.quote .metadata { + font-style: italic; padding-left: 0.5em; + color: #444 } .figure { diff --git a/src/format/html.rs b/src/format/html.rs index 96fa293..e416cf3 100644 --- a/src/format/html.rs +++ b/src/format/html.rs @@ -1,4 +1,5 @@ use crate::elements::*; +use minify::html::minify; macro_rules! combine_with_lb { ($a:expr, $b:expr) => { @@ -60,9 +61,9 @@ impl ToHtml for Document { .iter() .fold("".to_string(), |a, b| format!("{}{}", a, b.to_html())); if self.is_root { - let style = std::include_str!("assets/style.css"); + let style = minify(std::include_str!("assets/style.css")); format!( - "
{}
", + "\n
{}
", style, inner ) } else { @@ -107,7 +108,7 @@ impl ToHtml for Paragraph { .elements .iter() .fold("".to_string(), |a, b| combine_with_lb!(a, b)); - format!("

{}

", inner) + minify(format!("

{}

", inner).as_str()) } } @@ -190,11 +191,11 @@ impl ToHtml for Quote { .fold("".to_string(), |a, b| combine_with_lb!(a, b)); if let Some(meta) = self.metadata.clone() { format!( - "
{}
- {}
", + "
{}
", text, meta.data ) } else { - format!("
{}
", text) + format!("
{}
", text) } } }