File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -1126,6 +1126,26 @@ static void source_pos_inlines(test_batch_runner *runner) {
11261126 free (xml );
11271127 cmark_node_free (doc );
11281128 }
1129+ {
1130+ static const char markdown [] =
1131+ "` It is one backtick\n"
1132+ "`` They are two backticks\n" ;
1133+
1134+ cmark_node * doc = cmark_parse_document (markdown , sizeof (markdown ) - 1 , CMARK_OPT_DEFAULT );
1135+ char * xml = cmark_render_xml (doc , CMARK_OPT_DEFAULT | CMARK_OPT_SOURCEPOS );
1136+ STR_EQ (runner , xml , "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1137+ "<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
1138+ "<document sourcepos=\"1:1-2:25\" xmlns=\"http://commonmark.org/xml/1.0\">\n"
1139+ " <paragraph sourcepos=\"1:1-2:25\">\n"
1140+ " <text sourcepos=\"1:1-1:20\" xml:space=\"preserve\">` It is one backtick</text>\n"
1141+ " <softbreak />\n"
1142+ " <text sourcepos=\"2:1-2:25\" xml:space=\"preserve\">`` They are two backticks</text>\n"
1143+ " </paragraph>\n"
1144+ "</document>\n" ,
1145+ "sourcepos are as expected" );
1146+ free (xml );
1147+ cmark_node_free (doc );
1148+ }
11291149}
11301150
11311151static void ref_source_pos (test_batch_runner * runner ) {
Original file line number Diff line number Diff line change @@ -373,13 +373,14 @@ static void S_normalize_code(cmark_strbuf *s) {
373373// Parse backtick code section or raw backticks, return an inline.
374374// Assumes that the subject has a backtick at the current position.
375375static cmark_node * handle_backticks (subject * subj , int options ) {
376+ bufsize_t initpos = subj -> pos ;
376377 cmark_chunk openticks = take_while (subj , isbacktick );
377378 bufsize_t startpos = subj -> pos ;
378379 bufsize_t endpos = scan_to_closing_backticks (subj , openticks .len );
379380
380381 if (endpos == 0 ) { // not found
381382 subj -> pos = startpos ; // rewind
382- return make_str (subj , subj -> pos , subj -> pos , openticks );
383+ return make_str (subj , initpos , initpos + openticks . len - 1 , openticks );
383384 } else {
384385 cmark_strbuf buf = CMARK_BUF_INIT (subj -> mem );
385386
You can’t perform that action at this time.
0 commit comments