1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-09 10:22:51 +03:00
Files
bookstack/resources/js/markdown/codemirror.ts
2025-07-21 18:53:22 +01:00

32 lines
892 B
TypeScript

import {provideKeyBindings} from './shortcuts';
import {EditorView, ViewUpdate} from "@codemirror/view";
import {MarkdownEditor} from "./index.mjs";
import {CodeModule} from "../global";
import {MarkdownEditorEventMap} from "./dom-handlers";
/**
* Initiate the codemirror instance for the Markdown editor.
*/
export function init(editor: MarkdownEditor, Code: CodeModule, domEventHandlers: MarkdownEditorEventMap): EditorView {
function onViewUpdate(v: ViewUpdate) {
if (v.docChanged) {
editor.actions.updateAndRender();
}
}
const cm = Code.markdownEditor(
editor.config.inputEl,
onViewUpdate,
domEventHandlers,
provideKeyBindings(editor),
);
// Add editor view to the window for easy access/debugging.
// Not part of official API/Docs
// @ts-ignore
window.mdEditorView = cm;
return cm;
}