Welcome to mirror list, hosted at ThFree Co, Russian Federation.

remark_markdown_processing_spec.js « content_editor « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6348b97d91863066c77f6b256c67d960f89fd427 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import Bold from '~/content_editor/extensions/bold';
import Blockquote from '~/content_editor/extensions/blockquote';
import BulletList from '~/content_editor/extensions/bullet_list';
import Code from '~/content_editor/extensions/code';
import CodeBlockHighlight from '~/content_editor/extensions/code_block_highlight';
import HardBreak from '~/content_editor/extensions/hard_break';
import Heading from '~/content_editor/extensions/heading';
import HorizontalRule from '~/content_editor/extensions/horizontal_rule';
import Image from '~/content_editor/extensions/image';
import Italic from '~/content_editor/extensions/italic';
import Link from '~/content_editor/extensions/link';
import ListItem from '~/content_editor/extensions/list_item';
import OrderedList from '~/content_editor/extensions/ordered_list';
import Sourcemap from '~/content_editor/extensions/sourcemap';
import remarkMarkdownDeserializer from '~/content_editor/services/remark_markdown_deserializer';
import markdownSerializer from '~/content_editor/services/markdown_serializer';

import { createTestEditor } from './test_utils';

const tiptapEditor = createTestEditor({
  extensions: [
    Blockquote,
    Bold,
    BulletList,
    Code,
    CodeBlockHighlight,
    HardBreak,
    Heading,
    HorizontalRule,
    Image,
    Italic,
    Link,
    ListItem,
    OrderedList,
    Sourcemap,
  ],
});

describe('Client side Markdown processing', () => {
  const deserialize = async (content) => {
    const { document } = await remarkMarkdownDeserializer().deserialize({
      schema: tiptapEditor.schema,
      content,
    });

    return document;
  };

  const serialize = (document) =>
    markdownSerializer({}).serialize({
      doc: document,
      pristineDoc: document,
    });

  it.each([
    {
      markdown: '__bold text__',
    },
    {
      markdown: '**bold text**',
    },
    {
      markdown: '<strong>bold text</strong>',
    },
    {
      markdown: '<b>bold text</b>',
    },
    {
      markdown: '_italic text_',
    },
    {
      markdown: '*italic text*',
    },
    {
      markdown: '<em>italic text</em>',
    },
    {
      markdown: '<i>italic text</i>',
    },
    {
      markdown: '`inline code`',
    },
    {
      markdown: '**`inline code bold`**',
    },
    {
      markdown: '__`inline code italics`__',
    },
    {
      markdown: '[GitLab](https://gitlab.com "Go to GitLab")',
    },
    {
      markdown: '**[GitLab](https://gitlab.com "Go to GitLab")**',
    },
    {
      markdown: `
This is a paragraph with a\\
hard line break`,
    },
    {
      markdown: '![GitLab Logo](https://gitlab.com/logo.png "GitLab Logo")',
    },
    {
      markdown: '---',
    },
    {
      markdown: '***',
    },
    {
      markdown: '___',
    },
    {
      markdown: '<hr>',
    },
    {
      markdown: '# Heading 1',
    },
    {
      markdown: '## Heading 2',
    },
    {
      markdown: '### Heading 3',
    },
    {
      markdown: '#### Heading 4',
    },
    {
      markdown: '##### Heading 5',
    },
    {
      markdown: '###### Heading 6',
    },

    {
      markdown: `
    Heading
    one
    ======
    `,
    },
    {
      markdown: `
    Heading
    two
    -------
    `,
    },
    {
      markdown: `
    - List item 1
    - List item 2
    `,
    },
    {
      markdown: `
    * List item 1
    * List item 2
    `,
    },
    {
      markdown: `
    + List item 1
    + List item 2
    `,
    },
    {
      markdown: `
    1. List item 1
    1. List item 2
    `,
    },
    {
      markdown: `
    1. List item 1
    2. List item 2
    `,
    },
    {
      markdown: `
    1) List item 1
    2) List item 2
    `,
    },
    {
      markdown: `
    - List item 1
      - Sub list item 1
    `,
    },
    {
      markdown: `
    - List item 1 paragraph 1

      List item 1 paragraph 2
    - List item 2
    `,
    },
    {
      markdown: `
    > This is a blockquote
    `,
    },
    {
      markdown: `
    > - List item 1
    > - List item 2
    `,
    },
    {
      markdown: `
        const fn = () => 'GitLab';
    `,
    },
    {
      markdown: `
    \`\`\`javascript
      const fn = () => 'GitLab';
    \`\`\`\
    `,
    },
    {
      markdown: `
    ~~~javascript
      const fn = () => 'GitLab';
    ~~~
    `,
    },
    {
      markdown: `
    \`\`\`
    \`\`\`\
    `,
    },
    {
      markdown: `
    \`\`\`javascript
      const fn = () => 'GitLab';

    \`\`\`\
    `,
    },
  ])('processes %s correctly', async ({ markdown }) => {
    const trimmed = markdown.trim();
    const document = await deserialize(trimmed);

    expect(serialize(document)).toEqual(trimmed);
  });
});