@@ -17,6 +17,8 @@ const LINKED_MARKDOWN_FILE = 'test/fixtures/linked-markdown-file.md';
17
17
const PARTIALLY_LINKED_MARKDOWN_FILE = 'test/fixtures/partially-linked-markdown-file.md' ;
18
18
/** Markdown file that has unlinked Mermaid diagrams */
19
19
const UNLINKED_MARKDOWN_FILE = 'test/fixtures/unlinked-markdown-file.md' ;
20
+ /** Markdown file that has non-standard Markdown features like YAML frontmatter */
21
+ const UNUSUAL_MARKDOWN_FILE = 'test/fixtures/unusual-markdown-file.md' ;
20
22
21
23
type Optional < T > = T | undefined ;
22
24
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -323,6 +325,37 @@ describe('link', () => {
323
325
324
326
expect ( file ) . toMatch ( `id: second-id\n` ) ;
325
327
} ) ;
328
+
329
+ it ( 'should handle unusual markdown formatting' , async ( ) => {
330
+ const unusualMarkdownFile = 'test/output/unusual-markdown-file.md' ;
331
+ await copyFile ( UNUSUAL_MARKDOWN_FILE , unusualMarkdownFile ) ;
332
+
333
+ const { program } = mockedProgram ( ) ;
334
+
335
+ vi . mock ( '@inquirer/confirm' ) ;
336
+ vi . mock ( '@inquirer/select' ) ;
337
+ vi . mocked ( confirm ) . mockResolvedValue ( true ) ;
338
+ vi . mocked ( select ) . mockResolvedValueOnce ( mockedProjects [ 0 ] . id ) ;
339
+
340
+ vi . mocked ( MermaidChart . prototype . createDocument ) . mockResolvedValueOnce ( {
341
+ ...mockedEmptyDiagram ,
342
+ documentID : 'my-mocked-diagram-id' ,
343
+ } ) ;
344
+ await program . parseAsync ( [ '--config' , CONFIG_AUTHED , 'link' , unusualMarkdownFile ] , {
345
+ from : 'user' ,
346
+ } ) ;
347
+
348
+ const file = await readFile ( unusualMarkdownFile , { encoding : 'utf8' } ) ;
349
+
350
+ const idLineRegex = / ^ .* i d : m y - m o c k e d - d i a g r a m - i d \n / gm;
351
+
352
+ expect ( file ) . toMatch ( idLineRegex ) ;
353
+ // other than the added `id: xxxx` field, everything else should be identical,
354
+ // although in practice, we'd expect some formatting changes
355
+ expect ( file . replace ( idLineRegex , '' ) ) . toStrictEqual (
356
+ await readFile ( UNUSUAL_MARKDOWN_FILE , { encoding : 'utf8' } ) ,
357
+ ) ;
358
+ } ) ;
326
359
} ) ;
327
360
328
361
describe ( 'pull' , ( ) => {
0 commit comments