Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to keep raw HTML tags structure #335

Closed
Eliot00 opened this issue Mar 6, 2024 · 3 comments · Fixed by #355
Closed

Option to keep raw HTML tags structure #335

Eliot00 opened this issue Mar 6, 2024 · 3 comments · Fixed by #355

Comments

@Eliot00
Copy link

Eliot00 commented Mar 6, 2024

my code:

use std::borrow::Cow;

const HTML: &str = r#"<main>
<h1>Hello</h1>
<section>
<p>who am i</p>
</section>
</main>
"#;

const CSS: &str = r#"
p {
    color: red;
}

h1 {
    color: blud;
}
"#;

fn main() -> css_inline::Result<()> {
    let inliner = css_inline::CSSInliner::options()
        .inline_style_tags(false)
        .extra_css(Some(Cow::from(CSS)))
        .build();
    let inlined = inliner.inline(HTML)?;
    println!("result: {}", inlined);

    Ok(())
}

current output:

<html><head></head><body><main>
<h1 style="color: blud;">Hello</h1>
<section>
<p style="color: red;">who am i</p>
</section>
</main>
</body></html>

expect output:

<main>
<h1 style="color: blud;">Hello</h1>
<section>
<p style="color: red;">who am i</p>
</section>
</main>
@Stranger6667
Copy link
Owner

I think it comes from the html5ever parser that adds html, head & body elements to the tree if they are missing, then they get serialized later on. What we can do on the css-inline side is to provide a way to configure the serialization step, so it can skip tags in a more flexible manner, or just give a config option for skipping html / head / body

@jlarmstrongiv
Copy link

That would be great! I’m inlining individual components, rather than the entire email all at once

@Stranger6667
Copy link
Owner

This feature will be released in 0.14 via the inline_fragment function (bindings have the same name for this function in their public API)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants