Jump to content

CSS minifier string manipulation


phpaliuk

Recommended Posts

Hi - for a CSS minifier I have, how do I find strings that match a pattern of:

}.[anytext].[anytext]{

and put a whitespace inbetween the fullstops, eg:-

}.class1.class2{ --> becomes --> }class1. class2{
}.name1.myname2.anothername3{ --> becomes --> }name1. myname2. anothername3{

Many thanks for your help,

Alex

 

Edited by Barand
add code tags
Link to comment
Share on other sites

You do know that ".class1.class2" and ".class1 .class2" mean two different things, right? Is the minifier buggy and incorrectly removing the space? Or is the source it's processing incorrect?

How about more of a description about what's going on, why you have this problem in the first place, and exactly what you need when you say "find strings that match a pattern of"?

Link to comment
Share on other sites

What minifier are you using? As requinix pointed out, `.class1.class2` is very different from `.class1 .class2` and if your minifier is adding or removing spaces like that it's broken. I always had good luck with cssmin if you're using gulp - I assume it's usable via webpack.

Link to comment
Share on other sites

I wrote the CSS minifier myself. It removes whitespace and newlines and comments, but because I don't know how to code a pattern matching for multiple classnames as posted, it removes whitespace from between the class names as well.

As mentioned, 'class1.class2' is different to '.class1 .class2'.

Is there a way to pattern match text between braces }xxx{ and replace .class1.class2...etc... with the space?

Edited by phpaliuk
Link to comment
Share on other sites

Given that you wrote the minifier yourself, it's going to be very hard for us to recommend anything given we have absolutely no idea what the minifier is or how it works. I mean, I can't even tell if it's written in PHP...

And on that note, why did you write it yourself? There are plenty of existing minifiers out there that don't have bugs like stripping significant whitespace.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.