2022-08-08 17:00:14 +02:00
|
|
|
import { markdown } from '@codemirror/lang-markdown';
|
|
|
|
import { GFM as GithubFlavoredMarkdownExt } from '@lezer/markdown';
|
2022-08-29 13:40:19 +02:00
|
|
|
import { forceParsing, indentUnit } from '@codemirror/language';
|
2022-08-08 17:00:14 +02:00
|
|
|
import { SelectionRange, EditorSelection, EditorState } from '@codemirror/state';
|
|
|
|
import { EditorView } from '@codemirror/view';
|
|
|
|
import { MarkdownMathExtension } from './markdownMathParser';
|
|
|
|
|
|
|
|
// Creates and returns a minimal editor with markdown extensions
|
|
|
|
const createEditor = (initialText: string, initialSelection: SelectionRange): EditorView => {
|
2022-08-29 13:40:19 +02:00
|
|
|
const editor = new EditorView({
|
2022-08-08 17:00:14 +02:00
|
|
|
doc: initialText,
|
|
|
|
selection: EditorSelection.create([initialSelection]),
|
|
|
|
extensions: [
|
|
|
|
markdown({
|
|
|
|
extensions: [MarkdownMathExtension, GithubFlavoredMarkdownExt],
|
|
|
|
}),
|
|
|
|
indentUnit.of('\t'),
|
|
|
|
EditorState.tabSize.of(4),
|
|
|
|
],
|
|
|
|
});
|
2022-08-29 13:40:19 +02:00
|
|
|
|
|
|
|
forceParsing(editor);
|
|
|
|
return editor;
|
2022-08-08 17:00:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default createEditor;
|