@docusaurus/utils 2.0.0-beta.fc64c12e4 → 2.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.
Files changed (113) hide show
  1. package/lib/constants.d.ts +73 -0
  2. package/lib/constants.d.ts.map +1 -0
  3. package/lib/constants.js +78 -0
  4. package/lib/constants.js.map +1 -0
  5. package/lib/dataFileUtils.d.ts +60 -0
  6. package/lib/dataFileUtils.d.ts.map +1 -0
  7. package/lib/dataFileUtils.js +91 -0
  8. package/lib/dataFileUtils.js.map +1 -0
  9. package/lib/emitUtils.d.ts +32 -0
  10. package/lib/emitUtils.d.ts.map +1 -0
  11. package/lib/emitUtils.js +80 -0
  12. package/lib/emitUtils.js.map +1 -0
  13. package/lib/gitUtils.d.ts +66 -0
  14. package/lib/gitUtils.d.ts.map +1 -0
  15. package/lib/gitUtils.js +63 -0
  16. package/lib/gitUtils.js.map +1 -0
  17. package/lib/globUtils.d.ts +29 -0
  18. package/lib/globUtils.d.ts.map +1 -0
  19. package/lib/globUtils.js +36 -12
  20. package/lib/globUtils.js.map +1 -0
  21. package/lib/hashUtils.d.ts +6 -4
  22. package/lib/hashUtils.d.ts.map +1 -0
  23. package/lib/hashUtils.js +13 -10
  24. package/lib/hashUtils.js.map +1 -0
  25. package/lib/i18nUtils.d.ts +53 -0
  26. package/lib/i18nUtils.d.ts.map +1 -0
  27. package/lib/i18nUtils.js +70 -0
  28. package/lib/i18nUtils.js.map +1 -0
  29. package/lib/index.d.ts +15 -75
  30. package/lib/index.d.ts.map +1 -0
  31. package/lib/index.js +86 -395
  32. package/lib/index.js.map +1 -0
  33. package/lib/jsUtils.d.ts +28 -0
  34. package/lib/jsUtils.d.ts.map +1 -0
  35. package/lib/jsUtils.js +57 -0
  36. package/lib/jsUtils.js.map +1 -0
  37. package/lib/markdownLinks.d.ts +49 -5
  38. package/lib/markdownLinks.d.ts.map +1 -0
  39. package/lib/markdownLinks.js +57 -13
  40. package/lib/markdownLinks.js.map +1 -0
  41. package/lib/markdownUtils.d.ts +112 -0
  42. package/lib/markdownUtils.d.ts.map +1 -0
  43. package/lib/markdownUtils.js +271 -0
  44. package/lib/markdownUtils.js.map +1 -0
  45. package/lib/pathUtils.d.ts +45 -1
  46. package/lib/pathUtils.d.ts.map +1 -0
  47. package/lib/pathUtils.js +92 -12
  48. package/lib/pathUtils.js.map +1 -0
  49. package/lib/shellUtils.d.ts +8 -0
  50. package/lib/shellUtils.d.ts.map +1 -0
  51. package/lib/shellUtils.js +21 -0
  52. package/lib/shellUtils.js.map +1 -0
  53. package/lib/slugger.d.ts +24 -0
  54. package/lib/slugger.d.ts.map +1 -0
  55. package/lib/slugger.js +23 -0
  56. package/lib/slugger.js.map +1 -0
  57. package/lib/tags.d.ts +59 -0
  58. package/lib/tags.d.ts.map +1 -0
  59. package/lib/tags.js +91 -0
  60. package/lib/tags.js.map +1 -0
  61. package/lib/urlUtils.d.ts +66 -0
  62. package/lib/urlUtils.d.ts.map +1 -0
  63. package/lib/urlUtils.js +207 -0
  64. package/lib/urlUtils.js.map +1 -0
  65. package/lib/webpackUtils.d.ts +35 -0
  66. package/lib/webpackUtils.d.ts.map +1 -0
  67. package/lib/webpackUtils.js +115 -0
  68. package/lib/webpackUtils.js.map +1 -0
  69. package/package.json +27 -12
  70. package/src/constants.ts +98 -0
  71. package/src/dataFileUtils.ts +122 -0
  72. package/src/deps.d.ts +10 -0
  73. package/src/emitUtils.ts +99 -0
  74. package/src/gitUtils.ts +146 -0
  75. package/src/globUtils.ts +37 -15
  76. package/src/hashUtils.ts +9 -8
  77. package/src/i18nUtils.ts +114 -0
  78. package/src/index.ts +91 -502
  79. package/src/jsUtils.ts +59 -0
  80. package/src/markdownLinks.ts +101 -30
  81. package/src/markdownUtils.ts +357 -0
  82. package/src/pathUtils.ts +93 -12
  83. package/src/shellUtils.ts +18 -0
  84. package/src/slugger.ts +36 -0
  85. package/src/tags.ts +130 -0
  86. package/src/urlUtils.ts +234 -0
  87. package/src/webpackUtils.ts +153 -0
  88. package/lib/.tsbuildinfo +0 -1
  89. package/lib/codeTranslationsUtils.d.ts +0 -11
  90. package/lib/codeTranslationsUtils.js +0 -50
  91. package/lib/escapePath.d.ts +0 -17
  92. package/lib/escapePath.js +0 -25
  93. package/lib/markdownParser.d.ts +0 -30
  94. package/lib/markdownParser.js +0 -140
  95. package/lib/posixPath.d.ts +0 -14
  96. package/lib/posixPath.js +0 -28
  97. package/src/__tests__/__fixtures__/defaultCodeTranslations/en.json +0 -4
  98. package/src/__tests__/__fixtures__/defaultCodeTranslations/fr-FR.json +0 -5
  99. package/src/__tests__/__fixtures__/defaultCodeTranslations/fr.json +0 -4
  100. package/src/__tests__/__snapshots__/index.test.ts.snap +0 -8
  101. package/src/__tests__/codeTranslationsUtils.test.ts +0 -112
  102. package/src/__tests__/escapePath.test.ts +0 -25
  103. package/src/__tests__/globUtils.test.ts +0 -109
  104. package/src/__tests__/hashUtils.test.ts +0 -51
  105. package/src/__tests__/index.test.ts +0 -631
  106. package/src/__tests__/markdownParser.test.ts +0 -817
  107. package/src/__tests__/pathUtils.test.ts +0 -63
  108. package/src/__tests__/posixPath.test.ts +0 -25
  109. package/src/codeTranslationsUtils.ts +0 -56
  110. package/src/escapePath.ts +0 -23
  111. package/src/markdownParser.ts +0 -182
  112. package/src/posixPath.ts +0 -27
  113. package/tsconfig.json +0 -9
