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:
@@ -12,7 +12,7 @@ import CssSettingsModal from './CssSettingsModal';
|
|||||||
const minCodeWrapSize = 33;
|
const minCodeWrapSize = 33;
|
||||||
|
|
||||||
/* global htmlCodeEl, jsCodeEl, cssCodeEl, logCountEl
|
/* global htmlCodeEl, jsCodeEl, cssCodeEl, logCountEl
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export default class ContentWrap extends Component {
|
export default class ContentWrap extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -222,8 +222,7 @@ export default class ContentWrap extends Component {
|
|||||||
if (targetFrame.contentDocument.querySelector('#webmakerstyle')) {
|
if (targetFrame.contentDocument.querySelector('#webmakerstyle')) {
|
||||||
targetFrame.contentDocument.querySelector(
|
targetFrame.contentDocument.querySelector(
|
||||||
'#webmakerstyle'
|
'#webmakerstyle'
|
||||||
).textContent =
|
).textContent = result.code || '';
|
||||||
result.code || '';
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -752,6 +751,8 @@ export default class ContentWrap extends Component {
|
|||||||
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
|
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
|
||||||
noAutocomplete: true,
|
noAutocomplete: true,
|
||||||
matchTags: { bothTags: true },
|
matchTags: { bothTags: true },
|
||||||
|
prettier: true,
|
||||||
|
prettierParser: 'html',
|
||||||
emmet: true
|
emmet: true
|
||||||
}}
|
}}
|
||||||
prefs={this.props.prefs}
|
prefs={this.props.prefs}
|
||||||
|
@@ -80,12 +80,13 @@ export default class UserCodeMirror extends Component {
|
|||||||
CodeMirror.commands.goLineDown(editor);
|
CodeMirror.commands.goLineDown(editor);
|
||||||
},
|
},
|
||||||
'Shift-Tab': function(editor) {
|
'Shift-Tab': function(editor) {
|
||||||
|
CodeMirror.commands.indentAuto(editor);
|
||||||
|
},
|
||||||
|
'Shift-Ctrl-F': function(editor) {
|
||||||
if (options.prettier) {
|
if (options.prettier) {
|
||||||
prettify(editor.getValue(), options.prettierParser).then(
|
prettify(editor.getValue(), options.prettierParser).then(
|
||||||
formattedCode => editor.setValue(formattedCode)
|
formattedCode => editor.setValue(formattedCode)
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
CodeMirror.commands.indentAuto(editor);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Tab: function(editor) {
|
Tab: function(editor) {
|
||||||
|
@@ -2,10 +2,14 @@ importScripts('./prettier/standalone.js');
|
|||||||
|
|
||||||
function prettify({ content, type }) {
|
function prettify({ content, type }) {
|
||||||
let plugins, parser;
|
let plugins, parser;
|
||||||
if (type === 'js') {
|
if (type === 'html') {
|
||||||
|
importScripts('./prettier/parser-html.js');
|
||||||
|
parser = 'html';
|
||||||
|
}else if (type === 'js') {
|
||||||
parser = 'babylon';
|
parser = 'babylon';
|
||||||
importScripts('./prettier/parser-babylon.js');
|
importScripts('./prettier/parser-babylon.js');
|
||||||
} else if (type === 'css') {
|
}
|
||||||
|
else if (type === 'css') {
|
||||||
parser = 'css';
|
parser = 'css';
|
||||||
importScripts('./prettier/parser-postcss.js');
|
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(
|
const worker = new Worker(
|
||||||
chrome.extension
|
chrome.extension
|
||||||
? chrome.extension.getURL('lib/prettier-worker.js')
|
? 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.postMessage({ content, type });
|
||||||
worker.addEventListener('message', e => {
|
worker.addEventListener('message', e => {
|
||||||
|
Reference in New Issue
Block a user