1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-07-17 12:01:13 +02:00

add prettier for html support

This commit is contained in:
Kushagra Gour
2018-11-16 14:59:18 +05:30
parent f073413c89
commit 8b9fe4da3c
6 changed files with 30234 additions and 9 deletions

View File

@@ -222,8 +222,7 @@ export default class ContentWrap extends Component {
if (targetFrame.contentDocument.querySelector('#webmakerstyle')) {
targetFrame.contentDocument.querySelector(
'#webmakerstyle'
).textContent =
result.code || '';
).textContent = result.code || '';
}
});
} else {
@@ -752,6 +751,8 @@ export default class ContentWrap extends Component {
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
noAutocomplete: true,
matchTags: { bothTags: true },
prettier: true,
prettierParser: 'html',
emmet: true
}}
prefs={this.props.prefs}

View File

@@ -80,12 +80,13 @@ export default class UserCodeMirror extends Component {
CodeMirror.commands.goLineDown(editor);
},
'Shift-Tab': function(editor) {
CodeMirror.commands.indentAuto(editor);
},
'Shift-Ctrl-F': function(editor) {
if (options.prettier) {
prettify(editor.getValue(), options.prettierParser).then(
formattedCode => editor.setValue(formattedCode)
);
} else {
CodeMirror.commands.indentAuto(editor);
}
},
Tab: function(editor) {

View File

@@ -2,10 +2,14 @@ importScripts('./prettier/standalone.js');
function prettify({ content, type }) {
let plugins, parser;
if (type === 'js') {
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') {
}
else if (type === 'css') {
parser = 'css';
importScripts('./prettier/parser-postcss.js');
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -465,7 +465,7 @@ export function prettify(content, type = 'js') {
const worker = new Worker(
chrome.extension
? chrome.extension.getURL('lib/prettier-worker.js')
: `${BASE_PATH}/lib/prettier-worker.js`
: `${BASE_PATH === '/' ? '' : BASEPATH}/lib/prettier-worker.js`
);
worker.postMessage({ content, type });
worker.addEventListener('message', e => {