Fix language mime type lookup (#712)

* add editorconfig to keep files consistent automatically

* lookup language mime type in languages dictionary

* use language maps instead of language list

* Revert "add editorconfig to keep files consistent automatically"

This reverts commit 3cfdd4a5444791e763ffae59fde199406677f82f.

* move location of toLowerCase()
main
Konstantin Gorodinskiy 6 years ago committed by Michael Fix
parent 1378b619e4
commit eefc49b737

@ -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,

Loading…
Cancel
Save