CodeMirror中的嵌套组

时间:2017-03-31 18:57:08

标签: javascript codemirror codemirror-modes

我正在尝试为Minecraft样式编写模式

http://minecraft.tools/en/color-code.php

我想进行组嵌套,其中以§开头的所有内容都设置为直到行的末尾

即。 §7 $1 \(§l§3$0\)

会变成

<span class="cm-§7"> // gray text
  §7 $1 \(
  <span class="cm-§l"> //Bold text
    <span class="cm-§3">§3$0\)</span> // Dark_Aqua text
  </span>
</span>

我已经有了CSS

.cm-s-monokai span.cm-§4 { color: #BE0000; }
.cm-s-monokai span.cm-§c { color: #FE3F3F; }
.cm-s-monokai span.cm-§6 { color: #D9A334; }
.cm-s-monokai span.cm-§e { color: #FEFE3F; }
.cm-s-monokai span.cm-§2 { color: #00BE00; }
.cm-s-monokai span.cm-§a { color: #00BE00; }
.cm-s-monokai span.cm-§b { color: #3FFEFE; }
.cm-s-monokai span.cm-§3 { color: #00BEBE; }
.cm-s-monokai span.cm-§1 { color: #0000BE; }
.cm-s-monokai span.cm-§9 { color: #3F3FFE; }
.cm-s-monokai span.cm-§d { color: #FE3FFE; }
.cm-s-monokai span.cm-§5 { color: #BE00BE; }
.cm-s-monokai span.cm-§f { color: #FFFFFF; }
.cm-s-monokai span.cm-§7 { color: #BEBEBE; }
.cm-s-monokai span.cm-§8 { color: #3F3F3F; }
.cm-s-monokai span.cm-§0 { color: #000000; }
.cm-s-monokai span.cm-§r { color: #FFFFFF; font-weight: normal; font-style: normal; text-decoration: initial; }
.cm-s-monokai span.cm-§l { font-weight: bolder; }
.cm-s-monokai span.cm-§o { font-style: italic; }
.cm-s-monokai span.cm-§n { text-decoration: underline; }
.cm-s-monokai span.cm-§m { text-decoration: line-through; }

到目前为止我的mode/minecraft/minecraft.js我有以下内容,只对第一行§到行尾的样式

(function(mod) {
  if (typeof exports == "object" && typeof module == "object") // CommonJS
    mod(require("../../lib/codemirror"));
  else if (typeof define == "function" && define.amd) // AMD
    define(["../../lib/codemirror"], mod);
  else // Plain browser env
    mod(CodeMirror);
})(function(CodeMirror) {
"use strict";

    CodeMirror.defineMode("minecraft", function() {
        var g= 0;

        var tokenBase = function(stream, state) {
            var ch = stream.next();

            if ( ch === "§" ) {
                const nxt = stream.next();
                stream.skipToEnd();
                return "§" + nxt;
            }

            stream.next();
            return null;
        };

        return {
            startState: base => {
                g = 0;
            },
            token: tokenBase
        };
    });

    CodeMirror.defineMIME("text/plain", "minecraft");
});

任何人都有任何想法如何实现这个

提前致谢

〜MRVDOG

0 个答案:

没有答案