-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
44 lines (41 loc) · 1.22 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const { parsers: typescriptParsers } = require('prettier/parser-typescript');
const { parsers: javascriptParsers } = require('prettier/parser-babel');
const { parsers: htmlParsers } = require('prettier/parser-html');
function preprocessClassName(text) {
const classNamePattern = /className\s*=\s*["']([^"']+)["']/g;
return text.replace(classNamePattern, (match, classNames) => {
const cleanClassNames = classNames.trim().replace(/\s+/g, ' ');
return `className="${cleanClassNames}"`;
});
}
function preprocessClass(text) {
const classPattern = /class\s*=\s*["']([^"']+)["']/g;
return text.replace(classPattern, (match, classNames) => {
const cleanClassNames = classNames.trim().replace(/\s+/g, ' ');
return `class="${cleanClassNames}"`;
});
}
module.exports = {
parsers: {
typescript: {
...typescriptParsers.typescript,
preprocess: preprocessClassName
},
babel: {
...javascriptParsers.babel,
preprocess: preprocessClassName
},
vue: {
...htmlParsers.html,
preprocess: preprocessClass
},
angular: {
...htmlParsers.html,
preprocess: preprocessClass
},
html: {
...htmlParsers.html,
preprocess: preprocessClass
}
}
};