mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-12 08:54:00 +02:00
27 lines
890 B
TypeScript
27 lines
890 B
TypeScript
import { markdown } from '@codemirror/lang-markdown';
|
|
import { GFM as GithubFlavoredMarkdownExt } from '@lezer/markdown';
|
|
import { forceParsing, indentUnit } from '@codemirror/language';
|
|
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 => {
|
|
const editor = new EditorView({
|
|
doc: initialText,
|
|
selection: EditorSelection.create([initialSelection]),
|
|
extensions: [
|
|
markdown({
|
|
extensions: [MarkdownMathExtension, GithubFlavoredMarkdownExt],
|
|
}),
|
|
indentUnit.of('\t'),
|
|
EditorState.tabSize.of(4),
|
|
],
|
|
});
|
|
|
|
forceParsing(editor);
|
|
return editor;
|
|
};
|
|
|
|
export default createEditor;
|