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:
21
src/utils.js
21
src/utils.js
@@ -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 {
|
||||
|
Reference in New Issue
Block a user