@@ -2,7 +2,10 @@ import PropTypes from 'prop-types';
2
2
import React from 'react' ;
3
3
import CodeMirror from 'codemirror' ;
4
4
import emmet from '@emmetio/codemirror-plugin' ;
5
- import beautifyJS from 'js-beautify' ;
5
+ import prettier from 'prettier' ;
6
+ import parserBabel from 'prettier/parser-babel' ;
7
+ import htmlParser from 'prettier/parser-html' ;
8
+ import cssParser from 'prettier/parser-postcss' ;
6
9
import { withTranslation } from 'react-i18next' ;
7
10
import 'codemirror/mode/css/css' ;
8
11
import 'codemirror/addon/selection/active-line' ;
@@ -59,14 +62,10 @@ import * as ConsoleActions from '../actions/console';
59
62
60
63
emmet ( CodeMirror ) ;
61
64
62
- const beautifyCSS = beautifyJS . css ;
63
- const beautifyHTML = beautifyJS . html ;
64
-
65
65
window . JSHINT = JSHINT ;
66
66
window . CSSLint = CSSLint ;
67
67
window . HTMLHint = HTMLHint ;
68
68
69
- const IS_TAB_INDENT = false ;
70
69
const INDENTATION_AMOUNT = 2 ;
71
70
72
71
class Editor extends React . Component {
@@ -337,23 +336,28 @@ class Editor extends React.Component {
337
336
}
338
337
339
338
tidyCode ( ) {
340
- const beautifyOptions = {
341
- indent_size : INDENTATION_AMOUNT ,
342
- indent_with_tabs : IS_TAB_INDENT
343
- } ;
344
339
const mode = this . _cm . getOption ( 'mode' ) ;
345
340
const currentPosition = this . _cm . doc . getCursor ( ) ;
346
341
if ( mode === 'javascript' ) {
347
342
this . _cm . doc . setValue (
348
- beautifyJS ( this . _cm . doc . getValue ( ) , beautifyOptions )
343
+ prettier . format ( this . _cm . doc . getValue ( ) , {
344
+ parser : 'babel' ,
345
+ plugins : [ parserBabel ]
346
+ } )
349
347
) ;
350
348
} else if ( mode === 'css' ) {
351
349
this . _cm . doc . setValue (
352
- beautifyCSS ( this . _cm . doc . getValue ( ) , beautifyOptions )
350
+ prettier . format ( this . _cm . doc . getValue ( ) , {
351
+ parser : 'css' ,
352
+ plugins : [ cssParser ]
353
+ } )
353
354
) ;
354
355
} else if ( mode === 'htmlmixed' ) {
355
356
this . _cm . doc . setValue (
356
- beautifyHTML ( this . _cm . doc . getValue ( ) , beautifyOptions )
357
+ prettier . format ( this . _cm . doc . getValue ( ) , {
358
+ parser : 'html' ,
359
+ plugins : [ htmlParser ]
360
+ } )
357
361
) ;
358
362
}
359
363
this . _cm . focus ( ) ;
0 commit comments