diff --git a/src/output.rs b/src/output.rs index fce2fdf..3f9f848 100644 --- a/src/output.rs +++ b/src/output.rs @@ -264,7 +264,9 @@ impl Css { last_toplevel = ToplevelKind::Other; } _ => { - if last_toplevel != ToplevelKind::Comment { + if last_toplevel != ToplevelKind::Comment + && last_toplevel != ToplevelKind::Media + { self.blocks.push(Toplevel::Newline); } @@ -624,7 +626,7 @@ impl Formatter for ExpandedFormatter { continue; } - if should_emit_newline { + if should_emit_newline && has_written { should_emit_newline = false; writeln!(buf)?; } diff --git a/tests/media.rs b/tests/media.rs index b4dea5f..0e87f41 100644 --- a/tests/media.rs +++ b/tests/media.rs @@ -189,6 +189,36 @@ test!( }", "a {\n color: red;\n}\n\n@media (min-width: 0px) {\n a {\n color: red;\n }\n}\n@media (min-width: 0px) {\n a {\n color: red;\n }\n}\n" ); +test!( + no_newline_after_media_after_ruleset, + "a { + color: red; + } + + @media (min-width: 0px) { + b { + color: red; + } + } + + d { + color: red; + }", + "a {\n color: red;\n}\n\n@media (min-width: 0px) {\n b {\n color: red;\n }\n}\nd {\n color: red;\n}\n" +); +test!( + no_newline_after_media, + "@media (min-width: 0px) { + b { + color: red; + } + } + + d { + color: red; + }", + "@media (min-width: 0px) {\n b {\n color: red;\n }\n}\nd {\n color: red;\n}\n" +); error!( media_feature_missing_closing_paren,