Use mode instead of module

main
Andrew 7 years ago committed by Brian Dennis
parent 1500627c3b
commit f3b80b1783

@ -8,7 +8,8 @@ import toHash from 'tohash'
import WindowControls from '../components/WindowControls' import WindowControls from '../components/WindowControls'
import { COLORS, DEFAULT_LANGUAGE, LANGUAGES } from '../lib/constants' import { COLORS, DEFAULT_LANGUAGE, LANGUAGES } from '../lib/constants'
const LANGUAGE_HASH = toHash(LANGUAGES, 'module') const LANGUAGE_MODE_HASH = toHash(LANGUAGES, 'mode')
const LANGUAGE_NAME_HASH = toHash(LANGUAGES, 'short')
const DEFAULT_SETTINGS = { const DEFAULT_SETTINGS = {
paddingVertical: '50px', paddingVertical: '50px',
@ -56,10 +57,11 @@ class Carbon extends React.Component {
if (props.config.language === 'auto') { if (props.config.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 languageModule = LANGUAGE_HASH[detectedLanguage] const languageMode =
LANGUAGE_MODE_HASH[detectedLanguage] || LANGUAGE_NAME_HASH[detectedLanguage]
if (languageModule) { if (languageMode) {
this.setState({ language: languageModule.module }) this.setState({ language: languageMode.mime ? languageMode.mime : languageMode.mode })
} }
} else { } else {
this.setState({ language: props.config.language }) this.setState({ language: props.config.language })

@ -72,208 +72,209 @@ export const THEMES = toHash(THEMES_ARRAY)
export const LANGUAGES = [ export const LANGUAGES = [
{ {
name: 'Auto', name: 'Auto',
module: 'auto' mode: 'auto'
}, },
{ {
name: 'Plain Text' name: 'Plain Text'
}, },
{ {
name: 'C', name: 'C',
module: 'clike' mode: 'clike'
}, },
{ {
name: 'Clojure', name: 'Clojure',
module: 'clojure' mode: 'clojure'
}, },
{ {
name: 'Cobol', name: 'Cobol',
module: 'cobol' mode: 'cobol'
}, },
{ {
name: 'CoffeeScript', name: 'CoffeeScript',
module: 'coffeescript' mode: 'coffeescript'
}, },
{ {
name: 'Crystal', name: 'Crystal',
module: 'crystal' mode: 'crystal'
}, },
{ {
name: 'CSS', name: 'CSS',
module: 'css' mode: 'css'
}, },
{ {
name: 'D', name: 'D',
module: 'd' mode: 'd'
}, },
{ {
name: 'Dart', name: 'Dart',
module: 'dart' mode: 'dart'
}, },
{ {
name: 'Django', name: 'Django',
module: 'django' mode: 'django'
}, },
{ {
name: 'Docker', name: 'Docker',
module: 'dockerfile' mode: 'dockerfile'
}, },
{ {
name: 'Elm', name: 'Elm',
module: 'elm' mode: 'elm'
}, },
{ {
name: 'Erlang', name: 'Erlang',
module: 'erlang' mode: 'erlang'
}, },
{ {
name: 'Fortran', name: 'Fortran',
module: 'fortran' mode: 'fortran'
}, },
{ {
name: 'F# / OCaml', name: 'F# / OCaml',
module: 'mllike' mode: 'mllike'
}, },
{ {
name: 'Go', name: 'Go',
module: 'go' mode: 'go'
}, },
{ {
name: 'Groovy', name: 'Groovy',
module: 'groovy' mode: 'groovy'
}, },
{ {
name: 'Handlebars', name: 'Handlebars',
module: 'handlebars' mode: 'handlebars'
}, },
{ {
name: 'Haskell', name: 'Haskell',
module: 'haskell' mode: 'haskell'
}, },
{ {
name: 'Haxe', name: 'Haxe',
module: 'haxe' mode: 'haxe'
}, },
{ {
name: 'HTML', name: 'HTML',
module: 'htmlmixed' mode: 'htmlmixed'
}, },
{ {
name: 'JavaScript', name: 'JavaScript',
module: 'javascript' mode: 'javascript'
}, },
{ {
name: 'JSX', name: 'JSX',
module: 'jsx' mode: 'jsx'
}, },
{ {
name: 'Julia', name: 'Julia',
module: 'julia' mode: 'julia'
}, },
{ {
name: 'Kotlin', name: 'Kotlin',
module: 'text/x-kotlin', mode: 'clike',
mime: true mime: 'text/x-kotlin',
short: 'kotlin'
}, },
{ {
name: 'Lisp', name: 'Lisp',
module: 'commonlisp' mode: 'commonlisp'
}, },
{ {
name: 'Lua', name: 'Lua',
module: 'lua' mode: 'lua'
}, },
{ {
name: 'Markdown', name: 'Markdown',
module: 'markdown' mode: 'markdown'
}, },
{ {
name: 'Mathematica', name: 'Mathematica',
module: 'mathematica' mode: 'mathematica'
}, },
{ {
name: 'NGINX', name: 'NGINX',
module: 'nginx' mode: 'nginx'
}, },
{ {
name: 'Nim', name: 'Nim',
module: 'nimrod', mode: 'nimrod',
custom: true custom: true
}, },
{ {
name: 'Pascal', name: 'Pascal',
module: 'pascal' mode: 'pascal'
}, },
{ {
name: 'Perl', name: 'Perl',
module: 'perl' mode: 'perl'
}, },
{ {
name: 'PHP', name: 'PHP',
module: 'php' mode: 'php'
}, },
{ {
name: 'Python', name: 'Python',
module: 'python' mode: 'python'
}, },
{ {
name: 'R', name: 'R',
module: 'r' mode: 'r'
}, },
{ {
name: 'Ruby', name: 'Ruby',
module: 'ruby' mode: 'ruby'
}, },
{ {
name: 'Rust', name: 'Rust',
module: 'rust' mode: 'rust'
}, },
{ {
name: 'Sass', name: 'Sass',
module: 'sass' mode: 'sass'
}, },
{ {
name: 'Scala', name: 'Scala',
module: 'clike' mode: 'clike'
}, },
{ {
name: 'Smalltalk', name: 'Smalltalk',
module: 'smalltalk' mode: 'smalltalk'
}, },
{ {
name: 'SQL', name: 'SQL',
module: 'sql' mode: 'sql'
}, },
{ {
name: 'Swift', name: 'Swift',
module: 'swift' mode: 'swift'
}, },
{ {
name: 'TCL', name: 'TCL',
module: 'tcl' mode: 'tcl'
}, },
{ {
name: 'VB.NET', name: 'VB.NET',
module: 'vb' mode: 'vb'
}, },
{ {
name: 'Verilog', name: 'Verilog',
module: 'verilog' mode: 'verilog'
}, },
{ {
name: 'VHDL', name: 'VHDL',
module: 'vhdl' mode: 'vhdl'
}, },
{ {
name: 'Vue', name: 'Vue',
module: 'vue' mode: 'vue'
}, },
{ {
name: 'XML', name: 'XML',
module: 'xml' mode: 'xml'
}, },
{ {
name: 'YAML', name: 'YAML',
module: 'yaml' mode: 'yaml'
} }
] ]
@ -299,13 +300,14 @@ const unfold = (f, seed) => {
}` }`
if (typeof window !== 'undefined' && typeof window.navigator !== 'undefined') { if (typeof window !== 'undefined' && typeof window.navigator !== 'undefined') {
LANGUAGES const required = []
.filter(language => language.module !== 'auto')
.forEach((language) => { LANGUAGES.filter(language => language.mode !== 'auto').forEach(language => {
if (language.module && !language.mime) { if (language.mode && required.indexOf(language.mode) === -1) {
required.push(language.mode)
!language.custom !language.custom
? require(`codemirror/mode/${language.module}/${language.module}`) ? require(`codemirror/mode/${language.mode}/${language.mode}`)
: require(`./customModes/${language.module}`) : require(`./customModes/${language.mode}`)
} }
}) })
} }

@ -111,7 +111,8 @@ class Editor extends React.Component {
/> />
<Dropdown <Dropdown
list={LANGUAGES} list={LANGUAGES}
onChange={language => this.setState({ language: language.module })} onChange={language =>
this.setState({ language: language.mime ? language.mime : language.mode })}
/> />
<ColorPicker <ColorPicker
onChange={color => this.setState({ background: color })} onChange={color => this.setState({ background: color })}

Loading…
Cancel
Save