@docusaurus/utils 2.0.0-beta.13 → 2.0.0-beta.15

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