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:
parent
54146e62c0
commit
af28ce59b8
9 changed files with 138 additions and 22 deletions
27
web_src/js/features/comp/EditorMarkdown.test.ts
Normal file
27
web_src/js/features/comp/EditorMarkdown.test.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import {initTextareaMarkdown} from './EditorMarkdown.ts';
|
||||
|
||||
test('EditorMarkdown', () => {
|
||||
const textarea = document.createElement('textarea');
|
||||
initTextareaMarkdown(textarea);
|
||||
|
||||
const testInput = (value, expected) => {
|
||||
textarea.value = value;
|
||||
textarea.setSelectionRange(value.length, value.length);
|
||||
const e = new KeyboardEvent('keydown', {key: 'Enter', cancelable: true});
|
||||
textarea.dispatchEvent(e);
|
||||
if (!e.defaultPrevented) textarea.value += '\n';
|
||||
expect(textarea.value).toEqual(expected);
|
||||
};
|
||||
|
||||
testInput('-', '-\n');
|
||||
testInput('1.', '1.\n');
|
||||
|
||||
testInput('- ', '');
|
||||
testInput('1. ', '');
|
||||
|
||||
testInput('- x', '- x\n- ');
|
||||
testInput('- [ ]', '- [ ]\n- ');
|
||||
testInput('- [ ] foo', '- [ ] foo\n- [ ] ');
|
||||
testInput('* [x] foo', '* [x] foo\n* [ ] ');
|
||||
testInput('1. [x] foo', '1. [x] foo\n1. [ ] ');
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue