Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix list tightness #479

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 169 additions & 1 deletion api_test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ static void source_pos(test_batch_runner *runner) {
" </paragraph>\n"
" <block_quote sourcepos=\"6:1-10:20\">\n"
" <list sourcepos=\"6:3-10:20\" type=\"ordered\" start=\"1\" delim=\"period\" tight=\"false\">\n"
" <item sourcepos=\"6:3-8:1\">\n"
" <item sourcepos=\"6:3-7:10\">\n"
" <paragraph sourcepos=\"6:6-7:10\">\n"
" <text sourcepos=\"6:6-6:10\" xml:space=\"preserve\">Okay.</text>\n"
" <softbreak />\n"
Expand Down Expand Up @@ -1067,6 +1067,173 @@ static void ref_source_pos(test_batch_runner *runner) {
cmark_node_free(doc);
}

static void source_pos_pathological(test_batch_runner *runner) {
static const char markdown[] =
"> ```\n"
"> This code block is closed implicitly by the end of the block quote.\n"
"> \n"
"\n"
"> <pre>\n"
"> This HTML block is closed implicitly by the end of the block quote.\n"
"> \n"
"\n"
"- ```\n"
" This code block is closed implicitly by the end of the list item.\n"
" \n"
"- <pre>\n"
" This code block is closed implicitly by the end of the list item.\n"
" \n"
"- \n"
"\n"
" \n"
" Indented code block...\n"
" \n"
" doesn't contain trailing blank lines,\n"
" but it does contain trailing spaces at end of the line \n"
" \n"
"\n"
"```\n"
"Explicitly closed code block\n"
"```\n"
"\n"
"<pre>\n"
"Explicitly closed HTML block\n"
"</pre>\n"
"\n"
"\n"
"<!-- multiple HTML blocks --> <!-- in a line --> with trailing text.\n"
"\n"
"\n"
" Setext heading across\n"
" multiple lines\n"
" =====================\n"
"\n"
"\n"
"---\n"
"\n"
" ### ATX heading\n"
"\n"
"\n"
"[\n"
"foo\n"
"]:\n"
"/url\n"
"'\n"
"Link reference definitions followed by a paragraph\n"
"'\n"
"bar\n"
"\n"
"> [foo]: /url 'Block containing only link reference definitions'\n"
"\n"
"\n"
">\n"
"> \n"
"> \n"
"\n"
"\n"
" > Indented code block\n"
"> with offseted first line.\n"
"\n"
"> Indented code block\n"
" > with offseted second line.\n"
"\n"
"\n"
"- Empty list items\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, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
"<document sourcepos=\"1:1-73:5\" xmlns=\"http://commonmark.org/xml/1.0\">\n"
" <block_quote sourcepos=\"1:1-3:4\">\n"
" <code_block sourcepos=\"1:3-3:4\" xml:space=\"preserve\">This code block is closed implicitly by the end of the block quote.\n"
" \n"
"</code_block>\n"
" </block_quote>\n"
" <block_quote sourcepos=\"5:1-7:4\">\n"
" <html_block sourcepos=\"5:3-7:4\" xml:space=\"preserve\">&lt;pre&gt;\n"
"This HTML block is closed implicitly by the end of the block quote.\n"
" \n"
"</html_block>\n"
" </block_quote>\n"
" <list sourcepos=\"9:1-15:2\" type=\"bullet\" tight=\"true\">\n"
" <item sourcepos=\"9:1-11:3\">\n"
" <code_block sourcepos=\"9:3-11:3\" xml:space=\"preserve\">This code block is closed implicitly by the end of the list item.\n"
" \n"
"</code_block>\n"
" </item>\n"
" <item sourcepos=\"12:1-14:3\">\n"
" <html_block sourcepos=\"12:3-14:3\" xml:space=\"preserve\">&lt;pre&gt;\n"
"This code block is closed implicitly by the end of the list item.\n"
" \n"
"</html_block>\n"
" </item>\n"
" <item sourcepos=\"15:1-15:2\" />\n"
" </list>\n"
" <code_block sourcepos=\"18:5-21:61\" xml:space=\"preserve\">Indented code block...\n"
"\n"
"doesn't contain trailing blank lines,\n"
"but it does contain trailing spaces at end of the line \n"
"</code_block>\n"
" <code_block sourcepos=\"24:1-26:3\" xml:space=\"preserve\">Explicitly closed code block\n"
"</code_block>\n"
" <html_block sourcepos=\"28:1-30:6\" xml:space=\"preserve\">&lt;pre&gt;\n"
"Explicitly closed HTML block\n"
"&lt;/pre&gt;\n"
"</html_block>\n"
" <html_block sourcepos=\"33:1-33:68\" xml:space=\"preserve\">&lt;!-- multiple HTML blocks --&gt; &lt;!-- in a line --&gt; with trailing text.\n"
"</html_block>\n"
" <heading sourcepos=\"36:3-38:23\" level=\"1\">\n"
" <text sourcepos=\"36:3-36:23\" xml:space=\"preserve\">Setext heading across</text>\n"
" <softbreak />\n"
" <text sourcepos=\"37:3-37:16\" xml:space=\"preserve\">multiple lines</text>\n"
" </heading>\n"
" <thematic_break sourcepos=\"41:1-41:3\" />\n"
" <heading sourcepos=\"43:2-43:16\" level=\"3\">\n"
" <text sourcepos=\"43:6-43:16\" xml:space=\"preserve\">ATX heading</text>\n"
" </heading>\n"
" <paragraph sourcepos=\"53:0-53:3\">\n"
" <text sourcepos=\"53:0-53:2\" xml:space=\"preserve\">bar</text>\n"
" </paragraph>\n"
" <block_quote sourcepos=\"55:1-55:66\" />\n"
" <block_quote sourcepos=\"58:1-60:3\" />\n"
" <block_quote sourcepos=\"63:4-64:31\">\n"
" <code_block sourcepos=\"63:10-64:31\" xml:space=\"preserve\">Indented code block\n"
"with offseted first line.\n"
"</code_block>\n"
" </block_quote>\n"
" <block_quote sourcepos=\"66:1-67:35\">\n"
" <code_block sourcepos=\"66:7-67:35\" xml:space=\"preserve\">Indented code block\n"
"with offseted second line.\n"
"</code_block>\n"
" </block_quote>\n"
" <list sourcepos=\"70:1-73:5\" type=\"bullet\" tight=\"true\">\n"
" <item sourcepos=\"70:1-70:18\">\n"
" <paragraph sourcepos=\"70:3-70:18\">\n"
" <text sourcepos=\"70:3-70:18\" xml:space=\"preserve\">Empty list items</text>\n"
" </paragraph>\n"
" </item>\n"
" <item sourcepos=\"71:1-71:4\" />\n"
" <item sourcepos=\"72:1-73:5\">\n"
" <list sourcepos=\"72:3-73:5\" type=\"bullet\" tight=\"true\">\n"
" <item sourcepos=\"72:3-72:3\" />\n"
" <item sourcepos=\"73:3-73:5\">\n"
" <list sourcepos=\"73:5-73:5\" type=\"bullet\" tight=\"true\">\n"
" <item sourcepos=\"73:5-73:5\" />\n"
" </list>\n"
" </item>\n"
" </list>\n"
" </item>\n"
" </list>\n"
"</document>\n",
"sourcepos are as expected");
free(xml);
cmark_node_free(doc);
}

int main(void) {
int retval;
test_batch_runner *runner = test_batch_runner_new();
Expand Down Expand Up @@ -1096,6 +1263,7 @@ int main(void) {
source_pos(runner);
source_pos_inlines(runner);
ref_source_pos(runner);
source_pos_pathological(runner);

test_print_summary(runner);
retval = test_ok(runner) ? 0 : 1;
Expand Down
Loading