Skip to content

Commit

Permalink
Fix the slash handling of the "font" property. fix #32
Browse files Browse the repository at this point in the history
  • Loading branch information
Horcrux7 committed Feb 11, 2017
1 parent 9022b7c commit 5251396
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 32 deletions.
32 changes: 1 addition & 31 deletions src/com/inet/lib/less/CssFormatter.java
Expand Up @@ -759,44 +759,14 @@ void appendProperty( @Nonnull String name, @Nonnull Expression value ) {
name = SelectorUtils.replacePlaceHolder( this, name, value );
output.append( name ).append( ':' );
space();
if( "font".equals( name ) && value.getClass() == Operation.class ) {
appendFontPropertyValue( (Operation)value );
} else {
value.appendTo( this );
}
value.appendTo( this );
if( state.importantCount > 0 || value.isImportant() ) {
output.append( " !important" );
}
semicolon();
newline();
}

/**
* Special hack for property "font" which contains a value font-size/line-height
* @param value the value
*/
void appendFontPropertyValue( Operation value ) {
ArrayList<Expression> operands = value.getOperands();
char operator = value.getOperator();
switch( operator ) {
case '~':
case ',':
value.appendTo( this );
return;
}
for( int i = 0; i < operands.size(); i++ ) {
if( i > 0 ) {
this.append( operator );
}
Expression operand = operands.get( i );
if( operand.getClass() == Operation.class ) {
appendFontPropertyValue( (Operation)operand );
} else {
operand.appendTo( this );
}
}
}

/**
* Increment the important flag.
*/
Expand Down
16 changes: 16 additions & 0 deletions src/com/inet/lib/less/LessParser.java
Expand Up @@ -45,6 +45,10 @@
*/
class LessParser implements FormattableContainer {

private boolean strictMath;

private int nesting;

private URL baseURL;

private ReaderFactory readerFactory;
Expand Down Expand Up @@ -184,7 +188,9 @@ private void parseSemicolon( FormattableContainer currentRule ) {
continue LOOP;
}
String name = trim( builder );
strictMath = "font".equals( name );
Expression value = parseExpression( (char)0 );
strictMath = false;
ch = read();
switch( ch ) {
case '}': //last line in a block does not need a semicolon
Expand Down Expand Up @@ -784,6 +790,14 @@ private Expression parseExpression( char leftOperator ) {
}
switch( ch ) {
case '/':
if( strictMath && nesting == 0 ) {
if( wasWhite ) {
builder.append( ' ' );
wasWhite = false;
}
builder.append( ch );
continue LOOP;
}
if( comment( null ) ) {
continue LOOP;
}
Expand Down Expand Up @@ -979,7 +993,9 @@ Operation parseParameterList() {
Expression left = null;
char ch;
do {
nesting++;
Expression expr = parseExpression( (char)0 );
nesting--;
left = concat( left, ';', expr );
ch = read();
} while( ch == ';' );
Expand Down
1 change: 1 addition & 0 deletions test/com/inet/lib/less/samples/general/import.css
Expand Up @@ -9,6 +9,7 @@
f: a / b;
g: a / b;
h: a / b;
font: 3/2;
}
.values .slash2 {
background: url("img.jpg") center / 100px;
Expand Down
1 change: 1 addition & 0 deletions test/com/inet/lib/less/samples/general/importOptional.css
Expand Up @@ -5,6 +5,7 @@
f: a / b;
g: a / b;
h: a / b;
font: 3/2;
}
.slash2 {
background: url("img.jpg") center / 100px;
Expand Down
1 change: 1 addition & 0 deletions test/com/inet/lib/less/samples/general/slash.css
Expand Up @@ -5,6 +5,7 @@
f: a / b;
g: a / b;
h: a / b;
font: 3/2;
}
.slash2 {
background: url("img.jpg") center / 100px;
Expand Down
1 change: 1 addition & 0 deletions test/com/inet/lib/less/samples/general/slash.less
Expand Up @@ -7,6 +7,7 @@
f: a/ b;
g: a /b;
h: a/b;
font:3/2;
}
.slash2 {
background: url("img.jpg") center / 100px;
Expand Down
2 changes: 1 addition & 1 deletion test/com/inet/lib/less/samples/less_org_tests/less/css.css
Expand Up @@ -60,7 +60,7 @@ p + h1 {
#more-shorthands {
margin: 0;
padding: 1px 0 2px 0;
font: normal small / 20px 'Trebuchet MS', Verdana, sans-serif;
font: normal small/20px 'Trebuchet MS', Verdana, sans-serif;
font: 0/0 a;
border-radius: 0.5px;
}
Expand Down

0 comments on commit 5251396

Please sign in to comment.