@@ -1210,6 +1210,50 @@ test('heading', (t) => {
12101210 'should not escape a `#` in a heading (2)'
12111211 )
12121212
1213+ t . equal (
1214+ to ( { type : 'heading' , depth : 1 , children : [ { type : 'text' , value : ' a' } ] } ) ,
1215+ '#   a\n' ,
1216+ 'should encode a space at the start of an atx heading'
1217+ )
1218+
1219+ t . equal (
1220+ to ( { type : 'heading' , depth : 1 , children : [ { type : 'text' , value : '\t\ta' } ] } ) ,
1221+ '# 	\ta\n' ,
1222+ 'should encode a tab at the start of an atx heading'
1223+ )
1224+
1225+ t . equal (
1226+ to ( { type : 'heading' , depth : 1 , children : [ { type : 'text' , value : 'a ' } ] } ) ,
1227+ '# a  \n' ,
1228+ 'should encode a space at the end of an atx heading'
1229+ )
1230+
1231+ t . equal (
1232+ to ( { type : 'heading' , depth : 1 , children : [ { type : 'text' , value : 'a\t\t' } ] } ) ,
1233+ '# a\t	\n' ,
1234+ 'should encode a tab at the end of an atx heading'
1235+ )
1236+
1237+ t . equal (
1238+ to ( {
1239+ type : 'heading' ,
1240+ depth : 1 ,
1241+ children : [ { type : 'text' , value : 'a \n b' } ]
1242+ } ) ,
1243+ 'a \n b\n=======\n' ,
1244+ 'should encode spaces around a line ending in a setext heading'
1245+ )
1246+
1247+ t . equal (
1248+ to ( {
1249+ type : 'heading' ,
1250+ depth : 3 ,
1251+ children : [ { type : 'text' , value : 'a \n b' } ]
1252+ } ) ,
1253+ '### a 
 b\n' ,
1254+ 'should not need to encode spaces around a line ending in an atx heading (because the line ending is encoded)'
1255+ )
1256+
12131257 t . end ( )
12141258} )
12151259
@@ -1507,7 +1551,7 @@ test('imageReference', (t) => {
15071551 t . end ( )
15081552} )
15091553
1510- test ( 'Code text' , ( t ) => {
1554+ test ( 'code ( text) ' , ( t ) => {
15111555 // @ts -expect-error: `value` missing.
15121556 t . equal ( to ( { type : 'inlineCode' } ) , '``\n' , 'should support an empty code text' )
15131557
@@ -2733,6 +2777,42 @@ test('paragraph', (t) => {
27332777 'should support a paragraph'
27342778 )
27352779
2780+ t . equal (
2781+ to ( { type : 'paragraph' , children : [ { type : 'text' , value : ' a' } ] } ) ,
2782+ '  a\n' ,
2783+ 'should encode spaces at the start of paragraphs'
2784+ )
2785+
2786+ t . equal (
2787+ to ( { type : 'paragraph' , children : [ { type : 'text' , value : 'a ' } ] } ) ,
2788+ 'a  \n' ,
2789+ 'should encode spaces at the end of paragraphs'
2790+ )
2791+
2792+ t . equal (
2793+ to ( { type : 'paragraph' , children : [ { type : 'text' , value : '\t\ta' } ] } ) ,
2794+ '	\ta\n' ,
2795+ 'should encode tabs at the start of paragraphs'
2796+ )
2797+
2798+ t . equal (
2799+ to ( { type : 'paragraph' , children : [ { type : 'text' , value : 'a\t\t' } ] } ) ,
2800+ 'a\t	\n' ,
2801+ 'should encode tabs at the end of paragraphs'
2802+ )
2803+
2804+ t . equal (
2805+ to ( { type : 'paragraph' , children : [ { type : 'text' , value : 'a \n b' } ] } ) ,
2806+ 'a  \n  b\n' ,
2807+ 'should encode spaces around line endings in paragraphs'
2808+ )
2809+
2810+ t . equal (
2811+ to ( { type : 'paragraph' , children : [ { type : 'text' , value : 'a\t\t\n\t\tb' } ] } ) ,
2812+ 'a\t	\n	\tb\n' ,
2813+ 'should encode spaces around line endings in paragraphs'
2814+ )
2815+
27362816 t . end ( )
27372817} )
27382818
@@ -2769,6 +2849,7 @@ test('text', (t) => {
27692849 t . equal ( to ( { type : 'text' } ) , '' , 'should support a void text' )
27702850 t . equal ( to ( { type : 'text' , value : '' } ) , '' , 'should support an empty text' )
27712851 t . equal ( to ( { type : 'text' , value : 'a\nb' } ) , 'a\nb\n' , 'should support text' )
2852+
27722853 t . end ( )
27732854} )
27742855
@@ -3488,5 +3569,21 @@ test('roundtrip', (t) => {
34883569 'should roundtrip different lists w/ `bulletOrderedOther` and lists that could turn into thematic breaks (6)'
34893570 )
34903571
3572+ doc = ' \n'
3573+
3574+ t . equal ( to ( from ( doc ) ) , doc , 'should roundtrip a single encoded space' )
3575+
3576+ doc = '	\n'
3577+
3578+ t . equal ( to ( from ( doc ) ) , doc , 'should roundtrip a single encoded tab' )
3579+
3580+ doc = '  a  \n	\tb\t	\n'
3581+
3582+ t . equal (
3583+ to ( from ( doc ) ) ,
3584+ doc ,
3585+ 'should roundtrip encoded spaces and tabs where needed'
3586+ )
3587+
34913588 t . end ( )
34923589} )
0 commit comments