Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Malformed tokens handling #12 #13

Merged
merged 6 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/rollup.config.mjs export-ignore
/tsconfig.json export-ignore
# exclude all files in test/ from stats
/rollup.config.mjs linguist-vendored
/test/** linguist-vendored
/docs/** linguist-vendored
/tools/** linguist-vendored
Expand Down
60 changes: 59 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ $ npm install @tbela99/css-parser
- efficient minification, see [benchmark](https://tbela99.github.io/css-parser/benchmark/index.html)
- replace @import at-rules with actual css content of the imported rule
- automatically generate nested css rules
- expand nested css
- works the same way in node and web browser

### Performance
Expand Down Expand Up @@ -160,7 +161,7 @@ Single JavaScript file
<script src="dist/index-umd-web.js"></script>
```

## Example
## Example 1

### Automatic CSS Nesting

Expand Down Expand Up @@ -216,6 +217,63 @@ table.colortable {
}
```

## Example 2

### Nested CSS Expansion

CSS

```css
table.colortable {
& td {
text-align: center;
&.c {
text-transform: uppercase
}
&:first-child,&:first-child+td {
border: 1px solid #000
}
}
& th {
text-align: center;
background: #000;
color: #fff
}
}
```

Javascript
```javascript
import {parse, render} from '@tbela99/css-parser';


const options = {minify: true};

const {code} = await parse(css, options).then(result => render(result.ast, {minify: false, expandNestingRules: true}));
//
console.debug(code);
```

Result

```css

table.colortable td {
text-align:center;
}
table.colortable td.c {
text-transform:uppercase;
}
table.colortable td:first-child, table.colortable td:first-child+td {
border:1px solid black;
}
table.colortable th {
text-align:center;
background:black;
color:white;
}
```

## AST

### Comment
Expand Down
49 changes: 49 additions & 0 deletions dist/config.json.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,55 @@ var map = {
"border-width": {
shorthand: "border"
},
overflow: {
shorthand: "overflow",
pattern: "overflow-x overflow-y",
keywords: [
"auto",
"visible",
"hidden",
"clip",
"scroll"
],
"default": [
],
mapping: {
"visible visible": "visible",
"auto auto": "auto",
"hidden hidden": "hidden",
"scroll scroll": "scroll"
},
properties: {
"overflow-x": {
"default": [
],
keywords: [
"auto",
"visible",
"hidden",
"clip",
"scroll"
]
},
"overflow-y": {
"default": [
],
keywords: [
"auto",
"visible",
"hidden",
"clip",
"scroll"
]
}
}
},
"overflow-x": {
shorthand: "overflow"
},
"overflow-y": {
shorthand: "overflow"
},
outline: {
shorthand: "outline",
pattern: "outline-color outline-style outline-width",
Expand Down
Loading