@@ -773,6 +773,37 @@ static void render_commonmark(test_batch_runner *runner) {
773773 free (commonmark );
774774
775775 cmark_node_free (empty_item_doc );
776+
777+ // Hard line breaks are written as a backslash break in every position.
778+ // Two trailing spaces would be stripped as insignificant whitespace at the
779+ // start of a line, or after a space, losing the break on a round trip.
780+ static const char lead_break [] = "\\\nfoo\n" ;
781+ cmark_node * lead_break_doc =
782+ cmark_parse_document (lead_break , sizeof (lead_break ) - 1 , CMARK_OPT_DEFAULT );
783+ commonmark = cmark_render_commonmark (lead_break_doc , CMARK_OPT_DEFAULT , 0 );
784+ STR_EQ (runner , commonmark , "\\\nfoo\n" ,
785+ "render hard break at start of line" );
786+ free (commonmark );
787+ cmark_node_free (lead_break_doc );
788+
789+ static const char space_break [] = "foo \\\nbar\n" ;
790+ cmark_node * space_break_doc =
791+ cmark_parse_document (space_break , sizeof (space_break ) - 1 , CMARK_OPT_DEFAULT );
792+ commonmark = cmark_render_commonmark (space_break_doc , CMARK_OPT_DEFAULT , 0 );
793+ STR_EQ (runner , commonmark , "foo \\\nbar\n" ,
794+ "render hard break after a space" );
795+ free (commonmark );
796+ cmark_node_free (space_break_doc );
797+
798+ static const char plain_break [] = "foo\\\nbar\n" ;
799+ cmark_node * plain_break_doc =
800+ cmark_parse_document (plain_break , sizeof (plain_break ) - 1 , CMARK_OPT_DEFAULT );
801+ commonmark = cmark_render_commonmark (plain_break_doc , CMARK_OPT_DEFAULT , 0 );
802+ STR_EQ (runner , commonmark , "foo\\\nbar\n" ,
803+ "render ordinary hard break" );
804+ free (commonmark );
805+ cmark_node_free (plain_break_doc );
806+
776807 cmark_node_free (text );
777808 cmark_node_free (doc );
778809}
0 commit comments