How to use the codemirror.getMode 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 medialab / aime-core / interfaces / admin / js / lib / custom_mode.js View on Github external
CodeMirror.defineMode("aime-markdown", function(cmCfg, modeCfg) {

  var htmlFound = CodeMirror.modes.hasOwnProperty("xml");
  var htmlMode = CodeMirror.getMode(cmCfg, htmlFound ? {name: "xml", htmlMode: true} : "text/plain");

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

  // Should characters that affect highlighting be highlighted separate?
  // Does not include characters that will be output (such as `1.` and `-` for lists)
  if (modeCfg.highlightFormatting === undefined)
    modeCfg.highlightFormatting = false;

  // Maximum number of nested blockquotes. Set to 0 for infinite nesting.
github swimlane / ngx-ui / projects / swimlane / ngx-ui / src / lib / components / code-editor / mustache.ts View on Github external
if (stream.match('{{')) {
        // tslint:disable-next-line:no-conditional-assignment
        while ((ch = stream.next()) != null)
          if (ch === '}' && stream.next() === '}') {
            stream.eat('}');
            return 'mustache';
          }
      }
      while (stream.next() != null && !stream.match('{{', false)) {
        continue;
      }

      return null;
    }
  };
  return CodeMirror.overlayMode(CodeMirror.getMode(config, parserConfig.backdrop || 'text/html'), mustacheOverlay);
});
github IceEnd / Yosoro / app / views / utils / cheers / mode / markdown.js View on Github external
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?
  // Does not include characters that will be output (such as `1.` and `-` for lists)
github iodide-project / iodide / src / editor / components / codemirror-iomd-mode.js View on Github external
import "codemirror/mode/javascript/javascript";
import "codemirror/mode/markdown/markdown";
import "codemirror/mode/css/css";
import "codemirror/mode/htmlmixed/htmlmixed";
// FIXME perhaps python should only load if used, but this is fine for now
import "codemirror/mode/python/python";

export const delimLineRegex = /^%%\s*(\w*)/;

const innerModes = {
  js: CodeMirror.getMode(
    { indentUnit: 2, statementIndent: 2 },
    { name: "javascript" }
  ),
  py: CodeMirror.getMode(
    { indentUnit: 4, hangingIndent: 4 },
    { name: "python" }
  ),
  md: CodeMirror.getMode({}, { name: "markdown" }),
  css: CodeMirror.getMode({ indentUnit: 2 }, { name: "css" }),
  raw: CodeMirror.getMode({}, { name: "text/plain" }),
  fetch: CodeMirror.getMode({}, { name: "fetch" })
};
innerModes.raw.startState = () => null;

CodeMirror.defineMode("iomd", () => ({
  startState: () => ({
    localMode: innerModes.raw,
    localState: null
  }),
  token: (stream, state) => {
github antimatter15 / gayfish / src / codemirror / jsx.js View on Github external
CodeMirror.defineMode("jsx", function(config, parserConfig) {
  var jsMode = CodeMirror.getMode(config, "javascript");
  var xmlMode =  CodeMirror.getMode(config, {name: "xml", htmlMode: true});

  function js(stream, state) {
    if ((state.jsState.lastType == "operator"
         || state.jsState.lastType == "keyword c"
         || state.jsState.lastType == "=>"
         || /^[\[{}\(,;:]$/.test(state.jsState.lastType))
        && stream.match(/^<[a-zA-Z]+/i, false)) {
      state.token = xml;
      return xmlMode.token(stream, state.localState);
      state.localState = xmlMode.startState(jsMode.indent(state.jsState, ""));
      state.localMode = xmlMode;
      state.indented = stream.backUp(1);
      return xml(stream, state);
    }
    return jsMode.token(stream, state.jsState);;
github swisnl / laravel-nova-mirror / resources / js / components / Detail / CodeField.vue View on Github external
CodeMirror.defineMode('htmltwig', function(config, parserConfig) {
    return CodeMirror.overlayMode(
        CodeMirror.getMode(config, parserConfig.backdrop || 'text/html'),
        CodeMirror.getMode(config, 'twig')
    )
})
github bijection / nearley-playground / src / client / editor.js View on Github external
CodeMirror.defineMode("nearley", config => 
    CodeMirror.multiplexingMode(
        CodeMirror.getMode(config, "ebnf"),
        {   
            open: "{%",
            close: "%}",
            mode: CodeMirror.getMode(config, "javascript"),
            delimStyle: "js-delimit"
        },
        {   
            open: /^\s*#/,
            close: /.*$/,
            mode: CodeMirror.getMode(config, "text/plain"),
            delimStyle: "comment-delimit"
        }
    )
)
github nhn / tui.editor / src / js / codemirror / gfm.js View on Github external
stream.next();
      return null;
    },
    blankLine: blankLine
  };

  var markdownConfig = {
    taskLists: true,
    strikethrough: true,
    emoji: true
  };
  for (var attr in modeConfig) {
    markdownConfig[attr] = modeConfig[attr];
  }
  markdownConfig.name = "markdown";
  return CodeMirror.overlayMode(CodeMirror.getMode(config, markdownConfig), gfmOverlay);

}, "markdown");
github osmlab / learnoverpass / themes / src / scripts / codemirror-ql-mode.js View on Github external
CodeMirror.defineMode("ql+mustache", function(config) {
      return CodeMirror.multiplexingMode(
          CodeMirror.multiplexingMode(
              CodeMirror.getMode(config, "text/x-overpassQL"),
              {open: "{{", close:"}}",
                mode:CodeMirror.getMode(config, "text/plain"),
                delimStyle: "mustache"}
          ),
          {open: "{{style:", close: "}}",
            mode: CodeMirror.getMode(config, "text/css"),
            delimStyle: "mustache"}
      );
  });
github Kong / insomnia / packages / insomnia-app / app / ui / components / codemirror / modes / nunjucks.js View on Github external
CodeMirror.defineMode('nunjucks', (config, parserConfig) => {
  const baseMode = CodeMirror.getMode(config, parserConfig.baseMode || 'text/plain');
  const nunjucksMode = _nunjucksMode();
  return CodeMirror.overlayMode(baseMode, nunjucksMode, false);
});