diff --git a/api_test/main.c b/api_test/main.c old mode 100644 new mode 100755 index 62006eaa9..b4502a05f --- a/api_test/main.c +++ b/api_test/main.c @@ -6,6 +6,7 @@ #include "cmark-gfm.h" #include "node.h" #include "../extensions/cmark-gfm-core-extensions.h" +#include "registry.h" #include "harness.h" #include "cplusplus.h" @@ -994,6 +995,7 @@ static void test_pathological_regressions(test_batch_runner *runner) { } static void source_pos(test_batch_runner *runner) { + { static const char markdown[] = "# Hi *there*.\n" "\n" @@ -1034,7 +1036,7 @@ static void source_pos(test_batch_runner *runner) { " \n" " \n" " \n" - " \n" + " \n" " \n" " Okay.\n" " \n" @@ -1057,24 +1059,278 @@ static void source_pos(test_batch_runner *runner) { 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"; -static void source_pos_inlines(test_batch_runner *runner) { + 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[] = - "*first*\n" - "second\n"; + "> 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" + "\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" + " <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" + "