|
|
|
@ -4,8 +4,11 @@ import React from 'react'
|
|
|
|
|
import domtoimage from 'dom-to-image'
|
|
|
|
|
import CodeMirror from 'react-codemirror'
|
|
|
|
|
import Spinner from 'react-spinner'
|
|
|
|
|
import toHash from 'tohash'
|
|
|
|
|
import WindowControls from '../components/WindowControls'
|
|
|
|
|
import { COLORS, DEFAULT_LANGUAGE, LANGUAGE_HASH } from '../lib/constants'
|
|
|
|
|
import { COLORS, DEFAULT_LANGUAGE, LANGUAGES } from '../lib/constants'
|
|
|
|
|
|
|
|
|
|
const LANGUAGE_HASH = toHash(LANGUAGES, 'module')
|
|
|
|
|
|
|
|
|
|
const DEFAULT_SETTINGS = {
|
|
|
|
|
paddingVertical: '50px',
|
|
|
|
@ -50,13 +53,13 @@ class Carbon extends React.Component {
|
|
|
|
|
handleLanguageChange(newCode, config) {
|
|
|
|
|
const props = (config && config.customProps) || this.props
|
|
|
|
|
|
|
|
|
|
if (props.config.language.name === 'Auto') {
|
|
|
|
|
if (props.config.language === 'auto') {
|
|
|
|
|
// try to set the language
|
|
|
|
|
const detectedLanguage = hljs.highlightAuto(newCode).language
|
|
|
|
|
const languageModule = LANGUAGE_HASH[detectedLanguage]
|
|
|
|
|
|
|
|
|
|
if (languageModule) {
|
|
|
|
|
this.setState({ language: languageModule })
|
|
|
|
|
this.setState({ language: languageModule.module })
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.setState({ language: props.config.language })
|
|
|
|
@ -68,7 +71,7 @@ class Carbon extends React.Component {
|
|
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
|
lineNumbers: false,
|
|
|
|
|
mode: this.state.language ? this.state.language.module : 'plaintext',
|
|
|
|
|
mode: this.state.language || 'plaintext',
|
|
|
|
|
theme: config.theme,
|
|
|
|
|
scrollBarStyle: null,
|
|
|
|
|
viewportMargin: Infinity,
|
|
|
|
|