From 45dfbddb3d466dd489e39d7fdd8f54065b741272 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Wed, 20 Dec 2023 22:36:45 +0300 Subject: [PATCH] Fix CSS escaping --- src/cube/mod.rs | 7 ++++--- src/minify/css.rs | 44 ++----------------------------------------- src/pages/_404/mod.rs | 2 +- 3 files changed, 7 insertions(+), 46 deletions(-) diff --git a/src/cube/mod.rs b/src/cube/mod.rs index 7c80edf..3511afe 100644 --- a/src/cube/mod.rs +++ b/src/cube/mod.rs @@ -2,6 +2,7 @@ use embed_file::embed_string as embed; use maud::{ html, Markup, + PreEscaped, }; use crate::{ @@ -15,12 +16,12 @@ pub fn create>(styling: S, faces: [Markup; 6]) -> Markup { page::create( html! { style { - (minify::css(embed!("cube.css"))) + (PreEscaped(minify::css(embed!("cube.css")))) } }, html! { style { - (styling.as_ref()) + (PreEscaped(styling.as_ref())) } div class="scene" { @@ -34,7 +35,7 @@ pub fn create>(styling: S, faces: [Markup; 6]) -> Markup { } script { - (minify::js(embed!("cube.js"))) + (PreEscaped(minify::js(embed!("cube.js")))) } }, ) diff --git a/src/minify/css.rs b/src/minify/css.rs index 110716f..f4c1173 100644 --- a/src/minify/css.rs +++ b/src/minify/css.rs @@ -1,44 +1,4 @@ -const SPECIAL_CHARS: [char; 8] = ['{', '}', ':', ';', ' ', '\n', '!', '>']; - -// Taken from https://github.com/amgarrett09/rust-css-minifier/blob/master/src/minify/mod.rs. pub fn css>(input: S) -> String { - let mut last_char: Vec = " ".chars().collect(); - let mut output = Vec::new(); - - let mut inside_comment = false; - - for c in input.as_ref().chars() { - // We're in a comment if we find '/*' - if !inside_comment && c == '*' && last_char[0] == '/' { - inside_comment = true; - output.pop(); - } - - // We're no longer in a comment if we find '*/' - if inside_comment && c == '/' && last_char[0] == '*' { - inside_comment = false; - } - - // We should NOT add a char to the output if: - // 1) It's a line break, OR - // 2) The char is a space AND the last char scanned was one of our - // special cases OR - // 3) We're inside a comment - // should_add_char is the negation of that - if !(c == '\n' || (c == ' ' && SPECIAL_CHARS.contains(&last_char[0])) || inside_comment) { - // Remove last char (and don't put it back) if it's a space before - // a special character, or if it's a semicolon before an ending brace - if let Some(last) = output.pop() { - if (!SPECIAL_CHARS.contains(&c) || last != ' ') && (c != '}' || last != ';') { - output.push(last); - } - } - - output.push(c); - } - - last_char[0] = c; - } - - output.iter().collect() + // TODO: Actually do something. + return input.as_ref().to_string(); } diff --git a/src/pages/_404/mod.rs b/src/pages/_404/mod.rs index 9a1ebed..6bdb851 100644 --- a/src/pages/_404/mod.rs +++ b/src/pages/_404/mod.rs @@ -16,7 +16,7 @@ pub async fn generate() -> Markup { minify::css(embed!("404.css")), array::from_fn(|_| { (html! { - div class="frame" {} + div class="frame" { "404" } div class="square black" {} div class="square magenta" {} div class="square magenta" {}