Skip to content

Commit 9e3e2a2

Browse files
committed
add css nesting expansion #12
1 parent 6807478 commit 9e3e2a2

File tree

21 files changed

+5667
-4667
lines changed

21 files changed

+5667
-4667
lines changed

README.md

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ $ npm install @tbela99/css-parser
1616
- efficient minification, see [benchmark](https://tbela99.github.io/css-parser/benchmark/index.html)
1717
- replace @import at-rules with actual css content of the imported rule
1818
- automatically generate nested css rules
19+
- expand nested css
1920
- works the same way in node and web browser
2021

2122
### Performance
@@ -160,7 +161,7 @@ Single JavaScript file
160161
<script src="dist/index-umd-web.js"></script>
161162
```
162163

163-
## Example
164+
## Example 1
164165

165166
### Automatic CSS Nesting
166167

@@ -216,6 +217,63 @@ table.colortable {
216217
}
217218
```
218219

220+
## Example 2
221+
222+
### Nested CSS Expansion
223+
224+
CSS
225+
226+
```css
227+
table.colortable {
228+
& td {
229+
text-align: center;
230+
&.c {
231+
text-transform: uppercase
232+
}
233+
&:first-child,&:first-child+td {
234+
border: 1px solid #000
235+
}
236+
}
237+
& th {
238+
text-align: center;
239+
background: #000;
240+
color: #fff
241+
}
242+
}
243+
```
244+
245+
Javascript
246+
```javascript
247+
import {parse, render} from '@tbela99/css-parser';
248+
249+
250+
const options = {minify: true};
251+
252+
const {code} = await parse(css, options).then(result => render(result.ast, {minify: false, expandNestingRules: true}));
253+
//
254+
console.debug(code);
255+
```
256+
257+
Result
258+
259+
```css
260+
261+
table.colortable td {
262+
text-align:center;
263+
}
264+
table.colortable td.c {
265+
text-transform:uppercase;
266+
}
267+
table.colortable td:first-child, table.colortable td:first-child+td {
268+
border:1px solid black;
269+
}
270+
table.colortable th {
271+
text-align:center;
272+
background:black;
273+
color:white;
274+
}
275+
```
276+
219277
## AST
220278

221279
### Comment

0 commit comments

Comments
 (0)