mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-17 03:51:13 +02:00
30 lines
628 B
JavaScript
30 lines
628 B
JavaScript
importScripts('./prettier/standalone.js');
|
|
|
|
function prettify({ content, type }) {
|
|
let plugins, parser;
|
|
if (type === 'html') {
|
|
importScripts('./prettier/parser-html.js');
|
|
parser = 'html';
|
|
}else if (type === 'js') {
|
|
parser = 'babylon';
|
|
importScripts('./prettier/parser-babylon.js');
|
|
}
|
|
else if (type === 'css') {
|
|
parser = 'css';
|
|
importScripts('./prettier/parser-postcss.js');
|
|
}
|
|
|
|
if (!parser) {
|
|
return content;
|
|
}
|
|
const formattedContent = prettier.format(content, {
|
|
parser,
|
|
plugins: self.prettierPlugins
|
|
});
|
|
return formattedContent || content;
|
|
}
|
|
|
|
onmessage = e => {
|
|
postMessage(prettify(e.data));
|
|
};
|