Skip to content

Commit

Permalink
Fix Prettify for json (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinH authored and CompuIves committed Nov 12, 2017
1 parent ee5406c commit 43b960b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/app/components/sandbox/CodeEditor/Monaco.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,27 +521,20 @@ export default class CodeEditor extends React.Component<Props, State> {
const kind = title.match(/\.([^.]*)$/);

if (kind) {
if (kind[1] === 'css') {
return 'css';
}
if (kind[1] === 'scss') {
return 'scss';
} else if (kind[1] === 'html') {
return 'html';
} else if (kind[1] === 'vue') {
if (kind[1] === 'css') return 'css';
if (kind[1] === 'scss') return 'scss';
if (kind[1] === 'json') return 'json';
if (kind[1] === 'html') return 'html';
if (kind[1] === 'vue') {
if (!this.monaco.languages.getLanguages().find(l => l.id === 'vue')) {
await requireAMDModule(['vs/language/vue/monaco.contribution']);
}
return 'vue';
} else if (kind[1] === 'less') {
return 'less';
} else if (kind[1] === 'md') {
return 'markdown';
} else if (/jsx?$/.test(kind[1])) {
return 'javascript';
} else if (/tsx?$/.test(kind[1])) {
return 'typescript';
}
if (kind[1] === 'less') return 'less';
if (kind[1] === 'md') return 'markdown';
if (/jsx?$/.test(kind[1])) return 'javascript';
if (/tsx?$/.test(kind[1])) return 'typescript';
}

return 'typescript';
Expand Down Expand Up @@ -882,7 +875,12 @@ export default class CodeEditor extends React.Component<Props, State> {
const code = this.getCode();
const mode = await this.getMode(title);

if (mode === 'javascript' || mode === 'typescript' || mode === 'css') {
if (
mode === 'javascript' ||
mode === 'typescript' ||
mode === 'json' ||
mode === 'css'
) {
try {
const prettify = await import(/* webpackChunkName: 'prettier' */ 'app/utils/codemirror/prettify');
const newCode = await prettify.default(
Expand Down
1 change: 1 addition & 0 deletions src/app/utils/codemirror/prettify.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const worker = new Worker('/static/js/prettier/worker.js');

function getParser(mode) {
if (mode === 'jsx') return 'babylon';
if (mode === 'json') return 'json';
if (mode === 'css') return 'postcss';
if (mode === 'html') return 'parse5';
if (mode === 'typescript') return 'typescript';
Expand Down

0 comments on commit 43b960b

Please sign in to comment.