How to use the codemirror.defineMode 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 probmods / webchurch / cm-church.js View on Github external
/**
 * Author: Koh Zi Han, based on implementation by Koh Zi Chun
 */

var CodeMirror = require('codemirror');

CodeMirror.defineMode("scheme", function () {
    var BUILTIN = "builtin", COMMENT = "comment", STRING = "string",
        ATOM = "atom", NUMBER = "number", BRACKET = "bracket";
    var INDENT_WORD_SKIP = 2;

    function makeKeywords(str) {
        var obj = {}, words = str.split(" ");
        for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
        return obj;
    }

    var keywords = makeKeywords("λ case-lambda call/cc class define-class exit-handler field import inherit init-field interface let*-values let-values let/ec mixin opt-lambda override protect provide public rename require require-for-syntax syntax syntax-case syntax-error unit/sig unless when with-syntax and begin call-with-current-continuation call-with-input-file call-with-output-file case cond define define-syntax delay do dynamic-wind else for-each if lambda let let* let-syntax letrec letrec-syntax map or syntax-rules abs acos angle append apply asin assoc assq assv atan boolean? caar cadr call-with-values car cdddar cddddr cdr ceiling char->integer char-alphabetic? char-ci<=? char-ci=? char-ci>? char-downcase char-lower-case? char-numeric? char-ready? char-upcase char-upper-case? char-whitespace? char<=? char=? char>? char? close-input-port close-output-port complex? cons cos current-input-port current-output-port denominator display eof-object? eq? equal? eqv? eval even? exact->inexact exact? exp expt #f floor force gcd imag-part inexact->exact inexact? input-port? integer->char integer? interaction-environment lcm length list list->string list->vector list-ref list-tail list? load log magnitude make-polar make-rectangular make-string make-vector max member memq memv min modulo negative? newline not null-environment null? number->string number? numerator odd? open-input-file open-output-file output-port? pair? peek-char port? positive? procedure? quasiquote quote quotient rational? rationalize read read-char real-part real? remainder reverse round scheme-report-environment set! set-car! set-cdr! sin sqrt string string->list string->number string->symbol string-append string-ci<=? string-ci=? string-ci>? string-copy string-fill! string-length string-ref string-set! string<=? string=? string>? string? substring symbol->string symbol? #t tan transcript-off transcript-on truncate values vector vector->list vector-fill! vector-length vector-ref vector-set! with-input-from-file with-output-to-file write write-char zero? barplot enumeration-query rejection-query mh-query condition factor fold flatten pair first second third fourth fifth sixth seventh rest flip hist repeat gaussian density multiviz uniform-draw mem sum runPhysics animatePhysics uniform worldWidth worldHeight scatter lineplot dirichlet multinomial beta mean");
    var indentKeys = makeKeywords("define let letrec let* lambda");

    function stateStack(indent, type, prev) { // represents a state stack object
        this.indent = indent;
        this.type = type;
github carbon-app / carbon / lib / custom / modes / apache.js View on Github external
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// Apache mode by gloony

const CodeMirror = require('codemirror')

CodeMirror.defineMode('apache', function(config) {
  return {
    token: function(stream, state) {
      var sol = stream.sol() || state.afterSection
      var eol = stream.eol()

      state.afterSection = false

      if (sol) {
        if (state.nextMultiline) {
          state.inMultiline = true
          state.nextMultiline = false
        } else {
          state.position = 'def'
        }
      }
github IceEnd / Yosoro / app / views / utils / cheers / mode / markdown.js View on Github external
import CodeMirror from 'codemirror';

/* eslint no-cond-assign: 0 */

CodeMirror.defineMode('markdown', (cmCfg, modeCfg) => {
  const htmlMode = CodeMirror.getMode(cmCfg, 'text/html');
  const htmlModeMissing = htmlMode.name === 'null';

  function getMode(name) {
    let current = name;
    if (CodeMirror.findModeByName) {
      const found = CodeMirror.findModeByName(current);
      if (found) {
        current = found.mime || found.mimes[0];
      }
    }
    const mode = CodeMirror.getMode(cmCfg, current);
    return mode.name === 'null' ? null : mode;
  }

  // Should characters that affect highlighting be highlighted separate?
github jupyterlab / jupyterlab / src / notebook / notebook / codemirror-ipython.ts View on Github external
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
'use strict';

import * as CodeMirror
  from 'codemirror';

import 'codemirror/mode/python/python';


/**
 * Define an IPython codemirror mode.
 *
 * It is a slightly altered Python Mode with a `?` operator.
 */
CodeMirror.defineMode('ipython', (config: CodeMirror.EditorConfiguration, modeOptions?: any) => {
    let pythonConf: any = {};
    for (var prop in modeOptions) {
      if (modeOptions.hasOwnProperty(prop)) {
        pythonConf[prop] = modeOptions[prop];
      }
    }
    pythonConf.name = 'python';
    pythonConf.singleOperators = new RegExp('^[\\+\\-\\*/%&|\\^~<>!\\?]');
    pythonConf.identifiers = new RegExp('^[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*');
    return CodeMirror.getMode(config, pythonConf);
});

CodeMirror.defineMIME('text/x-ipython', 'ipython');
github mathieudutour / kayero / src / hypermd / mode / hypermd.js View on Github external
/* eslint-disable camelcase, no-sequences, no-useless-escape */
import CodeMirror from 'codemirror'

// This is a patch to GFM mode. Supports:
// 1. footnote: style 'hmd-footnote'
// 2. bare link: e.g. 'please visit [page1] to continue', forwarding to footnote named as 'page1'

CodeMirror.defineMode('hypermd', function (config, modeConfig) {
  var hypermdOverlay = {
    startState () {
      return {
        atBeginning: true,  // at the beginning of one line, quotes are skipped
        insideCodeFence: false,
        inside: null, // 'link'
        prevLineIsEmpty: false,
        inList: false,
        extra: null   // reserved, works with 'inside'
        // when inside 'math', this is the token like `$` or `$$`
      }
    },
    copyState (s) {
      return {
        // structure of `s` is defined in startState; do a deep copy for it
        atBeginning: s.atBeginning,
github TriplyDB / YASGUI.YASQE / lib / grammar / tokenizer.js View on Github external
"use strict";
var CodeMirror = require("codemirror");
CodeMirror.defineMode("sparql11", function(config, parserConfig) {
  var indentUnit = config.indentUnit;

  var grammar = require("./_tokenizer-table.js");
  var ll1_table = grammar.table;

  var IRI_REF = '<[^<>"`\|\{\}\^\\\x00-\x20]*>';
  /*
	 * PN_CHARS_BASE =
	 * '[A-Z]|[a-z]|[\\u00C0-\\u00D6]|[\\u00D8-\\u00F6]|[\\u00F8-\\u02FF]|[\\u0370-\\u037D]|[\\u037F-\\u1FFF]|[\\u200C-\\u200D]|[\\u2070-\\u218F]|[\\u2C00-\\u2FEF]|[\\u3001-\\uD7FF]|[\\uF900-\\uFDCF]|[\\uFDF0-\\uFFFD]|[\\u10000-\\uEFFFF]';
	 */

  var PN_CHARS_BASE = "[A-Za-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD]";
  var PN_CHARS_U = PN_CHARS_BASE + "|_";

  var PN_CHARS = "(" + PN_CHARS_U + "|-|[0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040])";
  var VARNAME = "(" + PN_CHARS_U + "|[0-9])" + "(" + PN_CHARS_U + "|[0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040])*";
github neinteractiveliterature / intercode / app / javascript / Codemirror / LiquidMultiplexModes.js View on Github external
mode: CodeMirror.getMode(config, 'text/x-liquid'),
        delimStyle: 'liquid variable variable-2',
        innerStyle: 'liquid variable variable-2',
      },
      {
        open: '{%',
        close: '%}',
        mode: CodeMirror.getMode(config, 'text/x-liquid'),
        delimStyle: 'liquid variable-2 special keyword',
        innerStyle: 'liquid variable-2 special keyword',
      },
    )
  )
);

CodeMirror.defineMode('liquid-html', defineMultiplexingMode('text/html'));
CodeMirror.defineMode('liquid-markdown', defineMultiplexingMode('markdown'));
github swisnl / laravel-nova-mirror / resources / js / components / Form / CodeField.vue View on Github external
import 'codemirror/mode/php/php'
import 'codemirror/mode/ruby/ruby'
import 'codemirror/mode/shell/shell'
import 'codemirror/mode/sass/sass'
import 'codemirror/mode/yaml/yaml'
import 'codemirror/mode/yaml-frontmatter/yaml-frontmatter'
import 'codemirror/mode/nginx/nginx'
import 'codemirror/mode/xml/xml'
import 'codemirror/mode/vue/vue'
import 'codemirror/mode/dockerfile/dockerfile'
import 'codemirror/keymap/vim'
import 'codemirror/mode/sql/sql'
import 'codemirror/mode/twig/twig'
import 'codemirror/mode/htmlmixed/htmlmixed'

CodeMirror.defineMode('htmltwig', function(config, parserConfig) {
    return CodeMirror.overlayMode(
        CodeMirror.getMode(config, parserConfig.backdrop || 'text/html'),
        CodeMirror.getMode(config, 'twig')
    )
})

import { FormField, HandlesValidationErrors } from 'laravel-nova'

export default {
    mixins: [HandlesValidationErrors, FormField],

    data: () => ({ codemirror: null }),

    /**
     * Mount the component.
     */
github codemirror / google-modes / src / kotlin.js View on Github external
return indent(state, textAfter, line, this.indentConf)
  }
}

let meta = {
  electricInput: /^\s*[{}]$/,
  blockCommentStart: "/*",
  blockCommentEnd: "*/",
  blockCommentContinue: " * ",
  lineComment: "//",
  fold: "brace",
  closeBrackets: "()[]{}''\"\"``"
}
for (let prop in meta) KotlinMode.prototype[prop] = meta[prop]

CodeMirror.defineMode("google-kotlin", (conf, modeConf) => new KotlinMode(conf, modeConf))
github influxdata / influxdb / ui / src / external / codemirror.js View on Github external
CodeMirror.defineSimpleMode = function (name, states) {
  CodeMirror.defineMode(name, function (config) {
    return CodeMirror.simpleMode(config, states)
  })
}