@dxos/ui-editor 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +8 -0
- package/README.md +21 -0
- package/package.json +121 -0
- package/src/defaults.ts +34 -0
- package/src/extensions/annotations.ts +55 -0
- package/src/extensions/autocomplete/autocomplete.ts +151 -0
- package/src/extensions/autocomplete/index.ts +8 -0
- package/src/extensions/autocomplete/match.ts +46 -0
- package/src/extensions/autocomplete/placeholder.ts +117 -0
- package/src/extensions/autocomplete/typeahead.ts +87 -0
- package/src/extensions/automerge/automerge.test.tsx +76 -0
- package/src/extensions/automerge/automerge.ts +105 -0
- package/src/extensions/automerge/cursor.ts +28 -0
- package/src/extensions/automerge/defs.ts +31 -0
- package/src/extensions/automerge/index.ts +5 -0
- package/src/extensions/automerge/sync.ts +79 -0
- package/src/extensions/automerge/update-automerge.ts +50 -0
- package/src/extensions/automerge/update-codemirror.ts +115 -0
- package/src/extensions/autoscroll.ts +165 -0
- package/src/extensions/awareness/awareness-provider.ts +127 -0
- package/src/extensions/awareness/awareness.ts +315 -0
- package/src/extensions/awareness/index.ts +6 -0
- package/src/extensions/blast.ts +363 -0
- package/src/extensions/blocks.ts +131 -0
- package/src/extensions/bookmarks.ts +77 -0
- package/src/extensions/comments.ts +579 -0
- package/src/extensions/debug.ts +15 -0
- package/src/extensions/dnd.ts +39 -0
- package/src/extensions/factories.ts +284 -0
- package/src/extensions/focus.ts +36 -0
- package/src/extensions/folding.ts +63 -0
- package/src/extensions/hashtag.ts +68 -0
- package/src/extensions/index.ts +34 -0
- package/src/extensions/json.ts +57 -0
- package/src/extensions/listener.ts +32 -0
- package/src/extensions/markdown/action.ts +117 -0
- package/src/extensions/markdown/bundle.ts +105 -0
- package/src/extensions/markdown/changes.test.ts +26 -0
- package/src/extensions/markdown/changes.ts +149 -0
- package/src/extensions/markdown/debug.ts +44 -0
- package/src/extensions/markdown/decorate.ts +622 -0
- package/src/extensions/markdown/formatting.test.ts +498 -0
- package/src/extensions/markdown/formatting.ts +1265 -0
- package/src/extensions/markdown/highlight.ts +183 -0
- package/src/extensions/markdown/image.ts +118 -0
- package/src/extensions/markdown/index.ts +13 -0
- package/src/extensions/markdown/link.ts +50 -0
- package/src/extensions/markdown/parser.test.ts +75 -0
- package/src/extensions/markdown/styles.ts +135 -0
- package/src/extensions/markdown/table.ts +150 -0
- package/src/extensions/mention.ts +41 -0
- package/src/extensions/modal.ts +24 -0
- package/src/extensions/modes.ts +41 -0
- package/src/extensions/outliner/commands.ts +270 -0
- package/src/extensions/outliner/editor.test.ts +33 -0
- package/src/extensions/outliner/editor.ts +184 -0
- package/src/extensions/outliner/index.ts +7 -0
- package/src/extensions/outliner/menu.ts +128 -0
- package/src/extensions/outliner/outliner.test.ts +100 -0
- package/src/extensions/outliner/outliner.ts +167 -0
- package/src/extensions/outliner/selection.ts +50 -0
- package/src/extensions/outliner/tree.test.ts +168 -0
- package/src/extensions/outliner/tree.ts +317 -0
- package/src/extensions/preview/index.ts +5 -0
- package/src/extensions/preview/preview.ts +193 -0
- package/src/extensions/replacer.test.ts +75 -0
- package/src/extensions/replacer.ts +93 -0
- package/src/extensions/scrolling.ts +189 -0
- package/src/extensions/selection.ts +100 -0
- package/src/extensions/state.ts +7 -0
- package/src/extensions/submit.ts +62 -0
- package/src/extensions/tags/extended-markdown.test.ts +263 -0
- package/src/extensions/tags/extended-markdown.ts +78 -0
- package/src/extensions/tags/index.ts +7 -0
- package/src/extensions/tags/streamer.ts +243 -0
- package/src/extensions/tags/xml-tags.ts +507 -0
- package/src/extensions/tags/xml-util.test.ts +48 -0
- package/src/extensions/tags/xml-util.ts +93 -0
- package/src/extensions/typewriter.ts +68 -0
- package/src/index.ts +14 -0
- package/src/styles/index.ts +7 -0
- package/src/styles/markdown.ts +26 -0
- package/src/styles/theme.ts +293 -0
- package/src/styles/tokens.ts +17 -0
- package/src/types/index.ts +5 -0
- package/src/types/types.ts +32 -0
- package/src/util/cursor.ts +56 -0
- package/src/util/debug.ts +56 -0
- package/src/util/decorations.ts +21 -0
- package/src/util/dom.ts +36 -0
- package/src/util/facet.ts +13 -0
- package/src/util/index.ts +10 -0
- package/src/util/util.ts +29 -0
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { markdownLanguage } from '@codemirror/lang-markdown';
|
|
6
|
+
import { EditorState, type StateCommand } from '@codemirror/state';
|
|
7
|
+
import { describe, expect, test } from 'vitest';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
type Formatting,
|
|
11
|
+
Inline,
|
|
12
|
+
List,
|
|
13
|
+
addBlockquote,
|
|
14
|
+
addCodeblock,
|
|
15
|
+
addLink,
|
|
16
|
+
addList,
|
|
17
|
+
addStyle,
|
|
18
|
+
getFormatting,
|
|
19
|
+
removeBlockquote,
|
|
20
|
+
removeCodeblock,
|
|
21
|
+
removeLink,
|
|
22
|
+
removeList,
|
|
23
|
+
removeStyle,
|
|
24
|
+
setHeading,
|
|
25
|
+
} from './formatting';
|
|
26
|
+
|
|
27
|
+
export const emptyFormatting: Formatting = {
|
|
28
|
+
blankLine: false,
|
|
29
|
+
blockType: 'paragraph',
|
|
30
|
+
strong: false,
|
|
31
|
+
emphasis: false,
|
|
32
|
+
strikethrough: false,
|
|
33
|
+
code: false,
|
|
34
|
+
link: false,
|
|
35
|
+
listStyle: null,
|
|
36
|
+
blockQuote: false,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const createState = (doc: string) => {
|
|
40
|
+
const selStart = doc.indexOf('{');
|
|
41
|
+
const selEnd = doc.indexOf('}') - 1;
|
|
42
|
+
return EditorState.create({
|
|
43
|
+
doc: doc.replace(/[{}]/g, ''),
|
|
44
|
+
selection: { anchor: selStart, head: selEnd },
|
|
45
|
+
extensions: markdownLanguage,
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const testCommand = (name: string, doc: string, command: StateCommand, result: string | null) => {
|
|
50
|
+
test(name, () => {
|
|
51
|
+
let state = createState(doc);
|
|
52
|
+
const status = command({ state, dispatch: (tr) => (state = tr.state) });
|
|
53
|
+
if (!status || result === null) {
|
|
54
|
+
expect(status).to.equal(result !== null);
|
|
55
|
+
} else {
|
|
56
|
+
let resultSel = null;
|
|
57
|
+
if (result.includes('{')) {
|
|
58
|
+
const resultState = createState(result);
|
|
59
|
+
result = resultState.doc.toString();
|
|
60
|
+
resultSel = resultState.selection.main;
|
|
61
|
+
}
|
|
62
|
+
expect(state.doc.toString()).to.equal(result);
|
|
63
|
+
if (resultSel) {
|
|
64
|
+
expect([state.selection.main.from, state.selection.main.to]).to.deep.equal([resultSel.from, resultSel.to]);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
describe('setHeading', () => {
|
|
71
|
+
testCommand('can create a heading', 'Hello {}', setHeading(1), '# Hello ');
|
|
72
|
+
|
|
73
|
+
testCommand('can create a level 2 heading', 'One\n\nTw{o}', setHeading(2), 'One\n\n## Two');
|
|
74
|
+
|
|
75
|
+
testCommand('can increase the depth of a heading', '# One{}', setHeading(3), '### One');
|
|
76
|
+
|
|
77
|
+
testCommand('can decrease the depth of a heading', '## One{}', setHeading(1), '# One');
|
|
78
|
+
|
|
79
|
+
testCommand('can remove a heading', '### A{}', setHeading(0), 'A');
|
|
80
|
+
|
|
81
|
+
testCommand(
|
|
82
|
+
'can make multiple blocks a heading',
|
|
83
|
+
'{One\n\nTwo}\n\nThree',
|
|
84
|
+
setHeading(3),
|
|
85
|
+
'### One\n\n### Two\n\nThree',
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
testCommand(
|
|
89
|
+
"doesn't affect code blocks",
|
|
90
|
+
'{One\n\n```\nTwo\n```\nThree}',
|
|
91
|
+
setHeading(1),
|
|
92
|
+
'# One\n\n```\nTwo\n```\n# Three',
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
testCommand('can remove a setext heading', 'One{}\n===', setHeading(0), 'One');
|
|
96
|
+
|
|
97
|
+
testCommand('can change a setext heading to ATX', 'One{}\n---', setHeading(1), '# One');
|
|
98
|
+
|
|
99
|
+
testCommand('can add a heading inside block markup', '> - {one\n> - two}\n', setHeading(1), '> - # one\n> - # two\n');
|
|
100
|
+
|
|
101
|
+
testCommand('can remove a heading inside block markup', '1. # one{}', setHeading(0), '1. one');
|
|
102
|
+
|
|
103
|
+
testCommand('can add a heading to a blank line', 'one\n\n{}', setHeading(1), 'one\n\n# {}');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe('addStyle', () => {
|
|
107
|
+
const em = addStyle(Inline.Emphasis);
|
|
108
|
+
const str = addStyle(Inline.Strong);
|
|
109
|
+
const code = addStyle(Inline.Code);
|
|
110
|
+
|
|
111
|
+
testCommand('can add emphasis', 'one {two}', em, 'one *{two}*');
|
|
112
|
+
|
|
113
|
+
testCommand('can add emphasis around cursor', 'one {}', em, 'one *{}*');
|
|
114
|
+
|
|
115
|
+
testCommand('can add strong style', '{one\n\ntwo}', str, '**{one**\n\n**two}**');
|
|
116
|
+
|
|
117
|
+
testCommand('can add strikethrough', '{hey}', addStyle(Inline.Strikethrough), '~~{hey}~~');
|
|
118
|
+
|
|
119
|
+
testCommand('can add code style', 'a {variable}', code, 'a `{variable}`');
|
|
120
|
+
|
|
121
|
+
testCommand('clears styles inside added code', '{some **bold** text}', code, '`some bold text`');
|
|
122
|
+
|
|
123
|
+
testCommand(
|
|
124
|
+
'clears styles partially inside added code',
|
|
125
|
+
'**some {bold** and *emphasized} text*',
|
|
126
|
+
code,
|
|
127
|
+
'**some** `bold and emphasized` *text*',
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
testCommand(
|
|
131
|
+
'inserts markers at same position in the right order',
|
|
132
|
+
'{some **bold,}text**',
|
|
133
|
+
code,
|
|
134
|
+
'`some bold,`**text**',
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
testCommand('remove existing markers inside', '{one *two* three}', em, '*{one two three}*');
|
|
138
|
+
|
|
139
|
+
testCommand(
|
|
140
|
+
'removes existing markers overlapping boundaries',
|
|
141
|
+
'*one {two* *three} four*',
|
|
142
|
+
em,
|
|
143
|
+
'*one {two three} four*',
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
testCommand(
|
|
147
|
+
'can style headers',
|
|
148
|
+
'{one\n\n# two\n\nthree\n---\n\nfour} five',
|
|
149
|
+
str,
|
|
150
|
+
'**{one**\n\n# **two**\n\n**three**\n---\n\n**four}** five',
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
testCommand('moves the insert position out of markup', 'one ~{~two~}~ three', em, 'one ~~*two*~~ three');
|
|
154
|
+
|
|
155
|
+
testCommand(
|
|
156
|
+
'moves the range to cover partially covered links and images',
|
|
157
|
+
'[one {two](x)  five',
|
|
158
|
+
em,
|
|
159
|
+
'*[one {two](x) * five',
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
testCommand('can add a style to an empty line', '{}', em, '*{}*');
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
describe('removeStyle', () => {
|
|
166
|
+
const em = removeStyle(Inline.Emphasis);
|
|
167
|
+
const str = removeStyle(Inline.Strong);
|
|
168
|
+
const code = removeStyle(Inline.Code);
|
|
169
|
+
const strike = removeStyle(Inline.Strikethrough);
|
|
170
|
+
|
|
171
|
+
testCommand('can remove emphasis', 'one *{two}*', em, 'one {two}');
|
|
172
|
+
|
|
173
|
+
testCommand('can remove emphasis around cursor', 'one *{}*', em, 'one {}');
|
|
174
|
+
|
|
175
|
+
testCommand('can remove strong style', '{**one**\n\n**two**}', str, '{one\n\ntwo}');
|
|
176
|
+
|
|
177
|
+
testCommand('can remove strikethrough', '~~{hey}~~', strike, '{hey}');
|
|
178
|
+
|
|
179
|
+
testCommand('can remove strikethrough around cursor', 'one ~~{}~~', strike, 'one {}');
|
|
180
|
+
|
|
181
|
+
testCommand('can remove strikethrough around cursor with inner emphasis', 'one ~~*{}*~~', strike, 'one *{}*');
|
|
182
|
+
|
|
183
|
+
testCommand('can remove code style', 'a `{variable}`', code, 'a {variable}');
|
|
184
|
+
|
|
185
|
+
// TODO(dmaretskyi): Flaky on CI.
|
|
186
|
+
// testCommand(
|
|
187
|
+
// 'can remove emphasis across multiple blocks',
|
|
188
|
+
// '{*one*\n\n# *two*\n\n> 1. *three} four*\n',
|
|
189
|
+
// em,
|
|
190
|
+
// '{one\n\n# two\n\n> 1. three} *four*\n',
|
|
191
|
+
// );
|
|
192
|
+
|
|
193
|
+
testCommand('can shrink existing styles', '*one {two three} four*', em, '*one* {two three} *four*');
|
|
194
|
+
|
|
195
|
+
testCommand('can remove strong from a partially emphasized text', '**{one*two*}**', str, '{one*two*}');
|
|
196
|
+
|
|
197
|
+
testCommand(
|
|
198
|
+
'can remove strong from a partially emphasized text with markers outside',
|
|
199
|
+
'***{o*ne*two}***',
|
|
200
|
+
str,
|
|
201
|
+
'*{o*ne*two}*',
|
|
202
|
+
);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe('addLink', () => {
|
|
206
|
+
testCommand('adds a link', '{}', addLink(), '[]({})');
|
|
207
|
+
|
|
208
|
+
testCommand('adds a link around text', 'hello {world}', addLink(), 'hello [world]({})');
|
|
209
|
+
|
|
210
|
+
testCommand('clears existing links', '[hello {world}](foo)', addLink(), 'hello [world]({})');
|
|
211
|
+
|
|
212
|
+
testCommand('does nothing across blocks', '{one\n\ntwo}', addLink(), null);
|
|
213
|
+
|
|
214
|
+
testCommand('does nothing in code blocks', '```\n{one}\n```', addLink(), null);
|
|
215
|
+
|
|
216
|
+
testCommand('patches up overlapping styles before', '*foo {bar* baz}', addLink(), '*foo* [*bar* baz]({})');
|
|
217
|
+
|
|
218
|
+
testCommand(
|
|
219
|
+
'patches up overlapping styles after',
|
|
220
|
+
'one {two ~~three} four~~',
|
|
221
|
+
addLink(),
|
|
222
|
+
'one [two ~~three~~]({}) ~~four~~',
|
|
223
|
+
);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
describe('removeLink', () => {
|
|
227
|
+
testCommand('removes a link', '[hi{}](x)', removeLink, 'hi{}');
|
|
228
|
+
|
|
229
|
+
testCommand('removes multiple links', '{[hi](x)\n\none [two](y)}', removeLink, '{hi\n\none two}');
|
|
230
|
+
|
|
231
|
+
testCommand('removes label links', '[hi{}][hi]', removeLink, 'hi{}');
|
|
232
|
+
|
|
233
|
+
testCommand('removes titles in links', '[hi{}](a "title" )', removeLink, 'hi{}');
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
describe('addList', () => {
|
|
237
|
+
const bullet = addList(List.Bullet);
|
|
238
|
+
const ordered = addList(List.Ordered);
|
|
239
|
+
|
|
240
|
+
testCommand('can add a bullet list', 'Hi{}', bullet, '- Hi');
|
|
241
|
+
|
|
242
|
+
testCommand('can add an ordered list', 'Hi{}', ordered, '1. Hi');
|
|
243
|
+
|
|
244
|
+
testCommand('can add a task list', 'Hi{}', addList(List.Task), '- [ ] Hi');
|
|
245
|
+
|
|
246
|
+
testCommand(
|
|
247
|
+
'can wrap multiple blocks in a bullet list',
|
|
248
|
+
'{One\n\n# Two\n\nThree}',
|
|
249
|
+
bullet,
|
|
250
|
+
'- One\n\n- # Two\n\n- Three',
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
testCommand('continues an existing numbered list', '1. Hello\n\nHi{}', ordered, '1. Hello\n\n2. Hi');
|
|
254
|
+
|
|
255
|
+
testCommand(
|
|
256
|
+
'can wrap multi-line blocks',
|
|
257
|
+
'Hello this\nis a three-line\nparagraph.{}',
|
|
258
|
+
bullet,
|
|
259
|
+
'- Hello this\n is a three-line\n paragraph.',
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
testCommand(
|
|
263
|
+
'can wrap fenced code blocks',
|
|
264
|
+
'```javascript\ntrue{}\n```',
|
|
265
|
+
ordered,
|
|
266
|
+
'1. ```javascript\n true\n ```',
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
testCommand(
|
|
270
|
+
'can wrap blocks inside markup',
|
|
271
|
+
'> 1. Hello\n {World\n>\n> Again}',
|
|
272
|
+
bullet,
|
|
273
|
+
'> 1. - Hello\n World\n>\n> - Again',
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
testCommand('restarts numbering on outer block markup boundaries', '> {one\n\ntwo}', ordered, '> 1. one\n\n1. two');
|
|
277
|
+
|
|
278
|
+
testCommand('aligns with above bullet list', ' - one\n\ntwo{}', bullet, ' - one\n\n - two');
|
|
279
|
+
|
|
280
|
+
testCommand('aligns with above ordered list', ' 1. One\n\nTwo{}', ordered, ' 1. One\n\n 2. Two');
|
|
281
|
+
|
|
282
|
+
testCommand('compensates for number size when aligning', ' 9. One\n\nTwo{}', ordered, ' 9. One\n\n 10. Two');
|
|
283
|
+
|
|
284
|
+
testCommand(
|
|
285
|
+
'anticipates number size of other items',
|
|
286
|
+
'{a\n\nb\n\nc\n\nd\n\ne\n\nf\n\ng\n\nh\n\ni\n\nj}',
|
|
287
|
+
ordered,
|
|
288
|
+
' 1. a\n\n 2. b\n\n 3. c\n\n 4. d\n\n 5. e\n\n 6. f\n\n 7. g\n\n 8. h\n\n 9. i\n\n10. j',
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
testCommand(
|
|
292
|
+
'renumbers lists after the selection',
|
|
293
|
+
'one{}\n\n1. two\n\n2. three',
|
|
294
|
+
ordered,
|
|
295
|
+
'1. one\n\n2. two\n\n3. three',
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
testCommand("doesn't renumber lists with a different parent", '> one{}\n\n1. two', ordered, '> 1. one\n\n1. two');
|
|
299
|
+
|
|
300
|
+
testCommand('can add a list to an empty line', '{}', ordered, '1. {}');
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
describe('removeList', () => {
|
|
304
|
+
const bullet = removeList(List.Bullet);
|
|
305
|
+
const ordered = removeList(List.Ordered);
|
|
306
|
+
|
|
307
|
+
testCommand('can remove a bullet list', ' - Hi{}', bullet, 'Hi');
|
|
308
|
+
|
|
309
|
+
testCommand('can remove an ordered list', '1. Hi{}', ordered, 'Hi');
|
|
310
|
+
|
|
311
|
+
testCommand('can remove a task list', '- [x] Hi{}', removeList(List.Task), 'Hi');
|
|
312
|
+
|
|
313
|
+
testCommand(
|
|
314
|
+
'can remove a bullet list from multiple blocks',
|
|
315
|
+
'- {One\n\n- # Two\n\n- Three}',
|
|
316
|
+
bullet,
|
|
317
|
+
'One\n\n# Two\n\nThree',
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
testCommand(
|
|
321
|
+
'can unwrap multi-line blocks',
|
|
322
|
+
'1. Hello this\n is a three-line\nparagraph.{}',
|
|
323
|
+
ordered,
|
|
324
|
+
'Hello this\nis a three-line\nparagraph.',
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
testCommand('can unwrap fenced code blocks', '- ```javascript\n true{}\n ```', bullet, '```javascript\ntrue\n```');
|
|
328
|
+
|
|
329
|
+
testCommand(
|
|
330
|
+
'can unwrap blocks inside markup',
|
|
331
|
+
'> 1. - Hello\n {World\n>\n> - Again}',
|
|
332
|
+
bullet,
|
|
333
|
+
'> 1. Hello\n World\n>\n> Again',
|
|
334
|
+
);
|
|
335
|
+
|
|
336
|
+
testCommand("doesn't unwrap other types of lists", '1. foo{}', bullet, null);
|
|
337
|
+
|
|
338
|
+
testCommand(
|
|
339
|
+
'renumbers lists after the selection',
|
|
340
|
+
'1. one\n\n2. {two\n\n3. three}\n\n4. four\n\n5. five',
|
|
341
|
+
ordered,
|
|
342
|
+
'1. one\n\ntwo\n\nthree\n\n1. four\n\n2. five',
|
|
343
|
+
);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
describe('addBlockquote', () => {
|
|
347
|
+
testCommand('can add a blockquote', 'Hi{}', addBlockquote, '> Hi');
|
|
348
|
+
|
|
349
|
+
testCommand(
|
|
350
|
+
'can add a blockquote to multi-line paragraph',
|
|
351
|
+
'One\ntwo\nthree{}',
|
|
352
|
+
addBlockquote,
|
|
353
|
+
'> One\n> two\n> three',
|
|
354
|
+
);
|
|
355
|
+
|
|
356
|
+
testCommand(
|
|
357
|
+
'can add a blockquote to multiple blocks',
|
|
358
|
+
'{one\ntwo\n\n# three\n}\nfour',
|
|
359
|
+
addBlockquote,
|
|
360
|
+
'> one\n> two\n>\n> # three\n\nfour',
|
|
361
|
+
);
|
|
362
|
+
|
|
363
|
+
testCommand('can add a blockquote to an empty line', '{}', addBlockquote, '>{}');
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
describe('removeBlockquote', () => {
|
|
367
|
+
testCommand('can remove a blockquote', '> Hi{}', removeBlockquote, 'Hi');
|
|
368
|
+
|
|
369
|
+
testCommand('can remove a blockquote from a multi-line paragraph', '> A\n> B\n> C{}', removeBlockquote, 'A\nB\nC');
|
|
370
|
+
|
|
371
|
+
testCommand('can remove a nested blockquote', '>> A\n>> B\n>> C{}', removeBlockquote, '> A\n> B\n> C');
|
|
372
|
+
|
|
373
|
+
testCommand(
|
|
374
|
+
'removes markers from adjacent blank lines',
|
|
375
|
+
'> one\n>\n> two{}\n>\n> three',
|
|
376
|
+
removeBlockquote,
|
|
377
|
+
'> one\n\ntwo\n\n> three',
|
|
378
|
+
);
|
|
379
|
+
|
|
380
|
+
testCommand(
|
|
381
|
+
'can remove quotes nested in lists',
|
|
382
|
+
' - 1. > foo\n > {bar\n - > baz}',
|
|
383
|
+
removeBlockquote,
|
|
384
|
+
' - 1. foo\n bar\n - baz',
|
|
385
|
+
);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
describe('addCodeblock', () => {
|
|
389
|
+
testCommand('add a code block to a blank line', '{}', addCodeblock, '```{}\n\n```');
|
|
390
|
+
|
|
391
|
+
testCommand(
|
|
392
|
+
'can turn a paragraph into a code block',
|
|
393
|
+
'one\ntwo{}\nthree',
|
|
394
|
+
addCodeblock,
|
|
395
|
+
'```\none\ntwo{}\nthree\n```',
|
|
396
|
+
);
|
|
397
|
+
|
|
398
|
+
testCommand(
|
|
399
|
+
'can turn an indented paragraph into a code block',
|
|
400
|
+
'1. one\n two{}',
|
|
401
|
+
addCodeblock,
|
|
402
|
+
'1. ```\n one\n two{}\n ```',
|
|
403
|
+
);
|
|
404
|
+
|
|
405
|
+
testCommand(
|
|
406
|
+
'can turn multiple paragraphs into a code block',
|
|
407
|
+
"{10 print 'hello'\n\n20 goto 10}",
|
|
408
|
+
addCodeblock,
|
|
409
|
+
"```\n10 print 'hello'\n\n20 goto 10\n```",
|
|
410
|
+
);
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
describe('removeCodeblock', () => {
|
|
414
|
+
testCommand('removes fenced code blocks', '```\ncode{}\n```', removeCodeblock, 'code{}');
|
|
415
|
+
|
|
416
|
+
testCommand('removes indented code blocks', ' code{}', removeCodeblock, 'code{}');
|
|
417
|
+
|
|
418
|
+
testCommand('does nothing on regular text', 'not code{}', removeCodeblock, null);
|
|
419
|
+
|
|
420
|
+
testCommand('can remove multiple code block', '{```\none\n```\n\n two}', removeCodeblock, 'one\n\ntwo');
|
|
421
|
+
|
|
422
|
+
testCommand(
|
|
423
|
+
'can remove code in other block markup',
|
|
424
|
+
'> 1. ```\n> {one\n> ```\n>\n> 2. two}',
|
|
425
|
+
removeCodeblock,
|
|
426
|
+
'> 1. one\n>\n> 2. two',
|
|
427
|
+
);
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
describe('getFormatting', () => {
|
|
431
|
+
const t = (name: string, doc: string, result: Partial<Formatting>) => {
|
|
432
|
+
test(name, () => {
|
|
433
|
+
const formatting = getFormatting(createState(doc));
|
|
434
|
+
const expected = Object.assign({}, emptyFormatting, result);
|
|
435
|
+
expect(formatting).to.deep.equal(expected);
|
|
436
|
+
});
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
t('returns nothing special for regular content', 'hello {world}', {});
|
|
440
|
+
|
|
441
|
+
t('can see emphasis', 'hello *{world}*', { emphasis: true });
|
|
442
|
+
|
|
443
|
+
t('can see strong emphasis', 'hello **{world}**', { strong: true });
|
|
444
|
+
|
|
445
|
+
t('can see strikethrough', 'hello ~~{world}~~', { strikethrough: true });
|
|
446
|
+
|
|
447
|
+
t('can see inline code', 'hello `{world}`', { code: true });
|
|
448
|
+
|
|
449
|
+
t("doesn't enable inline styles when only part of selection is styled", 'he{llo **wor}ld**', {});
|
|
450
|
+
|
|
451
|
+
t('can handle adjacent styled spans', '**he{llo**\n**wor}ld**', { strong: true });
|
|
452
|
+
|
|
453
|
+
t('ignores markers for inline style purposes', '{***o***}', { strong: true, emphasis: true });
|
|
454
|
+
|
|
455
|
+
t('handles multi-paragraph inline styles', '~~*fo{o*~~\n\n~~ba}r~~', { strikethrough: true });
|
|
456
|
+
|
|
457
|
+
t('activates for cursor selections', '~~*fo{}o*~~', { strikethrough: true, emphasis: true });
|
|
458
|
+
|
|
459
|
+
t('spots a heading', '# Hello{}', { blockType: 'heading1' });
|
|
460
|
+
|
|
461
|
+
t('spots a heading', '# Hello{}', { blockType: 'heading1' });
|
|
462
|
+
|
|
463
|
+
t('spots a setext heading', 'Hello{}\n---', { blockType: 'heading2' });
|
|
464
|
+
|
|
465
|
+
t('spots a code block', ' {code}', { blockType: 'codeblock' });
|
|
466
|
+
|
|
467
|
+
t('spots a fenced code block', '```\n{code}\n```', { blockType: 'codeblock' });
|
|
468
|
+
|
|
469
|
+
t('reports null for mixed block types', '# on{e\n\ntwo}', { blockType: null });
|
|
470
|
+
|
|
471
|
+
t('reports heading for multiple selected headings', '# on{e\n\n# two}', { blockType: 'heading1' });
|
|
472
|
+
|
|
473
|
+
t('notices blockquotes', '> {one}', { blockQuote: true });
|
|
474
|
+
|
|
475
|
+
t('notices multi-block blockquotes', '> {one\n>\n> two}', { blockQuote: true });
|
|
476
|
+
|
|
477
|
+
t('disables blockquote when not all blocks are quoted', '{one\n\n> two}', {});
|
|
478
|
+
|
|
479
|
+
t('notices ordered lists', ' 1. Hi{}', { listStyle: 'ordered' });
|
|
480
|
+
|
|
481
|
+
t('notices bullet lists', ' - Hi{}', { listStyle: 'bullet' });
|
|
482
|
+
|
|
483
|
+
t('notices task lists', ' - [x] {Hi}', { listStyle: 'task' });
|
|
484
|
+
|
|
485
|
+
t('uses the innermost list style', ' - 1. Ok{}', { listStyle: 'ordered' });
|
|
486
|
+
|
|
487
|
+
t('notices multi-block lists', '1. {one\n2. two}', { listStyle: 'ordered' });
|
|
488
|
+
|
|
489
|
+
t("disables list style when a block isn't a list", '1. {one\n\ntwo}', {});
|
|
490
|
+
|
|
491
|
+
t('sees markup directly around cursor even if not valid', 'q **{}**', { strong: true });
|
|
492
|
+
|
|
493
|
+
t('sees multiple types of markup directly around cursor', 'q ~~***{}***~~', {
|
|
494
|
+
strong: true,
|
|
495
|
+
emphasis: true,
|
|
496
|
+
strikethrough: true,
|
|
497
|
+
});
|
|
498
|
+
});
|