File tree 2 files changed +22
-1
lines changed
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) {
1126
1126
free (xml );
1127
1127
cmark_node_free (doc );
1128
1128
}
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
+ }
1129
1149
}
1130
1150
1131
1151
static 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) {
373
373
// Parse backtick code section or raw backticks, return an inline.
374
374
// Assumes that the subject has a backtick at the current position.
375
375
static cmark_node * handle_backticks (subject * subj , int options ) {
376
+ bufsize_t initpos = subj -> pos ;
376
377
cmark_chunk openticks = take_while (subj , isbacktick );
377
378
bufsize_t startpos = subj -> pos ;
378
379
bufsize_t endpos = scan_to_closing_backticks (subj , openticks .len );
379
380
380
381
if (endpos == 0 ) { // not found
381
382
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 );
383
384
} else {
384
385
cmark_strbuf buf = CMARK_BUF_INIT (subj -> mem );
385
386
You can’t perform that action at this time.
0 commit comments