cerdic / csstidy Goto Github PK
View Code? Open in Web Editor NEWCSSTidy is a CSS minifier
License: GNU Lesser General Public License v2.1
CSSTidy is a CSS minifier
License: GNU Lesser General Public License v2.1
Hi,
I lost effect of @font-face rule from my perso.css when compressing css on my site (SPIP 3.2.11).
Regards.
Hi, I'm using this fork of CSSTidy for DirtyMarkup, as the original was abandoned, doesn't support media queries, etc. So thanks for your work on this project!
Quick feature request for indenting media queries. The current output looks like this:
@media (max-width: 767px) {
h1
font-size: 2em;
}
}
Desired output is:
@media (max-width: 767px) {
h1
font-size: 2em;
}
}
It looks like this would require a new formatter in the template files, or maybe it could be assumed that whatever the indent level is for properties could simply be doubled.
What are your thoughts on this?
subj
Hi,
I'm not sure whether this is the right place to report bugs, so feel free to point me elsewhere if needed. I have a very simple CSS file:
@keyframes blink {
0% { background: #7e7; }
50% { background: none; }
100% { background: #7e7; }
}
When throwing this file at CSSTidy, it gives me this result:
-----------------------------------
50% {
background:none;
}
100% {
background:#7e7;
}
-----------------------------------
1: Invalid @-rule: keyframes (removed)
2: Invalid property in CSS2.1: 0background
-----------------------------------
which is obviously not right, because @keyframes blink
is valid syntax, right?
Hi.
The compression changes 0s to 0 which is invalid in transition. for example:
transition: color 0.4s ease 0s;
will become
transition: color 0.4s ease 0;
which doesn't work
L'option reverse_left_and_right
ajoute un disgracieux autant qu'inutile right en reference quand on a une position center:
.foo {
background-position: center center;
}
devient :
.foo {
background-position: center right center;
}
I use cssmin which does too much with certain bootstrap.css'es (and evtl. also others - sometimes strange problems with some css'es)
How can i adjust csstidy , so that it just removes / *.... * / and //... and unecessary spaces and otherwise changes as little as possible - regarding code optimization ? The code may be a little bigger - i use mod_deflate anyway.
Composer #Fix52 "php": "^5.4.0 || ^7"
Prevents versions after 1.6.5 being installed in php > 8
I was using the CSSTidy C++ version to compress my CSS but this version had problem with format
in @font-face
. After taking a quick look to your up to date PHP version, I was thinking that this problem was fix in it (actually it's not fix, check my next issue).
So, I decided to use it instead of the C++ one. But I needed to call from the command line (like the C++ version) because I'm using it through django_compressor. The solution was to write a script to run it from the command line. I tried to do it in way that it will be mostly a drop in replacement of the C++ version.
You can found my script here: https://gist.github.com/2789689
It's NOT well tested and I don't think I will put more work on it because I can't use your CSSTidy PHP version for the moment. But feel free to do whatever you want with it, just keep my name in the credits please.
N.B.: I should add that the PHP and C++ versions are not totally equivalent. If I'm not wrong, the C++ version remove duplicate properties like this:
.duplicate{
display: none;
display: none;
}
The PHP version don't do that. I saw other differences like quotation around @font-face
font-family
name, etc.
CSSTidy remove all quotes around format
value in @font-face
except for the last format
but Firefox need the quotes. See this for more info: http://www.pixelastic.com/blog/86:csstidy-and-the-woff-fonts
And this fix: https://github.com/bombino/csstidy/blob/master/csstidy.php#L719
En utilisant une fonction de transformation rtl, on obtient :
Notice: Undefined offset: 1 in … class.csstidy_optimise.php on line 1286
Dans la méthode reverse_left_and_right_background_position($value)
$value = "0 0"
$values = []
La trace indique qu’on arrive avec background: #fff
, si ça peut aider...
^ array:27 [▼
0 => array:7 [▼
"file" => "class.csstidy_optimise.php"
"line" => 1234
"function" => "reverse_left_and_right_background_position"
"class" => "csstidy_optimise"
"object" => csstidy_optimise {#151 ▶}
"type" => "->"
"args" => array:1 [▼
0 => "0 0"
]
]
1 => array:7 [▼
"file" => "class.csstidy_optimise.php"
"line" => 1077
"function" => "reverse_left_and_right_background"
"class" => "csstidy_optimise"
"object" => csstidy_optimise {#151 ▶}
"type" => "->"
"args" => array:1 [▼
0 => "#fff"
]
]
2 => array:7 [▼
"file" => "class.csstidy_optimise.php"
"line" => 79
"function" => "reverse_left_and_right"
"class" => "csstidy_optimise"
"object" => csstidy_optimise {#151 ▶}
"type" => "->"
"args" => array:1 [▼
0 => array:9 [▼
"display" => "block"
"margin" => "0"
"padding" => "0"
"min-height" => "3.2em"
"background" => "#fff"
"border" => "1px solid #ddd"
"border-color" => "hsla(0,0%,0%,0.1)"
"border-bottom-color" => "hsla(0,0%,0%,0.05)"
"border-radius" => "6px 6px 0 0"
]
]
]
Hey! I see that CSSTidy is 5.4+ compliant, but what's the minimal PHP version supported?
I'm using PHP 5.1 (Don't ask), will it work with it?
class.csstidy.php
8192: Creation of dynamic property csstidy::$template is deprecated
Missing
public $template;
class.csstidy_optimise.php
Missing
public $css;
public $sub_value;
public $at;
public $selector;
public $property;
public $value;
class.csstidy_print.php
Missing
public $css;
public $template;
public $tokens;
public $charset;
public $import;
public $namespace;
The replacement definition for the ctype_alpha()
function is wrong. In its current state, it will only check for the existence of a letter in the checked string, but it does not check if ALL characters are letters.
It should be something like
function ctype_alpha( $text ) {
return ( 1 === preg_match( '/^[a-zA-Z]+$/', $text ) );
}
makes it easier to fail fast - on require in this case.
{
"require": {
"php": ">=5.3"
}
}
Or something along those lines
This is not an issue but noticed the $version member variable is still set to "1.5.2" instead of "1.5.5" (current version)
File: class.csstidy.php
Line #: 150
Currently:
public $version = '1.5.2';
Should be:
public $version = '1.5.5';
CSS Tidy generates these errors when running setting WP_DEBUG: TRUE.
csstidy has a deprecated constructor in /app/public/wp-content/plugins/wp-foft-loader/includes/csstidy/class.csstidy.php on line 61
csstidy_print has a deprecated constructor in /app/public/wp-content/plugins/wp-foft-loader/includes/csstidy/class.csstidy_print.php on line 39
csstidy_optimise has a deprecated constructor in /app/public/wp-content/plugins/wp-foft-loader/includes/csstidy/class.csstidy_optimise.php on line 39
Warning: Cannot modify header information - headers already sent by (output started at /path/to/plugin/includes/csstidy/class.csstidy_print.php:39) in /wp-includes/pluggable.php on line 1251
Warning: Cannot modify header information - headers already sent by (output started at /path/to/plugin/includes/csstidy/class.csstidy_print.php:39) in /wp-includes/pluggable.php on line 1254
I have found a security vulnerability and would like to inform you about it in a non-public way, but I couldn't find any current contact information anywhere. Is there an e-mail address I can write to?
The whole package is licensed with the LGPL, but in data.inc.php the quoted license is the standard GPL, which conflicts and actually makes it impossible for the whole package being LGPL.
Could you clear this up and correct the licensing for the whole package or the file?
First of all, it's great to see this project is still alive. I'm really enjoying the changes made after v1.3 :)
There's however a (new) minor issue with the "Remove unnecessary backslashes" checkbox.
Using this with a "custom layout", this feature simply doesn't work anymore. Also after submitting the "Process CSS" button it will automatically uncheck itself again.
On github, this tool has no release since 2019, thus it must be required with dev-main
when using it as aa dev dependency with composer.
The webiste, https://simpletest.org/, seems down, and https://simpletest.sourceforge.net/ is not really up-to-date :)
Can we consider replacing it with phpunit?
Normally the @import looks like this:
@import url("my.css");
When this runs through CSSTidy it changes it to:
@import "my.css";
HOWEVER, if you start with:
@import "my.css";
Then CSSTidy changes it to:
@import my.css;
Notice the double-quotes have been stripped. When this is done the imports no longer work.
This is a bug.
The fix can be found at PR #45
If I have an attribute selector, the whole CSS rule is deleted, because attribute selectors are not supported?
a[foo="warning"] {display: block;}
This outputs an empty array/string.
See test in https://github.com/Cerdic/CSSTidy/blob/master/testing/unit-tests/csst/selectors/attribute-equals.csst
@media print {
#navigation { display: none }
@media (max-width: 12cm) {
.note { float: none }
}
}
Produce
@media print {
#navigation
{
display:none
}
}
@media (max-width: 12cm) {
.note
{
float:none
}
}
Which is a mistake in CSS 3.0
I have csstidy 2.0.1 installed via composer. The command line executable is broken. The include path for class.csstidy.php is incorrect on line 42 of cerdic/css-tidy/bin/pcsstidy.
$ vendor/bin/pcsstidy --help
PHP Warning: include(class.csstidy.php): failed to open stream: No such file or directory in /var/www/html/dev/vendor/cerdic/css-tidy/bin/pcsstidy on line 42
PHP Stack trace:
PHP 1. {main}() /var/www/html/dev/vendor/bin/pcsstidy:0
PHP 2. include() /var/www/html/dev/vendor/bin/pcsstidy:112
PHP Warning: include(): Failed opening 'class.csstidy.php' for inclusion (include_path='.:/usr/share/php') in /var/www/html/dev/vendor/cerdic/css-tidy/bin/pcsstidy on line 42
PHP Stack trace:
PHP 1. {main}() /var/www/html/dev/vendor/bin/pcsstidy:0
PHP 2. include() /var/www/html/dev/vendor/bin/pcsstidy:112
PHP Fatal error: Uncaught Error: Class 'csstidy' not found in /var/www/html/dev/vendor/cerdic/css-tidy/bin/pcsstidy:43
Stack trace:
#0 /var/www/html/dev/vendor/bin/pcsstidy(112): include()
#1 {main}
thrown in /var/www/html/dev/vendor/cerdic/css-tidy/bin/pcsstidy on line 43
E.g. Bootstrap Glyphicons font-face.
Before:
@font-face {
font-family: 'Glyphicons Halflings';
src: url('../fonts/glyphicons-halflings-regular.eot');
src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'),
url('../fonts/glyphicons-halflings-regular.woff') format('woff'),
url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'),
url('../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
}
After (w/o minification for clarity)
@font-face {
font-family: "Glyphicons Halflings";
src: url("") format("embedded-opentype"),
url("../fonts/glyphicons-halflings-regular.woff") format("woff"),
url("../fonts/glyphicons-halflings-regular.ttf") format("truetype"),
url("") format("svg");
}
The problems:
@keyframes myanimation { 0% { opacity: 0; } 100% { opacity: 1; } }
loose the %
char in 0%
and make the rule fail in webkit
Hi there
I use CSS variables in my code and it shows the following log.
{"2":[{"m":"Removed invalid property: --color","t":"Warning"}]}
Is there any way to support CSS variables except turning off discard_invalid_properties
? Thanks!
Before
:root {
--color: red;
}
After
:root {}
I've sent you a couple of emails at your c****c@y******m
[redacted for your privacy] address regarding some possible security issues in the CSSTidy codebase. Did you get them?
I am glad the project is still maintained.
Interesting, that it still has the same bug as the original one, though.
You cannot use the class twice, for 2 css files in a row. the second file would always be empty upon parse():
$this->_Tidy->parse($content);
$css = $this->_Tidy->css;
...
unset($this->_Tidy); // try to avoid the bug by destroying
return $css;
in the second run with another script it returns an empty array.
thing is, If I switch the two files, the other one (now first) works fine.
So its definitly in the csstidy class somewhere
even destroying the object, unsetting the globals supervar etc won't help.
PS: would it be possible to rewrite it to not use $GLOBALS etc? I think the way of doing it this way and jumping outside its clean scope is not best practice anymore and should be avoided. the class can perfectly store the references inside some protected variables.
Hi, I found some bug.
the interval between "value" and "!important" vanishes.
For example,
a {color:red !important} becomes a {color:red!important}
Thanks for your great work :)
Hello, I love this tool, but don't know how to build for Windows. Is there any way you could upload v2.1.0 (or latest version)?
I found older version on SourceForge: https://sourceforge.net/projects/csstidy/
But it is not supporting CSS3 well.
In my css files I have relative URLs for background images and these get converted into absolute URL perfectly.
My problem is for font-face src, is it possible to also set this to be converted into absolute URL?
The reason for this is because my minified css file is saved in a different location to the original css files.
In following selector
/* ici */ .cartouche, .surlignable, /*.liste h2,*/ ul.liste-items li.hentry, p.pagination, #comments, p.repondre, .ps, .hyperlien, #descriptif_site_spip, .page_login .formulaire_spip, .page_login #formulaire_menu_lang, .resultats, .documents_joints, .chapo, .page_article .formulaire_ecrire_auteur { padding: 30px; }
/*.liste h2,*/
becomes /.liste h2,*/
and the rule is broken
Can easily cause extra white space to be outputted if left in.
http://drupal.org/node/1285886#comment-5046056
As a quick test I've tried using some css properties and notice that they are not in the data.inc.php file (sorry - don't know which CSS they relate to).
grid-area
grid-template-columns
grid-template-rows
grid-template-areas (important note - these require line breaks to be retained)
-ms-grid-columns
-ms-grid-column
-ms-grid-column-span
-ms-grid-rows
-ms-grid-row
-ms-flex-line-pack
align-content
-webkit-transition
-o-transition
-webkit-touch-callout
-webkit-user-select
-khtml-user-select
-moz-user-select
-ms-user-select
user-select
-webkit-appearance
When using " compress colors" option it does not recognize rgb() notation properly.
considering example :
white10 { color: rgba(255, 255, 255, 10%); }
white20 { color: rgb(255 255 255 / 20%); }
white30 { color: rgb(255, 255, 255, 30%); }
Output :
Optimised color: Changed "rgb(255 255 255 / 20%)" to "red"
Optimised color: Changed "rgb(255,255,255,30%)" to "#fff"
white10{color:rgba(255,255,255,10%)}
white20{color:red}
white30{color:#fff}
Should be:
white10{color:#ffffff1a}
white20{color:#fff3}
white30{color:#ffffff4d}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.