Skip to content

Commit 905f749

Browse files
committed
handle supressed division on a property name level instead of a special unit leafo#196
1 parent 7c23653 commit 905f749

File tree

5 files changed

+51
-25
lines changed

5 files changed

+51
-25
lines changed

lessc.inc.php

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ class lessc {
7474
static protected $dtypes = array('expression', 'variable',
7575
'function', 'negative', 'list', 'lookup');
7676

77+
// these properties will supress division unless it's inside parenthases
78+
static protected $supressDivisionProps = array('/border-radius$/i', '/^font$/i');
79+
7780
/**
7881
* @link http://www.w3.org/TR/css3-values/
7982
*/
@@ -148,7 +151,7 @@ function parseChunk() {
148151

149152
// setting a property
150153
if ($this->keyword($key) && $this->assign() &&
151-
$this->propertyValue($value) && $this->end())
154+
$this->propertyValue($value, $key) && $this->end())
152155
{
153156
$this->append(array('assign', $key, $value), $s);
154157
return true;
@@ -382,6 +385,15 @@ function expHelper($lhs, $minP) {
382385

383386
// try to find a valid operator
384387
while ($this->match(self::$operatorString.($needWhite ? '\s' : ''), $m) && self::$precedence[$m[1]] >= $minP) {
388+
if (!$this->inParens && isset($this->env->currentProperty) && $m[1] == "/") {
389+
foreach (self::$supressDivisionProps as $pattern) {
390+
if (preg_match($pattern, $this->env->currentProperty)) {
391+
$this->env->supressedDivision = true;
392+
break 2;
393+
}
394+
}
395+
}
396+
385397
// get rhs
386398
$s = $this->seek();
387399
$p = $this->inParens;
@@ -421,8 +433,10 @@ function expHelper($lhs, $minP) {
421433
}
422434

423435
// consume a list of values for a property
424-
function propertyValue(&$value) {
436+
function propertyValue(&$value, $keyName=null) {
425437
$values = array();
438+
439+
if (!is_null($keyName)) $this->env->currentProperty = $keyName;
426440

427441
$s = null;
428442
while ($this->expressionList($v)) {
@@ -433,6 +447,8 @@ function propertyValue(&$value) {
433447

434448
if ($s) $this->seek($s);
435449

450+
if (!is_null($keyName)) unset($this->env->currentProperty);
451+
436452
if (count($values) == 0) return false;
437453

438454
$value = $this->compressList($values, ', ');
@@ -503,6 +519,15 @@ function value(&$value) {
503519
$this->seek($s);
504520
}
505521

522+
// the spare / when supressing division
523+
if (!empty($this->env->supressedDivision)) {
524+
unset($this->env->supressedDivision);
525+
if ($this->literal("/")) {
526+
$value = array('keyword', '/');
527+
return true;
528+
}
529+
}
530+
506531
return false;
507532
}
508533
@@ -601,25 +626,12 @@ function string(&$string, &$d = null) {
601626
* $allowed restricts the types that are matched.
602627
*/
603628
function unit(&$unit, $allowed = null) {
604-
$simpleCase = $allowed == null;
605629
if (!$allowed) $allowed = self::$units;
606630

607-
if ($this->match('(-?[0-9]*(\.)?[0-9]+)('.implode('|', $allowed).')?', $m, !$simpleCase)) {
631+
if ($this->match('(-?[0-9]*(\.)?[0-9]+)('.implode('|', $allowed).')?', $m)) {
608632
if (!isset($m[3])) $m[3] = 'number';
609633
$unit = array($m[3], $m[1]);
610634

611-
// check for size/height font unit.. should this even be here?
612-
if ($simpleCase) {
613-
$s = $this->seek();
614-
if (!$this->inExp && $this->literal('/', false) && $this->unit($right, self::$units)) {
615-
$unit = array('keyword', $this->compileValue($unit).'/'.$this->compileValue($right));
616-
} else {
617-
// get rid of whitespace
618-
$this->seek($s);
619-
$this->match('', $_);
620-
}
621-
}
622-
623635
return true;
624636
}
625637

tests/inputs/math.less

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,16 @@
2727
mul: 10 * 5;
2828
}
2929

30-
31-
.shorthand {
32-
// 10/5 is a special shorthand syntax that can be used in the font property
33-
div: 10/5; // outputs a literal 10/5
30+
// these properties have divison not in parenthases
31+
.supress-division {
32+
border-radius: 10px / 10px;
33+
border-radius: 10px/10px;
34+
border-radius: hello (10px/10px) world;
35+
@x: 10px;
36+
font: @x/30 sans-serif;
37+
font: 10px / 20px sans-serif;
38+
font: 10px/20px sans-serif;
39+
border-radius:0 15px 15px 15px / 0 50% 50% 50%;
3440
}
3541

3642

tests/inputs/variables.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
background: @light-blue;
2525
font-family: @fonts;
2626
margin: @m + 0px; // 3px
27-
font-size: 10px/12px;
28-
font-size: 120%/120%;
27+
font: 10px/12px serif;
28+
font: 120%/120% serif;
2929
}
3030

3131
.external {

tests/outputs/math.css

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@
88
mul:50;
99
mul:50;
1010
}
11-
.shorthand { div:10/5; }
11+
.supress-division {
12+
border-radius:10px / 10px;
13+
border-radius:10px / 10px;
14+
border-radius:hello(10px / 10px) world;
15+
font:10px / 30 sans-serif;
16+
font:10px / 20px sans-serif;
17+
font:10px / 20px sans-serif;
18+
border-radius:0 15px 15px 15px / 0 50% 50% 50%;
19+
}
1220
.parens {
1321
sub:5;
1422
add:15;

tests/outputs/variables.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ color:44px;
99
background:#6c94be;
1010
font-family:"Trebuchet MS", Verdana, sans-serif;
1111
margin:3px;
12-
font-size:10px/12px;
13-
font-size:120%/120%;
12+
font:10px / 12px serif;
13+
font:120% / 120% serif;
1414
}
1515
.external {
1616
color:#888888;

0 commit comments

Comments
 (0)