Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions api_test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,26 @@ static void source_pos_inlines(test_batch_runner *runner) {
free(xml);
cmark_node_free(doc);
}
{
static const char markdown[] =
"` It is one backtick\n"
"`` They are two backticks\n";

cmark_node *doc = cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
char *xml = cmark_render_xml(doc, CMARK_OPT_DEFAULT | CMARK_OPT_SOURCEPOS);
STR_EQ(runner, xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
"<document sourcepos=\"1:1-2:25\" xmlns=\"http://commonmark.org/xml/1.0\">\n"
" <paragraph sourcepos=\"1:1-2:25\">\n"
" <text sourcepos=\"1:1-1:20\" xml:space=\"preserve\">` It is one backtick</text>\n"
" <softbreak />\n"
" <text sourcepos=\"2:1-2:25\" xml:space=\"preserve\">`` They are two backticks</text>\n"
" </paragraph>\n"
"</document>\n",
"sourcepos are as expected");
free(xml);
cmark_node_free(doc);
}
}

static void ref_source_pos(test_batch_runner *runner) {
Expand Down
3 changes: 2 additions & 1 deletion src/inlines.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,14 @@ static void S_normalize_code(cmark_strbuf *s) {
// Parse backtick code section or raw backticks, return an inline.
// Assumes that the subject has a backtick at the current position.
static cmark_node *handle_backticks(subject *subj, int options) {
bufsize_t initpos = subj->pos;
cmark_chunk openticks = take_while(subj, isbacktick);
bufsize_t startpos = subj->pos;
bufsize_t endpos = scan_to_closing_backticks(subj, openticks.len);

if (endpos == 0) { // not found
subj->pos = startpos; // rewind
return make_str(subj, subj->pos, subj->pos, openticks);
return make_str(subj, initpos, initpos + openticks.len - 1, openticks);
} else {
cmark_strbuf buf = CMARK_BUF_INIT(subj->mem);

Expand Down