Skip to content

Commit

Permalink
Fix inline source positions
Browse files Browse the repository at this point in the history
Account for partially removed delimiter chars.

Fixes #551.
  • Loading branch information
nwellnhof authored and jgm committed Aug 18, 2024
1 parent bb3678d commit 2734f21
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 6 additions & 6 deletions api_test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ static void sub_document(test_batch_runner *runner) {

static void source_pos(test_batch_runner *runner) {
static const char markdown[] =
"# Hi *there*.\n"
"# Hi **there*.\n"
"\n"
"Hello &ldquo; <http://www.google.com>\n"
"there `hi` -- [okay](www.google.com (ok)).\n"
Expand All @@ -998,12 +998,12 @@ static void source_pos(test_batch_runner *runner) {
STR_EQ(runner, xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
"<document sourcepos=\"1:1-10:20\" xmlns=\"http://commonmark.org/xml/1.0\">\n"
" <heading sourcepos=\"1:1-1:13\" level=\"1\">\n"
" <text sourcepos=\"1:3-1:5\" xml:space=\"preserve\">Hi </text>\n"
" <emph sourcepos=\"1:6-1:12\">\n"
" <text sourcepos=\"1:7-1:11\" xml:space=\"preserve\">there</text>\n"
" <heading sourcepos=\"1:1-1:14\" level=\"1\">\n"
" <text sourcepos=\"1:3-1:6\" xml:space=\"preserve\">Hi *</text>\n"
" <emph sourcepos=\"1:7-1:13\">\n"
" <text sourcepos=\"1:8-1:12\" xml:space=\"preserve\">there</text>\n"
" </emph>\n"
" <text sourcepos=\"1:13-1:13\" xml:space=\"preserve\">.</text>\n"
" <text sourcepos=\"1:14-1:14\" xml:space=\"preserve\">.</text>\n"
" </heading>\n"
" <paragraph sourcepos=\"3:1-4:42\">\n"
" <text sourcepos=\"3:1-3:14\" xml:space=\"preserve\">Hello “ </text>\n"
Expand Down
6 changes: 4 additions & 2 deletions src/inlines.c
Original file line number Diff line number Diff line change
Expand Up @@ -770,8 +770,10 @@ static delimiter *S_insert_emph(subject *subj, delimiter *opener,
closer_num_chars -= use_delims;
opener_inl->len = opener_num_chars;
opener_inl->data[opener_num_chars] = 0;
opener_inl->end_column -= use_delims;
closer_inl->len = closer_num_chars;
closer_inl->data[closer_num_chars] = 0;
closer_inl->start_column += use_delims;

// free delimiters between opener and closer
delim = closer->previous;
Expand Down Expand Up @@ -809,8 +811,8 @@ static delimiter *S_insert_emph(subject *subj, delimiter *opener,

emph->start_line = opener_inl->start_line;
emph->end_line = closer_inl->end_line;
emph->start_column = opener_inl->start_column;
emph->end_column = closer_inl->end_column;
emph->start_column = opener_inl->start_column + opener_inl->len;
emph->end_column = closer_inl->end_column - closer_inl->len;

// if opener has 0 characters, remove it and its associated inline
if (opener_num_chars == 0) {
Expand Down

0 comments on commit 2734f21

Please sign in to comment.