1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-07-26 08:11:17 +02:00

Use prettier on Shift+tab inside codemirror

This commit is contained in:
Kushagra Gour
2018-10-24 19:23:57 +05:30
parent 6361034933
commit 2091df6916
3 changed files with 35 additions and 3 deletions

View File

@@ -460,6 +460,27 @@ export function getFilenameFromUrl(url) {
return url.match(/\/([^/]*)$/)[1];
}
export function prettify(content, type = 'js') {
const prettier = require('prettier/standalone');
let plugins, parser;
if (type === 'js') {
parser = 'babylon';
plugins = [require('prettier/parser-babylon')];
} else if (type === 'css') {
parser = 'css';
plugins = [require('prettier/parser-postcss')];
}
if (!parser) {
return content;
}
const formattedContent = prettier.format(content, {
parser,
plugins
});
return formattedContent || content;
}
if (window.IS_EXTENSION) {
document.body.classList.add('is-extension');
} else {