Skip to content

Commit f97a08c

Browse files
properly set image/link sourcepos when spanning multiple lines
1 parent 3489555 commit f97a08c

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

api_test/main.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,13 +1005,18 @@ static void source_pos(test_batch_runner *runner) {
10051005
">\n"
10061006
"> 2. Yes, okay.\n"
10071007
"> ![ok](hi \"yes\")\n"
1008-
"<!-- HTML Comment -->";
1008+
"<!-- HTML Comment -->\n"
1009+
"\n"
1010+
"what happens if we spread a link [across multiple\n"
1011+
"lines][anchor]\n"
1012+
"\n"
1013+
"[anchor]: http://example.com\n";
10091014

10101015
cmark_node *doc = cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
10111016
char *xml = cmark_render_xml(doc, CMARK_OPT_DEFAULT | CMARK_OPT_SOURCEPOS);
10121017
STR_EQ(runner, xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
10131018
"<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
1014-
"<document sourcepos=\"1:1-11:21\" xmlns=\"http://commonmark.org/xml/1.0\">\n"
1019+
"<document sourcepos=\"1:1-16:28\" xmlns=\"http://commonmark.org/xml/1.0\">\n"
10151020
" <heading sourcepos=\"1:1-1:13\" level=\"1\">\n"
10161021
" <text sourcepos=\"1:3-1:5\" xml:space=\"preserve\">Hi </text>\n"
10171022
" <emph sourcepos=\"1:6-1:12\">\n"
@@ -1055,6 +1060,14 @@ static void source_pos(test_batch_runner *runner) {
10551060
" </block_quote>\n"
10561061
" <html_block sourcepos=\"11:1-11:21\" xml:space=\"preserve\">&lt;!-- HTML Comment --&gt;\n"
10571062
"</html_block>\n"
1063+
" <paragraph sourcepos=\"13:1-14:14\">\n"
1064+
" <text sourcepos=\"13:1-13:33\" xml:space=\"preserve\">what happens if we spread a link </text>\n"
1065+
" <link sourcepos=\"13:34-14:14\" destination=\"http://example.com\" title=\"\">\n"
1066+
" <text sourcepos=\"13:35-13:49\" xml:space=\"preserve\">across multiple</text>\n"
1067+
" <softbreak />\n"
1068+
" <text sourcepos=\"14:1-14:5\" xml:space=\"preserve\">lines</text>\n"
1069+
" </link>\n"
1070+
" </paragraph>\n"
10581071
"</document>\n",
10591072
"sourcepos are as expected");
10601073
free(xml);

src/inlines.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,8 +1258,9 @@ static cmark_node *handle_close_bracket(cmark_parser *parser, subject *subj) {
12581258
inl = make_simple(subj->mem, is_image ? CMARK_NODE_IMAGE : CMARK_NODE_LINK);
12591259
inl->as.link.url = url;
12601260
inl->as.link.title = title;
1261-
inl->start_line = inl->end_line = subj->line;
1261+
inl->start_line = opener->inl_text->start_line;
12621262
inl->start_column = opener->inl_text->start_column;
1263+
inl->end_line = subj->line;
12631264
inl->end_column = subj->pos + subj->column_offset + subj->block_offset;
12641265
cmark_node_insert_before(opener->inl_text, inl);
12651266
// Add link text:

0 commit comments

Comments
 (0)