テーマの設定 CodeMirror - JavaScript
シンタックスハイライトの設定 CodeMirror - JavaScript - TIL の続き
この動画を見て、実際にテーマの変更をしてみた
すごい簡単にできてびっくりした
themeフォルダにテーマ(.cssファイル)は格納されている
以下のようにthemeフォルダをコピーしてくる
. ├── index.html ├── lib ├── mode └── theme // コピーしてくる
themeの中を見てみたんだけど、gruvboxがない!!!!!大好きなテーマがなくて少しショック...
テーマの設定
今回はテーマをmonokaiにしてみる

テーマの設定をするには以下のようにする
- theme内にあるcssファイルを読み込む
- CodeMirrorオブジェクト生成時に
themeでテーマを指定する
まずはCSSの読み込み
<head> ... <link rel="stylesheet" href="theme/monokai.css"> ... </head>
次に、CodeMirrorオブジェクトの生成時にテーマを指定する
theme: テーマ名とすることで設定できる
<body>
...
<script>
const editor = CodeMirror(document.getElementById("codeeditor"), {
mode: "css",
theme: "monokai" /* テーマの設定 */
});
<script>
<body>
設定はdictionaryで渡すこともできる!
<body>
...
<script>
// dictionaryを生成して渡す
const conf = {
mode: "css",
theme: "monokai"
};
const editor = CodeMirror(document.getElementById("codeeditor"), conf);
<script>
<body>