From 8a3eeb1bdebb29c4394ced5275efc1868d0bce39 Mon Sep 17 00:00:00 2001 From: Janos Kis Date: Fri, 13 Apr 2018 11:11:02 +0100 Subject: [PATCH] Preserve whitespace after :not() selectors. Fixes #4 --- min.css.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/min.css.js b/min.css.js index 81b2961..51b61d8 100644 --- a/min.css.js +++ b/min.css.js @@ -41,7 +41,10 @@ function mincss (css) { return '#' + ((1 << 24) + ((1*r) << 16) + ((1*g) << 8) + (1*b)).toString(16).slice(1); } + var whiteSpacePlaceHolder = '|_|'; + return String(css) + .replace(/(:not\(.*?\))\s+(?!{)/g, '$1' + whiteSpacePlaceHolder) // Mark whitespace after :not() selectors for preservation .replace(/\/\*[\s\S]*?\*\//g, ' ') // Comments .replace(/\s+/g, ' ') // Extra spaces .replace(/^\s+/g, '') // Extra spaces @@ -112,6 +115,7 @@ function mincss (css) { .replace(/\:\s*calc\(([^;}]+)/g, function ($0) { // Repair CSS3 calc conditions return $0.replace(/\s+/g, "").replace(/([-+*/]+)/g, " $1 "); }) + .replace(/\|_\|/g, ' ') // Re-insert whitespaces that should be preserved ; }