summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-11-13 09:47:50 -0800
committerGitHub <noreply@github.com>2018-11-13 09:47:50 -0800
commitb1556b3407a4349b9a1f4f58d8677eda0ead09c1 (patch)
tree2ee14a588403d9c9ed1888d6270a6f6ca30668ad
parent3a440af3ba874289ef33ac6bbf2da90040c123d6 (diff)
parentd479c28a631731543e6276f807155388aa71acde (diff)
Merge pull request #275 from github/inline-sourcepos-off
correct sourcepos for emphasis inlines
-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) {