|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.3 KB
|
| Rev | Line | |
|---|
| [9af201e] | 1 | 'use strict';
|
|---|
| 2 | const charset = 'charset';
|
|---|
| 3 | // eslint-disable-next-line no-control-regex
|
|---|
| 4 | const nonAscii = /[^\x00-\x7F]/;
|
|---|
| 5 |
|
|---|
| 6 | /**
|
|---|
| 7 | * @typedef {{add?: boolean}} Options
|
|---|
| 8 | */
|
|---|
| 9 | /**
|
|---|
| 10 | * @type {import('postcss').PluginCreator<Options>}
|
|---|
| 11 | * @param {Options} opts
|
|---|
| 12 | * @return {import('postcss').Plugin}
|
|---|
| 13 | */
|
|---|
| 14 | function pluginCreator(opts = {}) {
|
|---|
| 15 | return {
|
|---|
| 16 | postcssPlugin: 'postcss-normalize-' + charset,
|
|---|
| 17 |
|
|---|
| 18 | OnceExit(css, { AtRule }) {
|
|---|
| 19 | /** @type {import('postcss').AtRule | undefined} */
|
|---|
| 20 | let charsetRule;
|
|---|
| 21 | /** @type {import('postcss').Node | undefined} */
|
|---|
| 22 | let nonAsciiNode;
|
|---|
| 23 |
|
|---|
| 24 | css.walk((node) => {
|
|---|
| 25 | if (node.type === 'atrule' && node.name === charset) {
|
|---|
| 26 | if (!charsetRule) {
|
|---|
| 27 | charsetRule = node;
|
|---|
| 28 | }
|
|---|
| 29 | node.remove();
|
|---|
| 30 | } else if (
|
|---|
| 31 | !nonAsciiNode &&
|
|---|
| 32 | node.parent === css &&
|
|---|
| 33 | nonAscii.test(node.toString())
|
|---|
| 34 | ) {
|
|---|
| 35 | nonAsciiNode = node;
|
|---|
| 36 | }
|
|---|
| 37 | });
|
|---|
| 38 |
|
|---|
| 39 | if (nonAsciiNode) {
|
|---|
| 40 | if (!charsetRule && opts.add !== false) {
|
|---|
| 41 | charsetRule = new AtRule({
|
|---|
| 42 | name: charset,
|
|---|
| 43 | params: '"utf-8"',
|
|---|
| 44 | });
|
|---|
| 45 | }
|
|---|
| 46 | if (charsetRule) {
|
|---|
| 47 | charsetRule.source = nonAsciiNode.source;
|
|---|
| 48 | css.prepend(charsetRule);
|
|---|
| 49 | }
|
|---|
| 50 | }
|
|---|
| 51 | },
|
|---|
| 52 | };
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | pluginCreator.postcss = true;
|
|---|
| 56 | module.exports = pluginCreator;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.