Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cssmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ function cssmin(css, linebreakpos) {
return m.replace(/\:/g, "___YUICSSMIN_PSEUDOCLASSCOLON___");
});

// Preserve spaces in calc expressions
css = css.replace(/calc\s*\(\s*(.*?)\s*\)/g, function (m, c) {
return m.replace(c, c.replace(/\s+/g, "___YUICSSMIN_SPACE_IN_CALC___"));
});

css = css.replace(/\s+([!{};:>+\(\)\],])/g, '$1');
css = css.replace(/___YUICSSMIN_PSEUDOCLASSCOLON___/g, ":");

Expand All @@ -258,6 +263,9 @@ function cssmin(css, linebreakpos) {
// Remove the spaces after the things that should not have spaces after them.
css = css.replace(/([!{}:;>+\(\[,])\s+/g, '$1');

// Restore preserved spaces in calc expressions
css = css.replace(/___YUICSSMIN_SPACE_IN_CALC___/g, " ");

// remove unnecessary semicolons
css = css.replace(/;+\}/g, "}");

Expand Down
6 changes: 6 additions & 0 deletions tests/files/preserve-space-calc.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.preserved {
width : calc ( 100% - 30px);
height: calc (80px + 10px + 10% );
top: calc(3px - 3px);
left: calc( 40% - 10% + 30% + 10px ) ;
}
1 change: 1 addition & 0 deletions tests/files/preserve-space-calc.css.min
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.preserved{width:calc(100% - 30px);height:calc(80px + 10px + 10%);top:calc(3px - 3px);left:calc(40% - 10% + 30% + 10px)}