Last change
on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
672 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | /**
|
---|
| 2 | * Module dependencies.
|
---|
| 3 | */
|
---|
| 4 | const postcss = require("postcss")
|
---|
| 5 | const valueParser = require("postcss-values-parser")
|
---|
| 6 | const color = "#639"
|
---|
| 7 | const regexp = /(^|[^\w-])rebeccapurple([^\w-]|$)/
|
---|
| 8 |
|
---|
| 9 | /**
|
---|
| 10 | * PostCSS plugin to convert colors
|
---|
| 11 | */
|
---|
| 12 | module.exports = postcss.plugin("postcss-color-rebeccapurple", () => (style) => {
|
---|
| 13 | style.walkDecls((decl) => {
|
---|
| 14 | const value = decl.value;
|
---|
| 15 |
|
---|
| 16 | if (value && regexp.test(value)) {
|
---|
| 17 | const valueAST = valueParser(value).parse()
|
---|
| 18 |
|
---|
| 19 | valueAST.walk(node => {
|
---|
| 20 | if (node.type === "word" && node.value === "rebeccapurple") {
|
---|
| 21 | node.value = color
|
---|
| 22 | }
|
---|
| 23 | })
|
---|
| 24 |
|
---|
| 25 | decl.value = valueAST.toString()
|
---|
| 26 | }
|
---|
| 27 | })
|
---|
| 28 | })
|
---|
Note:
See
TracBrowser
for help on using the repository browser.