How to use the codemirror.findModeByExtension function in codemirror

To help you get started, we’ve selected a few codemirror examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github recca0120 / laravel-terminal / resources / assets / ts / commands / vim.ts View on Github external
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',
        };
    }
}
github recca0120 / laravel-terminal / resources / assets / js / commands / vi.js View on Github external
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',
        };
    }
github ZeroX-DG / SnippetStore / browser / render / modals / create-multi-files-snippet / index.jsx View on Github external
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}`)
    }
  }
github ZeroX-DG / SnippetStore / browser / render / modals / create-multi-files-snippet / index.jsx View on Github external
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',
github ZeroX-DG / SnippetStore / browser / store / SnippetStore.js View on Github external
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 {
github vscosta / yap-6.3 / misc / editors / codemirror / mode.js View on Github external
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;
github ZeroX-DG / SnippetStore / browser / render / components / code-editor / index.jsx View on Github external
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)
      }
github jupyterlab / jupyterlab / packages / codemirror / src / mode.ts View on Github external
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;
  }
}
github jupyterlab / jupyterlab / packages / codemirror / src / mode.ts View on Github external
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;
  }
}