diff --git a/components/Carbon.js b/components/Carbon.js index b4900e1..acdb112 100644 --- a/components/Carbon.js +++ b/components/Carbon.js @@ -11,6 +11,7 @@ import { COLORS, LANGUAGE_MODE_HASH, LANGUAGE_NAME_HASH, + LANGUAGE_MIME_HASH, THEMES_HASH, DEFAULT_SETTINGS } from '../lib/constants' @@ -19,6 +20,14 @@ const Watermark = dynamic(() => import('./svg/Watermark'), { loading: () => null }) +function searchLanguage(l) { + const config = LANGUAGE_NAME_HASH[l] || LANGUAGE_MODE_HASH[l] || LANGUAGE_MIME_HASH[l] + + if (config) { + return config.mime || config.mode + } +} + class Carbon extends React.PureComponent { static defaultProps = { onAspectRatioChange: () => {}, @@ -43,14 +52,19 @@ class Carbon extends React.PureComponent { if (language === 'auto') { // try to set the language const detectedLanguage = hljs.highlightAuto(newCode).language - const languageMode = - LANGUAGE_MODE_HASH[detectedLanguage] || LANGUAGE_NAME_HASH[detectedLanguage] + const languageMode = searchLanguage(detectedLanguage) if (languageMode) { - return languageMode.mime || languageMode.mode + return languageMode } } + const languageMode = searchLanguage(language) + + if (languageMode) { + return languageMode + } + return language }, ms('300ms'), @@ -69,7 +83,10 @@ class Carbon extends React.PureComponent { render() { const config = { ...DEFAULT_SETTINGS, ...this.props.config } - const languageMode = this.handleLanguageChange(this.props.children, config.language) + const languageMode = this.handleLanguageChange( + this.props.children, + config.language && config.language.toLowerCase() + ) const options = { lineNumbers: config.lineNumbers,