@@ -1,817 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- import {
9
- createExcerpt,
10
- parseMarkdownContentTitle,
11
- parseMarkdownString,
12
- } from '../markdownParser';
13
- import dedent from 'dedent';
14
-
15
- describe('createExcerpt', () => {
16
- test('should create excerpt for text-only content', () => {
17
- expect(
18
- createExcerpt(dedent`
19
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ex urna, molestie et sagittis ut, varius ac justo.
20
-
21
- Nunc porttitor libero nec vulputate venenatis. Nam nec rhoncus mauris. Morbi tempus est et nibh maximus, tempus venenatis arcu lobortis.
22
- `),
23
- ).toEqual(
24
- 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ex urna, molestie et sagittis ut, varius ac justo.',
25
- );
26
- });
27
-
28
- test('should create excerpt for regular content with regular title', () => {
29
- expect(
30
- createExcerpt(dedent`
31
-
32
- # Markdown Regular Title
33
-
34
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ex urna, molestie et sagittis ut, varius ac justo.
35
-
36
- Nunc porttitor libero nec vulputate venenatis. Nam nec rhoncus mauris. Morbi tempus est et nibh maximus, tempus venenatis arcu lobortis.
37
- `),
38
- ).toEqual(
39
- // h1 title is skipped on purpose, because we don't want the page to have SEO metadatas title === description
40
- 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ex urna, molestie et sagittis ut, varius ac justo.',
41
- );
42
- });
43
-
44
- test('should create excerpt for regular content with alternate title', () => {
45
- expect(
46
- createExcerpt(dedent`
47
-
48
- Markdown Alternate Title
49
- ================
50
-
51
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ex urna, molestie et sagittis ut, varius ac justo.
52
-
53
- Nunc porttitor libero nec vulputate venenatis. Nam nec rhoncus mauris. Morbi tempus est et nibh maximus, tempus venenatis arcu lobortis.
54
- `),
55
- ).toEqual(
56
- // h1 title is skipped on purpose, because we don't want the page to have SEO metadatas title === description
57
- 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ex urna, molestie et sagittis ut, varius ac justo.',
58
- );
59
- });
60
-
61
- test('should create excerpt for content with h2 heading', () => {
62
- expect(
63
- createExcerpt(dedent`
64
- ## Lorem ipsum dolor sit amet
65
-
66
- Nunc porttitor libero nec vulputate venenatis. Nam nec rhoncus mauris. Morbi tempus est et nibh maximus, tempus venenatis arcu lobortis.
67
- `),
68
- ).toEqual('Lorem ipsum dolor sit amet');
69
- });
70
-
71
- test('should create excerpt for content beginning with blockquote', () => {
72
- expect(
73
- createExcerpt(dedent`
74
- > Lorem ipsum dolor sit amet
75
-
76
- Nunc porttitor libero nec vulputate venenatis. Nam nec rhoncus mauris. Morbi tempus est et nibh maximus, tempus venenatis arcu lobortis.
77
- `),
78
- ).toEqual('Lorem ipsum dolor sit amet');
79
- });
80
-
81
- test('should create excerpt for content beginning with image (eg. blog post)', () => {
82
- expect(
83
- createExcerpt(dedent`
84
- ![Lorem ipsum](/img/lorem-ipsum.svg)
85
- `),
86
- ).toEqual('Lorem ipsum');
87
- });
88
-
89
- test('should create excerpt for content beginning with admonitions', () => {
90
- expect(
91
- createExcerpt(dedent`
92
- import Component from '@site/src/components/Component'
93
-
94
- :::caution
95
-
96
- Lorem ipsum dolor sit amet, consectetur adipiscing elit.
97
-
98
- :::
99
-
100
- Nunc porttitor libero nec vulputate venenatis. Nam nec rhoncus mauris. Morbi tempus est et nibh maximus, tempus venenatis arcu lobortis.
101
- `),
102
- ).toEqual('Lorem ipsum dolor sit amet, consectetur adipiscing elit.');
103
- });
104
-
105
- test('should create excerpt for content with imports/exports declarations and Markdown markup, as well as Emoji', () => {
106
- expect(
107
- createExcerpt(dedent`
108
- import Component from '@site/src/components/Component';
109
- import Component from '@site/src/components/Component'
110
- import './styles.css';
111
-
112
- export function ItemCol(props) { return <Item {...props} className={'col col--6 margin-bottom--lg'}/> }
113
-
114
- export function ItemCol(props) { return <Item {...props} className={'col col--6 margin-bottom--lg'}/> };
115
-
116
- Lorem **ipsum** dolor sit \`amet\`[^1], consectetur _adipiscing_ elit. [**Vestibulum**](https://wiktionary.org/wiki/vestibulum) ex urna[^bignote], ~molestie~ et sagittis ut, varius ac justo :wink:.
117
-
118
- Nunc porttitor libero nec vulputate venenatis. Nam nec rhoncus mauris. Morbi tempus est et nibh maximus, tempus venenatis arcu lobortis.
119
- `),
120
- ).toEqual(
121
- 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ex urna, molestie et sagittis ut, varius ac justo.',
122
- );
123
- });
124
-
125
- test('should create excerpt for heading specified with anchor-id syntax', () => {
126
- expect(
127
- createExcerpt(dedent`
128
- ## Markdown title {#my-anchor-id}
129
- `),
130
- ).toEqual('Markdown title');
131
- });
132
- });
133
-
134
- describe('parseMarkdownContentTitle', () => {
135
- test('Should parse markdown h1 title at the top', () => {
136
- const markdown = dedent`
137
-
138
- # Markdown Title
139
-
140
- Lorem Ipsum
141
-
142
- `;
143
- expect(parseMarkdownContentTitle(markdown)).toEqual({
144
- content: markdown,
145
- contentTitle: 'Markdown Title',
146
- });
147
- });
148
-
149
- test('Should parse markdown h1 title at the top and remove it', () => {
150
- const markdown = dedent`
151
-
152
- # Markdown Title
153
-
154
- Lorem Ipsum
155
-
156
- `;
157
- expect(
158
- parseMarkdownContentTitle(markdown, {removeContentTitle: true}),
159
- ).toEqual({
160
- content: 'Lorem Ipsum',
161
- contentTitle: 'Markdown Title',
162
- });
163
- });
164
-
165
- test('Should parse markdown h1 title at the top and unwrap inline code block', () => {
166
- const markdown = dedent`
167
-
168
- # \`Markdown Title\`
169
-
170
- Lorem Ipsum
171
-
172
- `;
173
- expect(parseMarkdownContentTitle(markdown)).toEqual({
174
- content: markdown,
175
- contentTitle: 'Markdown Title',
176
- });
177
- });
178
-
179
- test('Should parse markdown h1 title and trim content', () => {
180
- const markdown = `
181
-
182
- # Markdown Title
183
-
184
- Lorem Ipsum
185
-
186
-
187
-
188
- `;
189
-
190
- expect(parseMarkdownContentTitle(markdown)).toEqual({
191
- content: markdown.trim(),
192
- contentTitle: 'Markdown Title',
193
- });
194
- });
195
-
196
- test('Should parse not parse markdown h1 title and trim content', () => {
197
- const markdown = `
198
-
199
- Lorem Ipsum
200
-
201
- `;
202
-
203
- expect(parseMarkdownContentTitle(markdown)).toEqual({
204
- content: markdown.trim(),
205
- contentTitle: undefined,
206
- });
207
- });
208
-
209
- test('Should parse markdown h1 title with fixed anchor-id syntax', () => {
210
- const markdown = dedent`
211
-
212
- # Markdown Title {#my-anchor-id}
213
-
214
- Lorem Ipsum
215
-
216
- `;
217
- expect(parseMarkdownContentTitle(markdown)).toEqual({
218
- content: markdown,
219
- contentTitle: 'Markdown Title',
220
- });
221
- });
222
-
223
- test('Should parse markdown h1 title at the top (atx style with closing #)', () => {
224
- const markdown = dedent`
225
-
226
- # Markdown Title #
227
-
228
- Lorem Ipsum
229
-
230
- `;
231
- expect(parseMarkdownContentTitle(markdown)).toEqual({
232
- content: markdown,
233
- contentTitle: 'Markdown Title',
234
- });
235
- });
236
-
237
- test('Should parse markdown h1 title at the top followed by h2 title', () => {
238
- const markdown = dedent`
239
-
240
- # Markdown Title
241
-
242
- ## Heading 2
243
-
244
- Lorem Ipsum
245
-
246
- `;
247
- expect(parseMarkdownContentTitle(markdown)).toEqual({
248
- content: markdown,
249
- contentTitle: 'Markdown Title',
250
- });
251
- });
252
-
253
- test('Should parse only first h1 title', () => {
254
- const markdown = dedent`
255
-
256
- # Markdown Title
257
-
258
- # Markdown Title 2
259
-
260
- Lorem Ipsum
261
-
262
- `;
263
- expect(parseMarkdownContentTitle(markdown)).toEqual({
264
- content: markdown,
265
- contentTitle: 'Markdown Title',
266
- });
267
- });
268
-
269
- test('Should not parse title that is not at the top', () => {
270
- const markdown = dedent`
271
-
272
- Lorem Ipsum
273
-
274
- # Markdown Title 2
275
-
276
- Lorem Ipsum
277
-
278
- `;
279
- expect(parseMarkdownContentTitle(markdown)).toEqual({
280
- content: markdown,
281
- contentTitle: undefined,
282
- });
283
- });
284
-
285
- test('Should parse markdown h1 alternate title', () => {
286
- const markdown = dedent`
287
-
288
- Markdown Title
289
- ================
290
-
291
- Lorem Ipsum
292
-
293
- `;
294
- expect(parseMarkdownContentTitle(markdown)).toEqual({
295
- content: markdown,
296
- contentTitle: 'Markdown Title',
297
- });
298
- });
299
-
300
- test('Should parse markdown h1 alternate title and remove it', () => {
301
- const markdown = dedent`
302
-
303
- Markdown Title
304
- ================
305
-
306
- Lorem Ipsum
307
-
308
- `;
309
- expect(
310
- parseMarkdownContentTitle(markdown, {removeContentTitle: true}),
311
- ).toEqual({
312
- content: 'Lorem Ipsum',
313
- contentTitle: 'Markdown Title',
314
- });
315
- });
316
-
317
- test('Should parse markdown h1 title placed after import declarations', () => {
318
- const markdown = dedent`
319
- import Component1 from '@site/src/components/Component1';
320
-
321
- import Component2 from '@site/src/components/Component2'
322
- import Component3 from '@site/src/components/Component3'
323
- import './styles.css';
324
-
325
- # Markdown Title
326
-
327
- Lorem Ipsum
328
-
329
- `;
330
-
331
- // remove the useless line breaks? Does not matter too much
332
- expect(parseMarkdownContentTitle(markdown)).toEqual({
333
- content: markdown,
334
- contentTitle: 'Markdown Title',
335
- });
336
- });
337
-
338
- test('Should parse markdown h1 title placed after various import declarations', () => {
339
- const markdown = `
340
- import DefaultComponent from '@site/src/components/Component1';
341
- import DefaultComponent2 from '../relative/path/Component2';
342
- import * as EntireComponent from './relative/path/Component3';
343
-
344
- import { Component4 } from "double-quote-module-name";
345
- import { Component51, Component52, \n Component53, \n\t\t Component54 } from "double-quote-module-name";
346
- import { Component6 as AliasComponent6 } from "module-name";
347
- import DefaultComponent8, { DefaultComponent81 ,\nDefaultComponent82 } from "module-name";
348
- import DefaultComponent9, * as EntireComponent9 from "module-name";
349
- import {Component71,\nComponent72 as AliasComponent72,\nComponent73\n} \nfrom "module-name";
350
-
351
- import './styles.css';
352
- import _ from 'underscore';
353
- import "module-name"
354
-
355
- # Markdown Title
356
-
357
- Lorem Ipsum
358
- `;
359
-
360
- expect(parseMarkdownContentTitle(markdown)).toEqual({
361
- content: markdown.trim(),
362
- contentTitle: 'Markdown Title',
363
- });
364
- });
365
-
366
- test('Should parse markdown h1 title placed after various import declarations and remove it', () => {
367
- const markdown = `
368
- import DefaultComponent from '@site/src/components/Component1';
369
- import DefaultComponent2 from '../relative/path/Component2';
370
- import * as EntireComponent from './relative/path/Component3';
371
-
372
- import { Component4 } from "double-quote-module-name";
373
- import { Component51, Component52, \n Component53, \n\t\t Component54 } from "double-quote-module-name";
374
- import { Component6 as AliasComponent6 } from "module-name";
375
- import DefaultComponent8, { DefaultComponent81 ,\nDefaultComponent82 } from "module-name";
376
- import DefaultComponent9, * as EntireComponent9 from "module-name";
377
- import {Component71,\nComponent72 as AliasComponent72,\nComponent73\n} \nfrom "module-name";
378
-
379
- import './styles.css';
380
- import _ from 'underscore';
381
- import "module-name"
382
-
383
- # Markdown Title
384
-
385
- Lorem Ipsum
386
- `;
387
-
388
- expect(
389
- parseMarkdownContentTitle(markdown, {removeContentTitle: true}),
390
- ).toEqual({
391
- content: markdown.trim().replace('# Markdown Title', ''),
392
- contentTitle: 'Markdown Title',
393
- });
394
- });
395
-
396
- test('Should parse markdown h1 alternate title placed after import declarations', () => {
397
- const markdown = dedent`
398
-
399
- import Component from '@site/src/components/Component';
400
- import Component from '@site/src/components/Component'
401
- import './styles.css';
402
-
403
- Markdown Title
404
- ==============
405
-
406
- Lorem Ipsum
407
-
408
- `;
409
- expect(parseMarkdownContentTitle(markdown)).toEqual({
410
- content: markdown,
411
- contentTitle: 'Markdown Title',
412
- });
413
- });
414
-
415
- test('Should parse markdown h1 alternate title placed after import declarations and remove it', () => {
416
- const markdown = dedent`
417
-
418
- import Component from '@site/src/components/Component';
419
- import Component from '@site/src/components/Component'
420
- import './styles.css';
421
-
422
- Markdown Title
423
- ==============
424
-
425
- Lorem Ipsum
426
-
427
- `;
428
- expect(
429
- parseMarkdownContentTitle(markdown, {removeContentTitle: true}),
430
- ).toEqual({
431
- content: markdown.replace('Markdown Title\n==============\n\n', ''),
432
- contentTitle: 'Markdown Title',
433
- });
434
- });
435
-
436
- test('Should parse title-only', () => {
437
- const markdown = '# Document With Only A Title';
438
- expect(parseMarkdownContentTitle(markdown)).toEqual({
439
- content: markdown,
440
- contentTitle: 'Document With Only A Title',
441
- });
442
- });
443
-
444
- test('Should not parse markdown h1 title in the middle of a doc', () => {
445
- const markdown = dedent`
446
-
447
- Lorem Ipsum
448
-
449
- # Markdown Title
450
-
451
- Lorem Ipsum
452
-
453
- `;
454
- expect(parseMarkdownContentTitle(markdown)).toEqual({
455
- content: markdown,
456
- contentTitle: undefined,
457
- });
458
- });
459
-
460
- test('Should not parse markdown h1 alternate title in the middle of the doc', () => {
461
- const markdown = dedent`
462
-
463
- Lorem Ipsum
464
-
465
- Markdown Title
466
- ================
467
-
468
- Lorem Ipsum
469
-
470
- `;
471
- expect(parseMarkdownContentTitle(markdown)).toEqual({
472
- content: markdown,
473
- contentTitle: undefined,
474
- });
475
- });
476
-
477
- test('Should parse markdown h1 title placed after multiple import declarations', () => {
478
- const markdown = dedent`
479
- import Component1 from '@site/src/components/Component1';
480
- import Component2 from '@site/src/components/Component2';
481
- import Component3 from '@site/src/components/Component3';
482
- import Component4 from '@site/src/components/Component4';
483
- import Component5 from '@site/src/components/Component5';
484
- import Component6 from '@site/src/components/Component6';
485
- import Component7 from '@site/src/components/Component7';
486
- import Component8 from '@site/src/components/Component8';
487
- import Component9 from '@site/src/components/Component9';
488
- import Component10 from '@site/src/components/Component10';
489
- import Component11 from '@site/src/components/Component11';
490
- import Component12 from '@site/src/components/Component12';
491
- import Component13 from '@site/src/components/Component13';
492
- import Component14 from '@site/src/components/Component14';
493
- import Component15 from '@site/src/components/Component15';
494
-
495
- # Markdown Title
496
-
497
- Lorem Ipsum
498
-
499
- `;
500
-
501
- expect(parseMarkdownContentTitle(markdown)).toEqual({
502
- content: markdown,
503
- contentTitle: 'Markdown Title',
504
- });
505
- });
506
-
507
- test('Should parse markdown h1 title placed after multiple import declarations and remove it', () => {
508
- const markdown = dedent`
509
- import Component1 from '@site/src/components/Component1';
510
- import Component2 from '@site/src/components/Component2';
511
- import Component3 from '@site/src/components/Component3';
512
- import Component4 from '@site/src/components/Component4';
513
- import Component5 from '@site/src/components/Component5';
514
- import Component6 from '@site/src/components/Component6';
515
- import Component7 from '@site/src/components/Component7';
516
- import Component8 from '@site/src/components/Component8';
517
- import Component9 from '@site/src/components/Component9';
518
- import Component10 from '@site/src/components/Component10';
519
- import Component11 from '@site/src/components/Component11';
520
- import Component12 from '@site/src/components/Component12';
521
- import Component13 from '@site/src/components/Component13';
522
- import Component14 from '@site/src/components/Component14';
523
- import Component15 from '@site/src/components/Component15';
524
-
525
- # Markdown Title
526
-
527
- Lorem Ipsum
528
-
529
- `;
530
-
531
- expect(
532
- parseMarkdownContentTitle(markdown, {removeContentTitle: true}),
533
- ).toEqual({
534
- content: markdown.replace('# Markdown Title', ''),
535
- contentTitle: 'Markdown Title',
536
- });
537
- });
538
- });
539
-
540
- describe('parseMarkdownString', () => {
541
- test('parse markdown with frontmatter', () => {
542
- expect(
543
- parseMarkdownString(dedent`
544
- ---
545
- title: Frontmatter title
546
- ---
547
-
548
- Some text
549
- `),
550
- ).toMatchInlineSnapshot(`
551
- Object {
552
- "content": "Some text",
553
- "contentTitle": undefined,
554
- "excerpt": "Some text",
555
- "frontMatter": Object {
556
- "title": "Frontmatter title",
557
- },
558
- }
559
- `);
560
- });
561
-
562
- test('should parse first heading as contentTitle', () => {
563
- expect(
564
- parseMarkdownString(dedent`
565
- # Markdown Title
566
-
567
- Some text
568
- `),
569
- ).toMatchInlineSnapshot(`
570
- Object {
571
- "content": "# Markdown Title
572
-
573
- Some text",
574
- "contentTitle": "Markdown Title",
575
- "excerpt": "Some text",
576
- "frontMatter": Object {},
577
- }
578
- `);
579
- });
580
-
581
- test('should warn about duplicate titles (frontmatter + markdown)', () => {
582
- expect(
583
- parseMarkdownString(dedent`
584
- ---
585
- title: Frontmatter title
586
- ---
587
-
588
- # Markdown Title
589
-
590
- Some text
591
- `),
592
- ).toMatchInlineSnapshot(`
593
- Object {
594
- "content": "# Markdown Title
595
-
596
- Some text",
597
- "contentTitle": "Markdown Title",
598
- "excerpt": "Some text",
599
- "frontMatter": Object {
600
- "title": "Frontmatter title",
601
- },
602
- }
603
- `);
604
- });
605
-
606
- test('should warn about duplicate titles (frontmatter + markdown alternate)', () => {
607
- expect(
608
- parseMarkdownString(dedent`
609
- ---
610
- title: Frontmatter title
611
- ---
612
-
613
- Markdown Title alternate
614
- ================
615
-
616
- Some text
617
- `),
618
- ).toMatchInlineSnapshot(`
619
- Object {
620
- "content": "Markdown Title alternate
621
- ================
622
-
623
- Some text",
624
- "contentTitle": "Markdown Title alternate",
625
- "excerpt": "Some text",
626
- "frontMatter": Object {
627
- "title": "Frontmatter title",
628
- },
629
- }
630
- `);
631
- });
632
-
633
- test('should not warn for duplicate title if markdown title is not at the top', () => {
634
- expect(
635
- parseMarkdownString(dedent`
636
- ---
637
- title: Frontmatter title
638
- ---
639
-
640
- foo
641
-
642
- # Markdown Title
643
- `),
644
- ).toMatchInlineSnapshot(`
645
- Object {
646
- "content": "foo
647
-
648
- # Markdown Title",
649
- "contentTitle": undefined,
650
- "excerpt": "foo",
651
- "frontMatter": Object {
652
- "title": "Frontmatter title",
653
- },
654
- }
655
- `);
656
- });
657
-
658
- test('should delete only first heading', () => {
659
- expect(
660
- parseMarkdownString(dedent`
661
- # Markdown Title
662
-
663
- test test test # test bar
664
-
665
- # Markdown Title 2
666
-
667
- ### Markdown Title h3
668
- `),
669
- ).toMatchInlineSnapshot(`
670
- Object {
671
- "content": "# Markdown Title
672
-
673
- test test test # test bar
674
-
675
- # Markdown Title 2
676
-
677
- ### Markdown Title h3",
678
- "contentTitle": "Markdown Title",
679
- "excerpt": "test test test # test bar",
680
- "frontMatter": Object {},
681
- }
682
- `);
683
- });
684
-
685
- test('should parse front-matter and ignore h2', () => {
686
- expect(
687
- parseMarkdownString(
688
- dedent`
689
- ---
690
- title: Frontmatter title
691
- ---
692
- ## test
693
- `,
694
- ),
695
- ).toMatchInlineSnapshot(`
696
- Object {
697
- "content": "## test",
698
- "contentTitle": undefined,
699
- "excerpt": "test",
700
- "frontMatter": Object {
701
- "title": "Frontmatter title",
702
- },
703
- }
704
- `);
705
- });
706
-
707
- test('should read front matter only', () => {
708
- expect(
709
- parseMarkdownString(dedent`
710
- ---
711
- title: test
712
- ---
713
- `),
714
- ).toMatchInlineSnapshot(`
715
- Object {
716
- "content": "",
717
- "contentTitle": undefined,
718
- "excerpt": undefined,
719
- "frontMatter": Object {
720
- "title": "test",
721
- },
722
- }
723
- `);
724
- });
725
-
726
- test('should parse title only', () => {
727
- expect(parseMarkdownString('# test')).toMatchInlineSnapshot(`
728
- Object {
729
- "content": "# test",
730
- "contentTitle": "test",
731
- "excerpt": undefined,
732
- "frontMatter": Object {},
733
- }
734
- `);
735
- });
736
-
737
- test('should parse title only alternate', () => {
738
- expect(
739
- parseMarkdownString(dedent`
740
- test
741
- ===
742
- `),
743
- ).toMatchInlineSnapshot(`
744
- Object {
745
- "content": "test
746
- ===",
747
- "contentTitle": "test",
748
- "excerpt": undefined,
749
- "frontMatter": Object {},
750
- }
751
- `);
752
- });
753
-
754
- test('should warn about duplicate titles', () => {
755
- expect(
756
- parseMarkdownString(dedent`
757
- ---
758
- title: Frontmatter title
759
- ---
760
- # test
761
- `),
762
- ).toMatchInlineSnapshot(`
763
- Object {
764
- "content": "# test",
765
- "contentTitle": "test",
766
- "excerpt": undefined,
767
- "frontMatter": Object {
768
- "title": "Frontmatter title",
769
- },
770
- }
771
- `);
772
- });
773
-
774
- test('should ignore markdown title if its not a first text', () => {
775
- expect(
776
- parseMarkdownString(dedent`
777
- foo
778
- # test
779
- `),
780
- ).toMatchInlineSnapshot(`
781
- Object {
782
- "content": "foo
783
- # test",
784
- "contentTitle": undefined,
785
- "excerpt": "foo",
786
- "frontMatter": Object {},
787
- }
788
- `);
789
- });
790
-
791
- test('should delete only first heading', () => {
792
- expect(
793
- parseMarkdownString(dedent`
794
- # test
795
-
796
- test test test test test test
797
- test test test # test bar
798
- # test2
799
- ### test
800
- test3
801
- `),
802
- ).toMatchInlineSnapshot(`
803
- Object {
804
- "content": "# test
805
-
806
- test test test test test test
807
- test test test # test bar
808
- # test2
809
- ### test
810
- test3",
811
- "contentTitle": "test",
812
- "excerpt": "test test test test test test",
813
- "frontMatter": Object {},
814
- }
815
- `);
816
- });
817
- });