Skip to content

Commit

Permalink
Fix #168: CSS remove spaces inside var(--) statements
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Jan 25, 2024
1 parent ca64acc commit 4c881c2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,25 @@ public void compress(Writer out, int linebreakpos) throws IOException {
s = s.replaceAll("(?<=[-|%)pxemrvhw\\d])\\*", " * ");
s = s.replaceAll("(?<=[-|%)pxemrvhw\\d])/", " / ");
s = s.replaceAll("(var\\(-\\s-\\s)", "var(--");
s = s.replaceAll("\\)(var\\(--)", ") var(--"); // #168

m.appendReplacement(sb, s);
}
m.appendTail(sb);
css = sb.toString();

// #168 remove spaces inside "var(--month - margin)"
sb = new StringBuilder();
p = Pattern.compile("var\\(--[^;})]*\\)");
m = p.matcher(css);
while (m.find()) {
String s = m.group();
s = s.replaceAll("\\s+", "");
m.appendReplacement(sb, s);
}
m.appendTail(sb);
css = sb.toString();

// Trim the final string (for any leading or trailing white spaces)
css = css.trim();

Expand Down Expand Up @@ -602,4 +615,4 @@ public static String normalizeSpace(final String str) {
}
return new String(newChars, 0, count - (whitespacesCount > 0 ? 1 : 0)).trim();
}
}
}
3 changes: 0 additions & 3 deletions src/test/resources/bug158.css

This file was deleted.

1 change: 0 additions & 1 deletion src/test/resources/bug158.css.min

This file was deleted.

6 changes: 6 additions & 0 deletions src/test/resources/bug168.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a{
margin: 0 calc(var(--month-margin) / 2) var(--month-margin) 0;
min-height: calc((var(--duration) * (var(--month-height) + var(--month-margin)) - var(--month-margin)));
top: calc(var(--month-offset) * (var(--month-height) + var(--month-margin)));
width: calc(100% - 2 * var(--current-date - border));
}
1 change: 1 addition & 0 deletions src/test/resources/bug168.css.min
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a{margin:0 calc(var(--month-margin) / 2) var(--month-margin) 0;min-height:calc((var(--duration) * (var(--month-height) + var(--month-margin)) - var(--month-margin)));top:calc(var(--month-offset) * (var(--month-height) + var(--month-margin)));width:calc(100% - 2 * var(--current-date-border))}

0 comments on commit 4c881c2

Please sign in to comment.