LaravelTest
72 строки · 2.4 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function (mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"), require("../yaml/yaml"))7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror", "../yaml/yaml"], mod)9else // Plain browser env10mod(CodeMirror)11})(function (CodeMirror) {12
13var START = 0, FRONTMATTER = 1, BODY = 214
15// a mixed mode for Markdown text with an optional YAML front matter16CodeMirror.defineMode("yaml-frontmatter", function (config, parserConfig) {17var yamlMode = CodeMirror.getMode(config, "yaml")18var innerMode = CodeMirror.getMode(config, parserConfig && parserConfig.base || "gfm")19
20function localMode(state) {21return state.state == FRONTMATTER ? {mode: yamlMode, state: state.yaml} : {mode: innerMode, state: state.inner}22}23
24return {25startState: function () {26return {27state: START,28yaml: null,29inner: CodeMirror.startState(innerMode)30}31},32copyState: function (state) {33return {34state: state.state,35yaml: state.yaml && CodeMirror.copyState(yamlMode, state.yaml),36inner: CodeMirror.copyState(innerMode, state.inner)37}38},39token: function (stream, state) {40if (state.state == START) {41if (stream.match('---', false)) {42state.state = FRONTMATTER43state.yaml = CodeMirror.startState(yamlMode)44return yamlMode.token(stream, state.yaml)45} else {46state.state = BODY47return innerMode.token(stream, state.inner)48}49} else if (state.state == FRONTMATTER) {50var end = stream.sol() && stream.match(/(---|\.\.\.)/, false)51var style = yamlMode.token(stream, state.yaml)52if (end) {53state.state = BODY54state.yaml = null55}56return style57} else {58return innerMode.token(stream, state.inner)59}60},61innerMode: localMode,62indent: function(state, a, b) {63var m = localMode(state)64return m.mode.indent ? m.mode.indent(m.state, a, b) : CodeMirror.Pass65},66blankLine: function (state) {67var m = localMode(state)68if (m.mode.blankLine) return m.mode.blankLine(m.state)69}70}71})72});73