summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api_test/main.c48
-rw-r--r--src/inlines.c7
2 files changed, 52 insertions, 3 deletions
diff --git a/api_test/main.c b/api_test/main.c
index a843530..1f1f77f 100644
--- a/api_test/main.c
+++ b/api_test/main.c
@@ -952,6 +952,53 @@ static void source_pos(test_batch_runner *runner) {
cmark_node_free(doc);
}
+static void source_pos_inlines(test_batch_runner *runner) {
+ {
+ static const char markdown[] =
+ "*first*\n"
+ "second\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:6\" xmlns=\"http://commonmark.org/xml/1.0\">\n"
+ " <paragraph sourcepos=\"1:1-2:6\">\n"
+ " <emph sourcepos=\"1:1-1:7\">\n"
+ " <text sourcepos=\"1:2-1:6\" xml:space=\"preserve\">first</text>\n"
+ " </emph>\n"
+ " <softbreak />\n"
+ " <text sourcepos=\"2:1-2:6\" xml:space=\"preserve\">second</text>\n"
+ " </paragraph>\n"
+ "</document>\n",
+ "sourcepos are as expected");
+ free(xml);
+ cmark_node_free(doc);
+ }
+ {
+ static const char markdown[] =
+ "*first\n"
+ "second*\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:7\" xmlns=\"http://commonmark.org/xml/1.0\">\n"
+ " <paragraph sourcepos=\"1:1-2:7\">\n"
+ " <emph sourcepos=\"1:1-2:7\">\n"
+ " <text sourcepos=\"1:2-1:6\" xml:space=\"preserve\">first</text>\n"
+ " <softbreak />\n"
+ " <text sourcepos=\"2:1-2:6\" xml:space=\"preserve\">second</text>\n"
+ " </emph>\n"
+ " </paragraph>\n"
+ "</document>\n",
+ "sourcepos are as expected");
+ free(xml);
+ cmark_node_free(doc);
+ }
+}
+
static void ref_source_pos(test_batch_runner *runner) {
static const char markdown[] =
"Let's try [reference] links.\n"
@@ -1002,6 +1049,7 @@ int main() {
test_safe(runner);
test_feed_across_line_ending(runner);
source_pos(runner);
+ source_pos_inlines(runner);
ref_source_pos(runner);
test_print_summary(runner);
diff --git a/src/inlines.c b/src/inlines.c
index 171247e..d31173d 100644
--- a/src/inlines.c
+++ b/src/inlines.c
@@ -732,9 +732,10 @@ static delimiter *S_insert_emph(subject *subj, delimiter *opener,
}
cmark_node_insert_after(opener_inl, emph);
- emph->start_line = emph->end_line = subj->line;
- emph->start_column = opener_inl->start_column + subj->column_offset;
- emph->end_column = closer_inl->end_column + subj->column_offset;
+ 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;
// if opener has 0 characters, remove it and its associated inline
if (opener_num_chars == 0) {