@@ -509,30 +509,41 @@ describe('frontmatter', () => {
509509 const expected = '---\ntitle: Test\n---'
510510 expect ( autoCloseMarkdown ( input ) ) . toBe ( expected )
511511 } )
512- it ( 'should handle frontmatter partial' , ( ) => {
512+ // Partial frontmatter is only completed when `frontmatter: true` — for a
513+ // complete document a leading `---` with no closing delimiter is a thematic
514+ // break, so completing it would swallow the body (see the default cases below).
515+ it ( 'should complete partial frontmatter when frontmatter option is enabled' , ( ) => {
513516 const input = '---\ntitle: Test'
514517 const expected = '---\ntitle: Test\n---'
515- expect ( autoCloseMarkdown ( input ) ) . toBe ( expected )
518+ expect ( autoCloseMarkdown ( input , { frontmatter : true } ) ) . toBe ( expected )
516519 } )
517- it ( 'should handle frontmatter partial' , ( ) => {
520+ it ( 'should complete a partial closing delimiter (-) when frontmatter option is enabled ' , ( ) => {
518521 const input = '---\ntitle: Test\n-'
519522 const expected = '---\ntitle: Test\n---'
520- expect ( autoCloseMarkdown ( input ) ) . toBe ( expected )
523+ expect ( autoCloseMarkdown ( input , { frontmatter : true } ) ) . toBe ( expected )
521524 } )
522- it ( 'should handle frontmatter partial' , ( ) => {
525+ it ( 'should complete a partial closing delimiter (--) when frontmatter option is enabled ' , ( ) => {
523526 const input = '---\ntitle: Test\n--'
524527 const expected = '---\ntitle: Test\n---'
525- expect ( autoCloseMarkdown ( input ) ) . toBe ( expected )
528+ expect ( autoCloseMarkdown ( input , { frontmatter : true } ) ) . toBe ( expected )
526529 } )
527- it ( 'should handle frontmatter partial 2 ' , ( ) => {
530+ it ( 'should complete partial frontmatter with an empty value when frontmatter option is enabled ' , ( ) => {
528531 const input = '---\ntitle: '
529532 const expected = '---\ntitle: \n---'
530- expect ( autoCloseMarkdown ( input ) ) . toBe ( expected )
533+ expect ( autoCloseMarkdown ( input , { frontmatter : true } ) ) . toBe ( expected )
531534 } )
532- it ( 'should handle frontmatter partial 3 ' , ( ) => {
535+ it ( 'should complete partial frontmatter with a trailing newline when frontmatter option is enabled ' , ( ) => {
533536 const input = '---\ntitle: Test\n'
534537 const expected = '---\ntitle: Test\n---'
535- expect ( autoCloseMarkdown ( input ) ) . toBe ( expected )
538+ expect ( autoCloseMarkdown ( input , { frontmatter : true } ) ) . toBe ( expected )
539+ } )
540+
541+ it ( 'should not complete unclosed frontmatter by default' , ( ) => {
542+ // Default (`frontmatter: false`): a leading `---` with content but no close
543+ // is a thematic break followed by body — completing it would swallow the body.
544+ const input = '---\ntitle: Test'
545+ expect ( autoCloseMarkdown ( input ) ) . toBe ( input )
546+ expect ( autoCloseMarkdown ( '---\n# Heading' ) ) . toBe ( '---\n# Heading' )
536547 } )
537548
538549 it ( 'should handle frontmatter with content after' , ( ) => {
@@ -553,9 +564,17 @@ describe('frontmatter', () => {
553564 expect ( autoCloseMarkdown ( input ) ) . toBe ( expected )
554565 } )
555566
556- it ( 'should handle just opening ---' , ( ) => {
567+ it ( 'should not complete a lone --- (thematic break, not frontmatter)' , ( ) => {
568+ // A lone `---` has no frontmatter content; completing it to `---\n---`
569+ // would parse as two thematic breaks (#268).
557570 const input = '---'
558- const expected = '---\n---'
571+ const expected = '---'
572+ expect ( autoCloseMarkdown ( input ) ) . toBe ( expected )
573+ } )
574+
575+ it ( 'should not complete an empty --- opener' , ( ) => {
576+ const input = '---\n'
577+ const expected = '---\n'
559578 expect ( autoCloseMarkdown ( input ) ) . toBe ( expected )
560579 } )
561580
0 commit comments