Skip to content

Commit 95a4d88

Browse files
committed
Interpret only variables in CSS function CSS. fix #52
1 parent a8bbebd commit 95a4d88

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* MIT License (MIT)
33
*
4-
* Copyright (c) 2014 - 2016 Volker Berlin
4+
* Copyright (c) 2014 - 2019 Volker Berlin
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -297,6 +297,11 @@ public void appendTo( CssFormatter formatter ) {
297297
case "range":
298298
range( formatter ).appendTo( formatter );
299299
return;
300+
case "calc":
301+
formatter.append( super.toString() ).append( '(' );
302+
SelectorUtils.appendToWithPlaceHolder( formatter, get( 0 ).stringValue( formatter ), 0, false, this );
303+
formatter.append( ')' );
304+
return;
300305
}
301306
if( type == UNKNOWN ) {
302307
eval( formatter );

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,15 @@ private Expression parseExpression( char leftOperator ) {
896896
op = parseParameterList();
897897
right = new Operation( reader, op.getOperands().get( 0 ), '~' );
898898
break;
899+
case "calc":
900+
ch = read();
901+
while( ch != ')' ) {
902+
builder.append( ch );
903+
ch = read();
904+
}
905+
op = new Operation( reader, new ValueExpression( reader, trim( builder ), Expression.STRING ), ';' );
906+
right = new FunctionExpression( reader, str, op );
907+
break;
899908
default:
900909
right = new FunctionExpression( reader, str, parseParameterList() );
901910
}

test/com/inet/lib/less/samples/general/minus.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@
2222
function2: - -3;
2323
function3: -floor(-2.3);
2424
function4: 3;
25+
calcWithSpace: calc(100% - 98px);
26+
calcCompact: calc(100%-98px);
27+
calcVariable: calc(90% -10px);
2528
}

test/com/inet/lib/less/samples/general/minus.less

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,10 @@
2323
function2: - floor(-2.3);
2424
function3: (-floor(-2.3));
2525
function4: (0-floor(-2.3));
26+
27+
calcWithSpace: calc(100% - 98px);
28+
calcCompact: calc(100%-98px);
29+
@a : 90%;
30+
@b : 10px;
31+
calcVariable: calc(@a -@b);
2632
}

0 commit comments

Comments
 (0)