|
@@ -2,9 +2,11 @@ import { useMemo } from 'react';
|
|
|
|
|
|
|
|
import { indentWithTab, defaultKeymap } from '@codemirror/commands';
|
|
import { indentWithTab, defaultKeymap } from '@codemirror/commands';
|
|
|
import { markdown, markdownLanguage } from '@codemirror/lang-markdown';
|
|
import { markdown, markdownLanguage } from '@codemirror/lang-markdown';
|
|
|
|
|
+import { syntaxHighlighting, HighlightStyle, defaultHighlightStyle } from '@codemirror/language';
|
|
|
import { languages } from '@codemirror/language-data';
|
|
import { languages } from '@codemirror/language-data';
|
|
|
import { EditorState, Prec, type Extension } from '@codemirror/state';
|
|
import { EditorState, Prec, type Extension } from '@codemirror/state';
|
|
|
import { keymap, EditorView } from '@codemirror/view';
|
|
import { keymap, EditorView } from '@codemirror/view';
|
|
|
|
|
+import { tags } from '@lezer/highlight';
|
|
|
import { useCodeMirror, type UseCodeMirror } from '@uiw/react-codemirror';
|
|
import { useCodeMirror, type UseCodeMirror } from '@uiw/react-codemirror';
|
|
|
import deepmerge from 'ts-deepmerge';
|
|
import deepmerge from 'ts-deepmerge';
|
|
|
|
|
|
|
@@ -16,6 +18,15 @@ import { useInsertText, type InsertText } from './utils/insert-text';
|
|
|
import { useReplaceText, type ReplaceText } from './utils/replace-text';
|
|
import { useReplaceText, type ReplaceText } from './utils/replace-text';
|
|
|
import { useSetCaretLine, type SetCaretLine } from './utils/set-caret-line';
|
|
import { useSetCaretLine, type SetCaretLine } from './utils/set-caret-line';
|
|
|
|
|
|
|
|
|
|
+const markdownHighlighting = HighlightStyle.define([
|
|
|
|
|
+ { tag: tags.heading1, class: 'cm-header-1 cm-header' },
|
|
|
|
|
+ { tag: tags.heading2, class: 'cm-header-2 cm-header' },
|
|
|
|
|
+ { tag: tags.heading3, class: 'cm-header-3 cm-header' },
|
|
|
|
|
+ { tag: tags.heading4, class: 'cm-header-4 cm-header' },
|
|
|
|
|
+ { tag: tags.heading5, class: 'cm-header-5 cm-header' },
|
|
|
|
|
+ { tag: tags.heading6, class: 'cm-header-6 cm-header' },
|
|
|
|
|
+]);
|
|
|
|
|
+
|
|
|
type UseCodeMirrorEditorUtils = {
|
|
type UseCodeMirrorEditorUtils = {
|
|
|
initDoc: InitDoc,
|
|
initDoc: InitDoc,
|
|
|
appendExtensions: AppendExtensions,
|
|
appendExtensions: AppendExtensions,
|
|
@@ -35,6 +46,8 @@ const defaultExtensions: Extension[] = [
|
|
|
markdown({ base: markdownLanguage, codeLanguages: languages }),
|
|
markdown({ base: markdownLanguage, codeLanguages: languages }),
|
|
|
keymap.of([indentWithTab]),
|
|
keymap.of([indentWithTab]),
|
|
|
Prec.lowest(keymap.of(defaultKeymap)),
|
|
Prec.lowest(keymap.of(defaultKeymap)),
|
|
|
|
|
+ syntaxHighlighting(markdownHighlighting),
|
|
|
|
|
+ Prec.lowest(syntaxHighlighting(defaultHighlightStyle)),
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
export const useCodeMirrorEditor = (props?: UseCodeMirror): UseCodeMirrorEditor => {
|
|
export const useCodeMirrorEditor = (props?: UseCodeMirror): UseCodeMirrorEditor => {
|