Add some handy markdown editor features (#32400)

There were some missing features from EasyMDE:

1. H1 - H3 style
2. Auto add task list
3. Insert a table

And added some tests
This commit is contained in:
wxiaoguang
2024-11-04 18:14:36 +08:00
committed by GitHub
parent 54146e62c0
commit af28ce59b8
9 changed files with 138 additions and 22 deletions

View File

@ -1,7 +1,7 @@
import {imageInfo} from '../../utils/image.ts';
import {replaceTextareaSelection} from '../../utils/dom.ts';
import {isUrl} from '../../utils/url.ts';
import {triggerEditorContentChanged} from './EditorMarkdown.ts';
import {textareaInsertText, triggerEditorContentChanged} from './EditorMarkdown.ts';
import {
DropzoneCustomEventRemovedFile,
DropzoneCustomEventUploadDone,
@ -41,14 +41,7 @@ class TextareaEditor {
}
insertPlaceholder(value) {
const editor = this.editor;
const startPos = editor.selectionStart;
const endPos = editor.selectionEnd;
editor.value = editor.value.substring(0, startPos) + value + editor.value.substring(endPos);
editor.selectionStart = startPos;
editor.selectionEnd = startPos + value.length;
editor.focus();
triggerEditorContentChanged(editor);
textareaInsertText(this.editor, value);
}
replacePlaceholder(oldVal, newVal) {