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:
@@ -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}
|
||||
|
@@ -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) {
|
||||
|
@@ -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');
|
||||
}
|
||||
|
1
src/lib/prettier/parser-html.js
Normal file
1
src/lib/prettier/parser-html.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -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 => {
|
||||
|
Reference in New Issue
Block a user