Add minifier for html and improve style

pull/1/head
trivernis 5 years ago
parent 7d0d04454e
commit d815ae9a20

7
Cargo.lock generated

@ -83,6 +83,11 @@ name = "libc"
version = "0.2.71" version = "0.2.71"
source = "registry+https://github.com/rust-lang/crates.io-index" 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]] [[package]]
name = "numtoa" name = "numtoa"
version = "0.1.0" version = "0.1.0"
@ -146,6 +151,7 @@ name = "snekdown"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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 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 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 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 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 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" "checksum proc-macro-error-attr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4f5444ead4e9935abd7f27dc51f7e852a0569ac888096d5ec2499470794e2e53"

@ -10,3 +10,4 @@ edition = "2018"
crossbeam-utils = "0.7.2" crossbeam-utils = "0.7.2"
structopt = "0.3.14" structopt = "0.3.14"
termion = "1.5.5" termion = "1.5.5"
minify = "1.1.1"

@ -18,10 +18,51 @@ img {
height: auto; 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 { blockquote {
margin-left: 0
}
.quote {
border-left: 0.3em solid gray; border-left: 0.3em solid gray;
border-radius: 0.2em; border-radius: 0.2em;
padding-left: 1em;
margin-left: 0
}
.quote .metadata {
font-style: italic;
padding-left: 0.5em; padding-left: 0.5em;
color: #444
} }
.figure { .figure {

@ -1,4 +1,5 @@
use crate::elements::*; use crate::elements::*;
use minify::html::minify;
macro_rules! combine_with_lb { macro_rules! combine_with_lb {
($a:expr, $b:expr) => { ($a:expr, $b:expr) => {
@ -60,9 +61,9 @@ impl ToHtml for Document {
.iter() .iter()
.fold("".to_string(), |a, b| format!("{}{}", a, b.to_html())); .fold("".to_string(), |a, b| format!("{}{}", a, b.to_html()));
if self.is_root { if self.is_root {
let style = std::include_str!("assets/style.css"); let style = minify(std::include_str!("assets/style.css"));
format!( format!(
"<html><head><style>{}</style></head><body><div class='content'>{}</div></body></html>", "<!DOCTYPE html>\n<html><head><style>{}</style></head><body><div class='content'>{}</div></body></html>",
style, inner style, inner
) )
} else { } else {
@ -107,7 +108,7 @@ impl ToHtml for Paragraph {
.elements .elements
.iter() .iter()
.fold("".to_string(), |a, b| combine_with_lb!(a, b)); .fold("".to_string(), |a, b| combine_with_lb!(a, b));
format!("<p>{}</p>", inner) minify(format!("<p>{}</p>", inner).as_str())
} }
} }
@ -190,11 +191,11 @@ impl ToHtml for Quote {
.fold("".to_string(), |a, b| combine_with_lb!(a, b)); .fold("".to_string(), |a, b| combine_with_lb!(a, b));
if let Some(meta) = self.metadata.clone() { if let Some(meta) = self.metadata.clone() {
format!( format!(
"<div><blockquote>{}</blockquote><span>- {}</span></div>", "<div class='quote'><blockquote>{}</blockquote><span class='metadata'>{}</span></div>",
text, meta.data text, meta.data
) )
} else { } else {
format!("<blockquote>{}</blockquote>", text) format!("<div class='quote'><blockquote>{}</blockquote></div>", text)
} }
} }
} }

Loading…
Cancel
Save