diff --git a/api_test/main.c b/api_test/main.c old mode 100644 new mode 100755 index 83afbff0c..a8cfaa813 --- a/api_test/main.c +++ b/api_test/main.c @@ -889,68 +889,314 @@ static void test_feed_across_line_ending(test_batch_runner *runner) { } static void source_pos(test_batch_runner *runner) { - static const char markdown[] = - "# Hi *there*.\n" + { + static const char markdown[] = + "# Hi *there*.\n" + "\n" + "Hello “ \n" + "there `hi` -- [okay](www.google.com (ok)).\n" + "\n" + "> 1. Okay.\n" + "> Sure.\n" + ">\n" + "> 2. Yes, okay.\n" + "> ![ok](hi \"yes\")\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, "\n" + "\n" + "\n" + " \n" + " Hi \n" + " \n" + " there\n" + " \n" + " .\n" + " \n" + " \n" + " Hello \xe2\x80\x9c \n" + " \n" + " http://www.google.com\n" + " \n" + " \n" + " there \n" + " hi\n" + " -- \n" + " \n" + " okay\n" + " \n" + " .\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " Okay.\n" + " \n" + " Sure.\n" + " \n" + " \n" + " \n" + " \n" + " Yes, okay.\n" + " \n" + " \n" + " ok\n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n", + "sourcepos are as expected"); + free(xml); + cmark_node_free(doc); + } + { + static const char markdown[] = + "1. **Start condition:** line begins with the string ``, or the end of the line.\\\n" + " **End condition:** line contains an end tag\n" + " ``, ``, or `` (case-insensitive; it\n" + " need not match the start tag).\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, "\n" + "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " Start condition:\n" + " \n" + " line begins with the string \n" + " <script\n" + " ,\n" + " \n" + " <pre\n" + " , or \n" + " <style\n" + " (case-insensitive), followed by whitespace,\n" + " \n" + " the string \n" + " >\n" + " , or the end of the line.\n" + " \n" + " \n" + " End condition:\n" + " \n" + " line contains an end tag\n" + " \n" + " </script>\n" + " , \n" + " </pre>\n" + " , or \n" + " </style>\n" + " (case-insensitive; it\n" + " \n" + " need not match the start tag).\n" + " \n" + " \n" + " \n" + "\n", + "list (with EOL backslash) sourcepos are as expected"); + free(xml); + cmark_node_free(doc); + } + { + static const char markdown[] = + "> The overriding design goal for Markdown's formatting syntax is\n" + " > to make it as **readable as possible**. The idea is that a\n" + "> Markdown-formatted document should be publishable as-is, as\n" + " > plain text, without *looking like* it's been marked up with tags\n" + " > or formatting instructions.\n" + "> ()\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, "\n" + "\n" + "\n" + " \n" + " \n" + " The overriding design goal for Markdown's formatting syntax is\n" + " \n" + " to make it as \n" + " \n" + " readable as possible\n" + " \n" + " . The idea is that a\n" + " \n" + " Markdown-formatted document should be publishable as-is, as\n" + " \n" + " plain text, without \n" + " \n" + " looking like\n" + " \n" + " it's been marked up with tags\n" + " \n" + " or formatting instructions.\n" + " \n" + " (\n" + " \n" + " http://daringfireball.net/projects/markdown/\n" + " \n" + " )\n" + " \n" + " \n" + "\n", + "inconsistently indented blockquote sourcepos are as expected"); + free(xml); + cmark_node_free(doc); + } + { + static const char markdown[] = "\n" - "Hello “ \n" - "there `hi` -- [okay](www.google.com (ok)).\n" "\n" - "> 1. Okay.\n" - "> Sure.\n" - ">\n" - "> 2. Yes, okay.\n" - "> ![ok](hi \"yes\")\n"; + "
```javascript\n"
+    "var s = \"JavaScript syntax highlighting\";\n"
+    "alert(s);\n"
+    "```\n"
+    " \n"
+    "```python\n"
+    "s = \"Python syntax highlighting\"\n"
+    "print s\n"
+    "```\n"
+    " \n"
+    "```\n"
+    "No language indicated, so no syntax highlighting. \n"
+    "But let's throw in a <b>tag</b>.\n"
+    "```\n"
+    "
\n" + "\n" + "\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, "\n" - "\n" - "\n" - " \n" - " Hi \n" - " \n" - " there\n" - " \n" - " .\n" - " \n" - " \n" - " Hello “ \n" - " \n" - " http://www.google.com\n" - " \n" - " \n" - " there \n" - " hi\n" - " -- \n" - " \n" - " okay\n" - " \n" - " .\n" - " \n" - " \n" - " \n" - " \n" - " \n" - " Okay.\n" - " \n" - " Sure.\n" - " \n" - " \n" - " \n" - " \n" - " Yes, okay.\n" - " \n" - " \n" - " ok\n" - " \n" - " \n" - " \n" - " \n" - " \n" - "\n", - "sourcepos are as expected"); - free(xml); - cmark_node_free(doc); + 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, "\n" + "\n" + "\n" + " <pre lang="no-highlight"><code>```javascript\n" + "var s = "JavaScript syntax highlighting";\n" + "alert(s);\n" + "```\n" + " \n" + "```python\n" + "s = "Python syntax highlighting"\n" + "print s\n" + "```\n" + " \n" + "```\n" + "No language indicated, so no syntax highlighting. \n" + "But let's throw in a &lt;b&gt;tag&lt;/b&gt;.\n" + "```\n" + "</code></pre>\n" + "\n" + "\n", + "html block sourcepos are as expected"); + free(xml); + cmark_node_free(doc); + } + { + static const char markdown[] = + "---\n" + "\n" + "\n" + "\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, "\n" + "\n" + "\n" + " \n" + "\n", + "thematic break sourcepos are as expected"); + free(xml); + cmark_node_free(doc); + } + { + static const char markdown[] = + "1. List 1, Item A.\n" + " 1. List 2, Item A.\n" + " Second line.\n" + "\n" + "2. List 1, Item B.\n" + " Second line.\n" + "\n" + "\n" + "\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, "\n" + "\n" + "\n" + " \n" + " \n" + " \n" + " List 1, Item A.\n" + " \n" + " \n" + " \n" + " \n" + " List 2, Item A.\n" + " \n" + " Second line.\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " List 1, Item B.\n" + " \n" + " Second line.\n" + " \n" + " \n" + " \n" + "\n", + "list sourcepos are as expected"); + free(xml); + cmark_node_free(doc); + } + { + static const char markdown[] = + "* List 1, item A.\n" + "\n" + "