Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private getModeByFile(file: string): any {
const matches = file.match(/.+\.([^.]+)$/);
if (matches.length > 0) {
return CodeMirror['findModeByExtension'](matches[1]);
}
if (/\//.test(file)) {
return CodeMirror['findModeByMIME'](file);
}
return {
mode: 'php',
mime: 'application/x-httpd-php',
};
}
}
info() {
const matches = this.file.match(/.+\.([^.]+)$/);
if (matches.length > 0) {
return CodeMirror.findModeByExtension(matches[1]);
}
if (/\//.test(this.file)) {
return CodeMirror.findModeByMIME(this.file);
}
return {
mode: 'php',
mime: 'application/x-httpd-php',
};
}
const wrapperElement = this.editor.getWrapperElement()
wrapperElement.style.fontFamily = fontFamily
const scrollElement = wrapperElement.querySelector('.CodeMirror-scroll')
scrollElement.style.maxHeight = '200px'
const FileList = this.refs.fileList
scrollElement.style.minHeight = `${FileList.clientHeight}px`
this.editor.refresh()
const totalSnippets = files.length
const file = files[selectedFile]
if (!file) {
this.handleChangeFileClick(totalSnippets - 1)
return
}
const fileExtension = getExtension(file.name)
const resultMode = CodeMirror.findModeByExtension(fileExtension)
let snippetMode = 'null'
if (resultMode) {
snippetMode = resultMode.mode
if (snippetMode === 'null') {
this.editor.setOption('mode', 'null')
this.editor.setOption('htmlMode', false)
return
}
require(`codemirror/mode/${snippetMode}/${snippetMode}`)
}
}
applyEditorLanguage (filename) {
const { config } = this.props
const langConf = config.language
const fileExtension = getExtension(filename)
const resultMode = CodeMirror.findModeByExtension(fileExtension)
if (resultMode) {
const snippetMode = resultMode.mode
if (snippetMode === 'null') {
this.editor.setOption('mode', 'null')
this.editor.setOption('htmlMode', false)
} else if (snippetMode === 'htmlmixed') {
require(`codemirror/mode/xml/xml`)
this.editor.setOption('mode', 'xml')
this.editor.setOption('htmlMode', true)
} else if (snippetMode === 'sql') {
require(`codemirror/mode/${snippetMode}/${snippetMode}`)
this.editor.setOption('mode', 'text/x-sql')
} else if (snippetMode === 'php') {
require(`codemirror/mode/${snippetMode}/${snippetMode}`)
this.editor.setOption('mode', {
name: 'php',
snippet.files.forEach(file => {
const ExtensionIndex = file.name.lastIndexOf('.') + 1
const fileExtension =
ExtensionIndex >= 2 ? file.name.substring(ExtensionIndex) : ''
const mode = CodeMirror.findModeByExtension(fileExtension)
let langName = fileExtension ? fileExtension.toUpperCase() : 'unknown'
if (mode) {
langName = mode.name
}
if (languages[langName]) {
languages[langName] += 1
} else {
languages[langName] = 1
}
})
} else {
function findByExtension(ext) {
if (typeof ext === 'string') {
return CodeMirror.findModeByExtension(name);
}
for (var i = 0; i < ext.length; i++) {
var mode = CodeMirror.findModeByExtension(ext[i]);
if (mode) {
return mode;
}
}
}
Mode.findByExtension = findByExtension;
onUpdateMultiFileSnippet () {
const { snippet, selectedFile, isEditing } = this.props
const { config } = this.props
const langConf = config.language
if (!isEditing) {
const file = snippet.files[selectedFile]
if (file) {
const fileExtension = getExtension(file.name)
const resultMode = CodeMirror.findModeByExtension(fileExtension)
let snippetMode = 'null'
if (resultMode) {
snippetMode = resultMode.mode
if (snippetMode && snippetMode !== 'null') {
require(`codemirror/mode/${snippetMode}/${snippetMode}`)
}
}
if (snippetMode === 'php') {
snippetMode = {
name: 'php',
startOpen: !langConf.php.requireOpenTag
}
}
this.editor.setOption('mode', snippetMode)
this.editor.setValue(file.value)
}
export function findByExtension(ext: string | string[]): ISpec | null {
if (typeof ext === 'string') {
return CodeMirror.findModeByExtension(name);
}
for (let i = 0; i < ext.length; i++) {
let mode = CodeMirror.findModeByExtension(ext[i]);
if (mode) {
return mode;
}
}
return null;
}
}
export function findByExtension(ext: string | string[]): ISpec | null {
if (typeof ext === 'string') {
return CodeMirror.findModeByExtension(name);
}
for (let i = 0; i < ext.length; i++) {
let mode = CodeMirror.findModeByExtension(ext[i]);
if (mode) {
return mode;
}
}
return null;
}
}