Skip to content

Commit 6ccdfa7

Browse files
committed
ignore @media tags in inline css files
1 parent 1de107c commit 6ccdfa7

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

src/com/inet/lib/less/CssAtRule.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
*/
3232
class CssAtRule extends LessObject implements Formattable {
3333

34-
private final String css;
34+
private final String css;
35+
36+
private final boolean withPlaceHolder;
3537

3638
/**
3739
* Create CSS at-rule that have no special handling. Known CSS at rules are @charset, @document, @font-face,
@@ -42,9 +44,10 @@ class CssAtRule extends LessObject implements Formattable {
4244
* @param css
4345
* the content of the rule
4446
*/
45-
public CssAtRule( LessObject reader, String css ) {
47+
public CssAtRule( LessObject reader, String css, boolean withPlaceHolder ) {
4648
super( reader );
4749
this.css = css;
50+
this.withPlaceHolder = withPlaceHolder;
4851
}
4952

5053
/**
@@ -78,7 +81,11 @@ public void appendTo( CssFormatter formatter ) {
7881
formatter = formatter.getHeader();
7982
}
8083
formatter.getOutput();
81-
SelectorUtils.appendToWithPlaceHolder( formatter, css, 1, false, this );
84+
if( withPlaceHolder ) {
85+
SelectorUtils.appendToWithPlaceHolder( formatter, css, 1, false, this );
86+
} else {
87+
formatter.append( css );
88+
}
8289
formatter.newline();
8390
}
8491
}

src/com/inet/lib/less/LessParser.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ private void variable( HashMap<String, Expression> variables, FormattableContain
420420
if( name.endsWith( "()" ) ) {
421421
currentRule.add( new VariableExpression( reader, name.substring( 0, name.length() - 2 ) ) ); // reference to detached ruleset
422422
} else {
423-
currentRule.add( new CssAtRule( reader, name + ';') ); // directives like @charset "UTF-8";
423+
currentRule.add( new CssAtRule( reader, name + ';', true ) ); // directives like @charset "UTF-8";
424424
}
425425
return;
426426
// throw createException( "Unrecognized input: '" + name + "'" );
@@ -547,7 +547,7 @@ private void importFile( FormattableContainer currentRule, final String name ) {
547547
if( filename.contains( "@{" ) ) { // filename with variable name, we need to parse later
548548
if( currentRule != this ) {
549549
//import is inside of a mixin and will be process if the mixin will be process
550-
currentRule.add( new CssAtRule( reader, "@import " + name + ';' ) );
550+
currentRule.add( new CssAtRule( reader, "@import " + name + ';', true ) );
551551
return;
552552
}
553553
HashMap<String, Expression> importVariables = new DefaultedHashMap<>( variables );
@@ -562,13 +562,13 @@ private void importFile( FormattableContainer currentRule, final String name ) {
562562
}
563563
if( !isLess && !isInline && (isCss || filename.endsWith( "css" )) ) {
564564
// filenames ends with "css" will not be inline else a CSS @import directive is written
565-
currentRule.add( new CssAtRule( reader, "@import " + name + ';') );
565+
currentRule.add( new CssAtRule( reader, "@import " + name + ';', true ) );
566566
return;
567567
}
568568
baseURL = baseURL == null ? new URL( filename ) : new URL( baseURL, filename );
569569
if( !isLess && !isInline && baseURL.getPath().endsWith( "css" ) ) {
570570
// URL path ends with "css" will not be inline else a CSS @import directive is written
571-
currentRule.add( new CssAtRule( reader, "@import " + name + ';') );
571+
currentRule.add( new CssAtRule( reader, "@import " + name + ';', true ) );
572572
return;
573573
}
574574
if( "file".equals( baseURL.getProtocol() ) && filename.lastIndexOf( '.' ) <= filename.lastIndexOf( '/' ) ) {
@@ -585,7 +585,7 @@ private void importFile( FormattableContainer currentRule, final String name ) {
585585
if( isInline ) {
586586
Scanner scanner = new Scanner(importReader).useDelimiter( "\\A" );
587587
if( scanner.hasNext() ) {
588-
currentRule.add( new CssAtRule( reader, scanner.next() ) );
588+
currentRule.add( new CssAtRule( reader, scanner.next(), false ) );
589589
}
590590
} else {
591591
reader = new LessLookAheadReader( importReader, filename, isReference, isMultiple );
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
@media (min-width:600px) {
22
#css { color: yellow; }
33

4+
}
5+
@media (pointer: coarse) {
6+
.ql-snow.ql-toolbar button:hover:not(.ql-active),
47
}
58
this isn't very valid CSS.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
@media (pointer: coarse) {
2+
.ql-snow.ql-toolbar button:hover:not(.ql-active),
3+
}
14
this isn't very valid CSS.

0 commit comments

Comments
 (0)