Welcome! Log In Create A New Profile

Advanced

How to parse a .CSS style sheet file?

Posted by YogiYang 
How to parse a .CSS style sheet file?
March 26, 2021 07:30AM
Hello,

I have been tasked to create a parser which will parse a .CSS file and list all styles in three sections:
1. Those styles applicable to HTML tags
2. Those styles application to tag's ID
3. Those styles which are costume (that is they are applied only if Class element in added to a tag)

I have never done any parsing so I really not know as to how to proceed.

If anyone has tried their hands on parsing such complex document please to guide me here.

TIA

--
Yogi Yang
Argus
Re: How to parse a .CSS style sheet file?
March 26, 2021 12:35PM
First step is to manually analyse SEVERAL files to establish rules. You want to know what precisely identifies the elements you are looking for in the files (tags, delimiters, etc)

Once you have identified that your type 1 elements are between delimiterA and delimiterB, it's just a question of looking for those in the files in a loop, and that can be done quite easily with extractstring and similar functions.

After that, you need to test your code against as many files as you can, to check if any strange case is going to break your code
José Antonio
Re: How to parse a .CSS style sheet file?
March 26, 2021 01:11PM
Maybe, you could first convert it to JSON, with a converter like this:

[github.com]

And then work with the json to extract the data.
Re: How to parse a .CSS style sheet file?
April 03, 2021 09:08AM
Hello José,

Thanks for the link. It looks promising way to achieve what I want the list of all styles in a CSS.

I am currently experimenting with this but personally I still feel it would be better if this whole thing can be done in WD, instead of relying on something external.

TIA

--
Yogi Yang
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: