lambda-fairy / maud

:pencil: Compile-time HTML templates for Rust
https://maud.lambda.xyz
Apache License 2.0
1.98k stars 132 forks source link

aggressive minification #397

Closed FallBackITA27 closed 7 months ago

FallBackITA27 commented 8 months ago

p {"values: "} -> <p>values:</p>

This is obviously an issue. Minifying code is fine, but against user input is painful to deal with.

lambda-fairy commented 7 months ago

Hi, would you like to give a minimal example?

Maud doesn't minify. So I'm not sure how you're seeing this behavior.

zr40 commented 7 months ago

@FallBackITA27 If you're using the browser's inspector rather than 'view source', you're seeing the resulting DOM, not the input HTML. Insignificant whitespace is stripped by the browser's HTML parser before appearing in the DOM.

FallBackITA27 commented 7 months ago

Insignificant whitespace is stripped by the browser's HTML parser before appearing in the DOM.

Nope, it's made into text nodes which are visible to the user and you can actually interact, depending on the tag.

You can actually see this by logging child nodes on an indented element.

FallBackITA27 commented 7 months ago

Hi, would you like to give a minimal example?

fn build() {
    let x = maud::html {
        head { title { "test" }  };
        body {
            p { "Shroomstrat: " };
        };
    }.to_string();
    std::fs::write("./t.html", x.as_bytes()).unwrap();
}

The result is as stated above, where the content of p, meaning that space, is removed. I'm unsure if the example works, I just winged it

zr40 commented 7 months ago

Changing your example as follows to fix the errors:

    fn build() {
        let x = maud::html! {
            head { title { "test" }  };
            body {
                p { "Shroomstrat: " };
            };
        }
        .into_string();

        std::fs::write("./t.html", x).unwrap();
    }

This creates the following output file:

<head><title>test</title></head><body><p>Shroomstrat: </p></body>

Note that the space is not removed.

FallBackITA27 commented 7 months ago

Huh. I'll look into it on my own, absolutely 0 idea on why the output isn't the same.