mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Define CodeMirror in external codeMirror.ts
This commit is contained in:
parent
e71aed7146
commit
e269fe73da
3 changed files with 50 additions and 59 deletions
|
@ -5,35 +5,13 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
import { onMount, createEventDispatcher } from "svelte";
|
import { onMount, createEventDispatcher } from "svelte";
|
||||||
import { ChangeTimer } from "./change-timer";
|
import { ChangeTimer } from "./change-timer";
|
||||||
|
import { CodeMirror, latex, baseOptions } from "./codeMirror";
|
||||||
import CodeMirror from "codemirror";
|
|
||||||
import "codemirror/mode/stex/stex";
|
|
||||||
import "codemirror/addon/fold/foldcode";
|
|
||||||
import "codemirror/addon/fold/foldgutter";
|
|
||||||
import "codemirror/addon/fold/xml-fold";
|
|
||||||
import "codemirror/addon/edit/matchtags.js";
|
|
||||||
import "codemirror/addon/edit/closetag.js";
|
|
||||||
|
|
||||||
export let initialValue: string;
|
export let initialValue: string;
|
||||||
|
|
||||||
const latex = {
|
|
||||||
name: "stex",
|
|
||||||
inMathMode: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
const noop = () => {
|
|
||||||
/* noop */
|
|
||||||
};
|
|
||||||
|
|
||||||
const codeMirrorOptions = {
|
const codeMirrorOptions = {
|
||||||
mode: latex,
|
mode: latex,
|
||||||
theme: "monokai",
|
...baseOptions,
|
||||||
lineWrapping: true,
|
|
||||||
matchTags: { bothTags: true },
|
|
||||||
extraKeys: { Tab: noop, "Shift-Tab": noop },
|
|
||||||
viewportMargin: Infinity,
|
|
||||||
lineWiseCopyCut: false,
|
|
||||||
autofocus: true,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let codeMirror: CodeMirror.EditorFromTextArea;
|
let codeMirror: CodeMirror.EditorFromTextArea;
|
||||||
|
|
|
@ -5,45 +5,13 @@
|
||||||
@typescript-eslint/no-non-null-assertion: "off",
|
@typescript-eslint/no-non-null-assertion: "off",
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import CodeMirror from "codemirror";
|
import { CodeMirror, htmlanki, baseOptions, gutterOptions } from "./codeMirror";
|
||||||
import "codemirror/mode/htmlmixed/htmlmixed";
|
|
||||||
import "codemirror/mode/stex/stex";
|
|
||||||
import "codemirror/addon/fold/foldcode";
|
|
||||||
import "codemirror/addon/fold/foldgutter";
|
|
||||||
import "codemirror/addon/fold/xml-fold";
|
|
||||||
import "codemirror/addon/edit/matchtags.js";
|
|
||||||
import "codemirror/addon/edit/closetag.js";
|
|
||||||
|
|
||||||
import { inCodable } from "./toolbar";
|
import { inCodable } from "./toolbar";
|
||||||
|
|
||||||
const latex = {
|
|
||||||
name: "stex",
|
|
||||||
inMathMode: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
const htmlanki = {
|
|
||||||
name: "htmlmixed",
|
|
||||||
tags: {
|
|
||||||
"anki-mathjax": [[null, null, latex]],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const noop = () => {
|
|
||||||
/* noop */
|
|
||||||
};
|
|
||||||
|
|
||||||
const codeMirrorOptions = {
|
const codeMirrorOptions = {
|
||||||
mode: htmlanki,
|
mode: htmlanki,
|
||||||
theme: "monokai",
|
...baseOptions,
|
||||||
lineNumbers: true,
|
...gutterOptions,
|
||||||
lineWrapping: true,
|
|
||||||
foldGutter: true,
|
|
||||||
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
|
|
||||||
matchTags: { bothTags: true },
|
|
||||||
autoCloseTags: true,
|
|
||||||
extraKeys: { Tab: noop, "Shift-Tab": noop },
|
|
||||||
viewportMargin: Infinity,
|
|
||||||
lineWiseCopyCut: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const parser = new DOMParser();
|
const parser = new DOMParser();
|
||||||
|
|
45
ts/editor/codeMirror.ts
Normal file
45
ts/editor/codeMirror.ts
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
import CodeMirror from "codemirror";
|
||||||
|
import "codemirror/mode/htmlmixed/htmlmixed";
|
||||||
|
import "codemirror/mode/stex/stex";
|
||||||
|
import "codemirror/addon/fold/foldcode";
|
||||||
|
import "codemirror/addon/fold/foldgutter";
|
||||||
|
import "codemirror/addon/fold/xml-fold";
|
||||||
|
import "codemirror/addon/edit/matchtags.js";
|
||||||
|
import "codemirror/addon/edit/closetag.js";
|
||||||
|
|
||||||
|
export { CodeMirror };
|
||||||
|
|
||||||
|
export const latex = {
|
||||||
|
name: "stex",
|
||||||
|
inMathMode: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const htmlanki = {
|
||||||
|
name: "htmlmixed",
|
||||||
|
tags: {
|
||||||
|
"anki-mathjax": [[null, null, latex]],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const noop = () => {
|
||||||
|
/* noop */
|
||||||
|
};
|
||||||
|
|
||||||
|
export const baseOptions = {
|
||||||
|
theme: "monokai",
|
||||||
|
lineWrapping: true,
|
||||||
|
matchTags: { bothTags: true },
|
||||||
|
autoCloseTags: true,
|
||||||
|
extraKeys: { Tab: noop, "Shift-Tab": noop },
|
||||||
|
viewportMargin: Infinity,
|
||||||
|
lineWiseCopyCut: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const gutterOptions = {
|
||||||
|
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
|
||||||
|
lineNumbers: true,
|
||||||
|
foldGutter: true,
|
||||||
|
};
|
Loading…
Reference in a new issue