I want to break the contents of a CSS file into blocks of code and insert each block of code into a list using Python 3.5.
So, given this CSS:
h1 {color: #333, background-color: transparent} h2 { font-weight:300 } h3 { font-weight: 200 }
We can clearly say that it has several styles and / or indent types, which means that CSS needs to be put in order:
h1 { color: #333,background-color: transparent; } h2 { font-weight: 300; } h3 { font-weight: 200; }
How can I use Python to read an ordered CSS string and insert each block of code inside it into a Python list as follows:
styles = [ "h1 {\n color: #333,background-color: transparent;\n}", "h2 {\n font-weight: 300;\n}", "h3 {\n font-weight: 200;\n}" ]
I would also like to point out that RegExp is actually not my forte, and I'm not quite sure what to use RegEx, but I thought I could use RegExp and [].split(...); to achieve this.
Itβs even possible to use RegExp to get rid of the need to pick up a stylesheet before splitting code blocks in it.
NOTE. I checked this question, but unfortunately it didnβt help either.
user5870134
source share