@docusaurus/utils 2.0.0-beta.15d451942 → 2.0.0-beta.18

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