Skip to content

Commit

Permalink
fix: prettier best effort
Browse files Browse the repository at this point in the history
closes #418
  • Loading branch information
Kikobeats committed Jun 18, 2019
1 parent 9b8a654 commit 4de7f96
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/elements/CodeEditor/CodeEditor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
import { prettier, getLines, serializeComponent } from 'helpers'
import styled, { css } from 'styled-components'
import { get, identity, range } from 'lodash'
import { prettier, getLines } from 'helpers'
import { Box } from 'components/elements'
import React, { useState } from 'react'
import CodeCopy from 'react-codecopy'
Expand Down
10 changes: 8 additions & 2 deletions src/helpers/prettier.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,14 @@ export const serializeObject = props => {
}, '')
}

const prettier = (code, opts) =>
prettierStandalone.format(code, { ...PRETTIER_CONFIG, ...opts })
const prettier = (code, opts) => {
try {
return prettierStandalone.format(code, { ...PRETTIER_CONFIG, ...opts })
} catch (err) {
return code
}
}

prettier.jsx = prettier.javascript = prettier.js = (code, opts) =>
prettier(code, { ...JS_OPTS, ...opts })
prettier.html = (code, opts) => prettier(code, { ...HTML_OPTS, ...opts })
Expand Down

0 comments on commit 4de7f96

Please sign in to comment.