Skip to content

Commit 901c4b2

Browse files
authored
Merge pull request #851 from streamich/markdown-import
Markdown import/export tests
2 parents 0f61b0d + 8c9d62c commit 901c4b2

File tree

1 file changed

+70
-1
lines changed

1 file changed

+70
-1
lines changed

src/json-crdt-extensions/peritext/transfer/__tests__/PeritextDataTransfer.spec.ts

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ const setup = () => {
1717
return {...kit, transfer};
1818
};
1919

20+
const assertMarkdownReExport = (markdown: string) => {
21+
const kit = setup();
22+
kit.transfer.fromMarkdown(0, markdown);
23+
kit.peritext.refresh();
24+
const back = kit.transfer.toMarkdown(kit.peritext.rangeAll()!);
25+
expect(back).toBe(markdown);
26+
};
27+
2028
test('ignores empty inline tags', () => {
2129
const {peritext, transfer} = setup();
2230
const html =
@@ -218,7 +226,6 @@ describe('Markdown', () => {
218226
const html = transfer.toHtml(all);
219227
expect(html).toBe('<blockquote><p>blockquote</p></blockquote>');
220228
const md2 = transfer.toMarkdown(all);
221-
console.log(md2);
222229
expect(md2).toBe('> blockquote');
223230
});
224231

@@ -272,4 +279,66 @@ describe('Markdown', () => {
272279
// console.log(md2);
273280
expect(md2).toBe('a' + md + 'b');
274281
});
282+
283+
test('can re-export a single paragraph', () => {
284+
assertMarkdownReExport('Hello world');
285+
});
286+
287+
test('can re-export a paragraph and a blockquote', () => {
288+
assertMarkdownReExport('Hello world\n\n> blockquote');
289+
});
290+
291+
test('can re-export a single blockquote', () => {
292+
assertMarkdownReExport('> blockquote');
293+
});
294+
295+
test('can re-export a code block', () => {
296+
assertMarkdownReExport('```\nconsole.log(123);\n```');
297+
});
298+
299+
test.skip('can re-export a code with language specified', () => {
300+
assertMarkdownReExport('```js\nconsole.log(123);\n```');
301+
});
302+
303+
test('can re-export various block elements', () => {
304+
assertMarkdownReExport('paragraph\n\n> blockquote');
305+
});
306+
307+
test('can re-export various block elements', () => {
308+
assertMarkdownReExport('paragraph\n\n> blockquote');
309+
assertMarkdownReExport('paragraph\n\n> blockquot e\n\n```\ncode block\n```');
310+
assertMarkdownReExport('paragraph\n\n> blockquot e\n\n```\ncode block\n```\n\nparagraph 2');
311+
assertMarkdownReExport('paragraph\n\n> blockquot e\n\n```\ncode block\n```\n\nparagraph 2\n\n> blockquote 2');
312+
});
313+
314+
test('can re-export various block elements with inline formatting', () => {
315+
assertMarkdownReExport('par_a_g`a`ph\n\n> blo__c__kqu`o`te');
316+
assertMarkdownReExport('par_a_g`a`ph\n\n> blo__c__kqu`o`te e\n\n```\ncode block\n```');
317+
assertMarkdownReExport('par_a_g`a`ph\n\n> blo__c__kqu`o`te e\n\n```\ncode block\n```\n\npar_a_g`a`ph 2');
318+
assertMarkdownReExport(
319+
'par_a_g`a`ph\n\n> blo__c__kqu`o`te e\n\n```\ncode block\n```\n\npar_a_g`a`ph 2\n\n> blo__c__kqu`o`te 2',
320+
);
321+
});
322+
323+
test('can re-export demo text', () => {
324+
const markdown =
325+
'The German __automotive sector__ is in the process of _cutting ' +
326+
'thousands of jobs_ as it grapples with a global shift toward electric vehicles ' +
327+
'— a transformation Musk himself has been at the forefront of.' +
328+
'\n\n' +
329+
'> To be, or not to be: that is the question.' +
330+
'\n\n' +
331+
'This is code:' +
332+
'\n\n' +
333+
'```' +
334+
'\n' +
335+
'console.log(123);' +
336+
'\n' +
337+
'```' +
338+
'\n\n' +
339+
'A `ClipboardEvent` is dispatched for copy, cut, and paste events, and it contains ' +
340+
'a `clipboardData` property of type `DataTransfer`. The `DataTransfer` object ' +
341+
'is used by the Clipboard Events API to hold multiple representations of data.';
342+
assertMarkdownReExport(markdown);
343+
});
275344
});

0 commit comments

Comments
 (0)