@ -11,6 +11,7 @@ import {
COLORS ,
COLORS ,
LANGUAGE _MODE _HASH ,
LANGUAGE _MODE _HASH ,
LANGUAGE _NAME _HASH ,
LANGUAGE _NAME _HASH ,
LANGUAGE _MIME _HASH ,
THEMES _HASH ,
THEMES _HASH ,
DEFAULT _SETTINGS
DEFAULT _SETTINGS
} from '../lib/constants'
} from '../lib/constants'
@ -19,6 +20,14 @@ const Watermark = dynamic(() => import('./svg/Watermark'), {
loading : ( ) => null
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 {
class Carbon extends React . PureComponent {
static defaultProps = {
static defaultProps = {
onAspectRatioChange : ( ) => { } ,
onAspectRatioChange : ( ) => { } ,
@ -43,14 +52,19 @@ class Carbon extends React.PureComponent {
if ( language === 'auto' ) {
if ( language === 'auto' ) {
// try to set the language
// try to set the language
const detectedLanguage = hljs . highlightAuto ( newCode ) . language
const detectedLanguage = hljs . highlightAuto ( newCode ) . language
const languageMode =
const languageMode = searchLanguage ( detectedLanguage )
LANGUAGE _MODE _HASH [ detectedLanguage ] || LANGUAGE _NAME _HASH [ detectedLanguage ]
if ( languageMode ) {
if ( languageMode ) {
return languageMode . mime || languageMode . mode
return languageMode
}
}
}
}
const languageMode = searchLanguage ( language )
if ( languageMode ) {
return languageMode
}
return language
return language
} ,
} ,
ms ( '300ms' ) ,
ms ( '300ms' ) ,
@ -69,7 +83,10 @@ class Carbon extends React.PureComponent {
render ( ) {
render ( ) {
const config = { ... DEFAULT _SETTINGS , ... this . props . config }
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 = {
const options = {
lineNumbers : config . lineNumbers ,
lineNumbers : config . lineNumbers ,