From 481db7b5c46fc8f40350d9993b85b16fe09940c9 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Tue, 2 Jun 2020 18:03:39 -0700 Subject: [PATCH] chore: fallback if unable to format code --- src/components/ComponentExample.js | 44 ++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/src/components/ComponentExample.js b/src/components/ComponentExample.js index 7774f6bda..dae98b05a 100644 --- a/src/components/ComponentExample.js +++ b/src/components/ComponentExample.js @@ -8,20 +8,36 @@ import styles from './ComponentExample.module.scss'; const TRAILING_SEMI = /;\s*$/; -const ComponentExample = ({ className, example }) => ( -
-

{example.label}

- - - - - -
-); +const ComponentExample = ({ className, example }) => { + let formattedCode; + + try { + formattedCode = formatCode(example.sourceCode).replace(TRAILING_SEMI, ''); + } catch (e) { + formattedCode = example.sourceCode; + } + + return ( +
+

{example.label}

+ + + + + +
+ ); +}; ComponentExample.propTypes = { className: PropTypes.string,