Skip to content

Commit 1429a7f

Browse files
apply block offsets for autolink source position info
1 parent c773440 commit 1429a7f

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

api_test/main.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,20 +1062,27 @@ static void source_pos_inlines(test_batch_runner *runner) {
10621062
{
10631063
static const char markdown[] =
10641064
"*first*\n"
1065-
"second\n";
1065+
"second\n"
1066+
"\n"
1067+
" <http://example.com>";
10661068

10671069
cmark_node *doc = cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
10681070
char *xml = cmark_render_xml(doc, CMARK_OPT_DEFAULT | CMARK_OPT_SOURCEPOS);
10691071
STR_EQ(runner, xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
10701072
"<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
1071-
"<document sourcepos=\"1:1-2:6\" xmlns=\"http://commonmark.org/xml/1.0\">\n"
1073+
"<document sourcepos=\"1:1-4:23\" xmlns=\"http://commonmark.org/xml/1.0\">\n"
10721074
" <paragraph sourcepos=\"1:1-2:6\">\n"
10731075
" <emph sourcepos=\"1:1-1:7\">\n"
10741076
" <text sourcepos=\"1:2-1:6\" xml:space=\"preserve\">first</text>\n"
10751077
" </emph>\n"
10761078
" <softbreak />\n"
10771079
" <text sourcepos=\"2:1-2:6\" xml:space=\"preserve\">second</text>\n"
10781080
" </paragraph>\n"
1081+
" <paragraph sourcepos=\"4:4-4:23\">\n"
1082+
" <link sourcepos=\"4:4-4:23\" destination=\"http://example.com\" title=\"\">\n"
1083+
" <text sourcepos=\"4:5-4:22\" xml:space=\"preserve\">http://example.com</text>\n"
1084+
" </link>\n"
1085+
" </paragraph>\n"
10791086
"</document>\n",
10801087
"sourcepos are as expected");
10811088
free(xml);

src/inlines.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ static CMARK_INLINE cmark_node *make_autolink(subject *subj,
150150
link->as.link.url = cmark_clean_autolink(subj->mem, &url, is_email);
151151
link->as.link.title = cmark_chunk_literal("");
152152
link->start_line = link->end_line = subj->line;
153-
link->start_column = start_column + 1;
154-
link->end_column = end_column + 1;
153+
link->start_column = start_column + 1 + subj->column_offset + subj->block_offset;
154+
link->end_column = end_column + 1 + subj->column_offset + subj->block_offset;
155155
cmark_node_append_child(link, make_str_with_entities(subj, start_column + 1, end_column - 1, &url));
156156
return link;
157157
}

0 commit comments

Comments
 (0)