Skip to content

Commit 1fd022f

Browse files
committed
Made readme more beutiful
1 parent b3d479f commit 1fd022f

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

README.md

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
# CSS Extractor
1+
![CSS Extractor Logo](assets/logo.png)
22

3-
The handiest script for UI development. Copy your favorite elements from the internet and get back `HTML` and `CSS` files that you can use and modify right away. No more manually copying and pasting elements from stylesheets.
3+
The handiest script for UI development. Copy your favorite elements from the internet and get back `HTML` and `CSS` files that you can use and modify right away. No more manually copying and pasting definitions from stylesheets.
44

55
## Installation
66

7-
1. Create a Python Virtual Environment
7+
1. **Create a Python Virtual Environment**
8+
89
You can use `conda` or something else, but this is the fastest for me.
910
```
1011
python -m venv /path/to/new/virtual/environment
1112
```
1213

13-
2. Download Dependencies
14+
2. **Download Dependencies**
15+
1416
Make sure to activate your virtual environment before running!
1517
```
1618
pip3 install -r requirements.txt
@@ -20,8 +22,9 @@ pip3 install -r requirements.txt
2022

2123
The extraction process is a 2-step process.
2224

23-
1. HTML Extraction
24-
We first analyze the input HTML markup and create a map of old classes to new ones.
25+
1. **HTML Extraction**
26+
27+
We first analyze the input HTML markup and create a map of old classes to new ones.
2528

2629
For example, if you have an HTML element like the following:
2730
```html
@@ -30,19 +33,23 @@ For example, if you have an HTML element like the following:
3033

3134
We would generate a mapping that is JSON-encoded like this:
3235
```json
36+
[
3337
{
3438
"newClass": "RANDOM_STRING_CLASS_NAME",
3539
"oldClasses": "big, red, slant"
3640
}
41+
]
3742
```
3843

3944
And produce an output HTML file like this:
4045
```html
4146
<h1 class="RANDOM_STRING_CLASS_NAME">This is a header</h1>
4247
```
4348

44-
2. CSS Extraction
45-
The JSON file generated in the previous step is then fed into the CSS extraction process, which builds our new class with all the styles from the old classes. The output class will have the old class names annotated in the CSS as comments for debugging purposes.
49+
2. **CSS Extraction**
50+
51+
The JSON file generated in the previous step is then fed into the CSS extraction process, which builds our new class with all the styles from the old classes. The output class will have the old class names annotated in the CSS as comments for debugging purposes.
52+
4653
```css
4754
.RANDOM_STRING_CLASS_NAME {
4855
/* big */
@@ -78,15 +85,15 @@ After years of manually extracting styles from websites I liked, I decided to cr
7885

7986
## How does it work?
8087

81-
The first iteration used regex to find and grab the CSS definitions from the desired input classes. However, this approach turned out to be problematic because CSS is complex, especially when you're dealing with @media queries and pseudo-selectors. There are still some leftover functions that use regex matching, as I didn't bother to rewrite them.
88+
The first iteration used regex to find and grab the CSS definitions from the desired input classes. However, this approach turned out to be problematic because CSS is complex, especially when you're dealing with `@media` queries and `pseudo-selectors`. There are still some leftover functions that use regex matching, as I didn't bother to rewrite them.
8289

83-
I eventually started using the `tinycss2` library, which parses CSS text into a format that can be programmatically analyzed. This is much better for handling @media queries and pseudo-selectors. This approach is a bit slow, as it involves many nested loops, and the library is not optimized for speed. Once we resolve the edge cases, we can focus on improving the program's performance.
90+
I eventually started using the `tinycss2` library, which parses CSS text into a format that can be programmatically analyzed. This is much better for handling `@media` queries and `pseudo-selectors`. This approach is a bit slow, as it involves many nested loops, and the library is not optimized for speed. Once we resolve the edge cases, we can focus on improving the program's performance.
8491

8592
## Caveats
8693

8794
- This is a very basic implementation, but it has served me well so far. There are certain edge cases that the library does not handle. For example, it struggles with nested classes (a child element within a parent element with a specific class). This nested class example will break the script.
8895

89-
- "Not" selectors and complex pseudo-selectors are also tricky and not detected. Feel free to open an issue for any bugs you encounter. If it's feasible, we'll fix them.
96+
- `Not` selectors and complex `pseudo-selectors` are also tricky and not detected. Feel free to open an issue for any bugs you encounter. If it's feasible, we'll fix them.
9097

9198
- The formatting of the output files is a bit janky. In the future, we can clean this up, but for now, it's easy enough to reformat CSS and HTML in a code editor or IDE.
9299

assets/logo.png

36.3 KB
Loading

0 commit comments

Comments
 (0)