11import _ from 'lodash'
22import * as Prism from 'prismjs/components/prism-core'
3- import prettier from 'prettier/standalone'
4- import babel from 'prettier/parser-babel'
5- import html from 'prettier/parser-html'
63import PropTypes from 'prop-types'
74import React from 'react'
85
@@ -16,19 +13,6 @@ import 'prismjs/components/prism-jsx'
1613
1714import CodeSnippetLabel from './CodeSnippetLabel'
1815
19- const prettierConfig = {
20- htmlWhitespaceSensitivity : 'ignore' ,
21- printWidth : 100 ,
22- tabWidth : 2 ,
23- semi : false ,
24- singleQuote : true ,
25- trailingComma : 'all' ,
26- plugins : {
27- babel,
28- html,
29- } ,
30- }
31-
3216const normalizeToString = ( value ) => {
3317 if ( Array . isArray ( value ) ) {
3418 return value . join ( '\n' )
@@ -37,22 +21,12 @@ const normalizeToString = (value) => {
3721 return _ . isObject ( value ) ? JSON . stringify ( value , null , 2 ) : value
3822}
3923
40- export const prettifyCode = ( code , parser ) => {
41- const formatted = prettier . format ( code , {
42- ...prettierConfig ,
43- // a narrower print width is more friendly to doc examples
44- parser,
45- } )
46-
47- return formatted . replace ( / ^ ; < / m, '<' ) // remove beginning semi in JSX/HTML
48- }
49-
5024const formatters = {
5125 bash : ( val = '' ) => val . replace ( / ^ [ \w ] / gm, '$$ $&' ) ,
52- json : ( val ) => prettifyCode ( val , 'json' ) ,
53- js : ( val = '' ) => prettifyCode ( val , 'babel' ) ,
54- jsx : ( val = '' ) => prettifyCode ( val , 'babel' ) ,
55- html : ( val = '' ) => prettifyCode ( val , 'html' ) ,
26+ json : ( val ) => val ,
27+ js : ( val = '' ) => val ,
28+ jsx : ( val = '' ) => val ,
29+ html : ( val = '' ) => val ,
5630}
5731
5832export const formatCode = ( code , mode ) => {
0 commit comments