@@ -1210,6 +1210,50 @@ test('heading', (t) => {
1210
1210
'should not escape a `#` in a heading (2)'
1211
1211
)
1212
1212
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
+
1213
1257
t . end ( )
1214
1258
} )
1215
1259
@@ -1507,7 +1551,7 @@ test('imageReference', (t) => {
1507
1551
t . end ( )
1508
1552
} )
1509
1553
1510
- test ( 'Code text' , ( t ) => {
1554
+ test ( 'code ( text) ' , ( t ) => {
1511
1555
// @ts -expect-error: `value` missing.
1512
1556
t . equal ( to ( { type : 'inlineCode' } ) , '``\n' , 'should support an empty code text' )
1513
1557
@@ -2733,6 +2777,42 @@ test('paragraph', (t) => {
2733
2777
'should support a paragraph'
2734
2778
)
2735
2779
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
+
2736
2816
t . end ( )
2737
2817
} )
2738
2818
@@ -2769,6 +2849,7 @@ test('text', (t) => {
2769
2849
t . equal ( to ( { type : 'text' } ) , '' , 'should support a void text' )
2770
2850
t . equal ( to ( { type : 'text' , value : '' } ) , '' , 'should support an empty text' )
2771
2851
t . equal ( to ( { type : 'text' , value : 'a\nb' } ) , 'a\nb\n' , 'should support text' )
2852
+
2772
2853
t . end ( )
2773
2854
} )
2774
2855
@@ -3488,5 +3569,21 @@ test('roundtrip', (t) => {
3488
3569
'should roundtrip different lists w/ `bulletOrderedOther` and lists that could turn into thematic breaks (6)'
3489
3570
)
3490
3571
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
+
3491
3588
t . end ( )
3492
3589
} )
0 commit comments