@@ -1417,6 +1417,160 @@ static void parser_interrupt(test_batch_runner *runner) {
14171417 cmark_syntax_extension_free (cmark_get_default_mem_allocator (), my_ext );
14181418}
14191419
1420+ static void compare_table_spans_html (test_batch_runner * runner , const char * markdown , bool use_ditto ,
1421+ const char * expected_html , const char * msg ) {
1422+ int options = CMARK_OPT_TABLE_SPANS ;
1423+ if (use_ditto )
1424+ options |= CMARK_OPT_TABLE_ROWSPAN_DITTO ;
1425+ cmark_parser * parser = cmark_parser_new (options );
1426+ cmark_parser_attach_syntax_extension (parser , cmark_find_syntax_extension ("table" ));
1427+
1428+ cmark_parser_feed (parser , markdown , strlen (markdown ));
1429+
1430+ cmark_node * doc = cmark_parser_finish (parser );
1431+ char * html = cmark_render_html (doc , options , NULL );
1432+ STR_EQ (runner , html , expected_html , msg );
1433+
1434+ free (html );
1435+ cmark_node_free (doc );
1436+ cmark_parser_free (parser );
1437+ }
1438+
1439+ static void table_spans (test_batch_runner * runner ) {
1440+ {
1441+ static const char markdown [] =
1442+ "| one | two |\n"
1443+ "| --- | --- |\n"
1444+ "| hello ||\n" ;
1445+ static const char html [] =
1446+ "<table>\n"
1447+ "<thead>\n"
1448+ "<tr>\n"
1449+ "<th>one</th>\n"
1450+ "<th>two</th>\n"
1451+ "</tr>\n"
1452+ "</thead>\n"
1453+ "<tbody>\n"
1454+ "<tr>\n"
1455+ "<td colspan=\"2\">hello</td>\n"
1456+ "</tr>\n"
1457+ "</tbody>\n"
1458+ "</table>\n" ;
1459+ compare_table_spans_html (runner , markdown , false, html ,
1460+ "table colspans should work when enabled" );
1461+ }
1462+ {
1463+ static const char markdown [] =
1464+ "| one | two |\n"
1465+ "| --- | ----- |\n"
1466+ "| big | small |\n"
1467+ "| ^ | small |\n" ;
1468+ static const char html [] =
1469+ "<table>\n"
1470+ "<thead>\n"
1471+ "<tr>\n"
1472+ "<th>one</th>\n"
1473+ "<th>two</th>\n"
1474+ "</tr>\n"
1475+ "</thead>\n"
1476+ "<tbody>\n"
1477+ "<tr>\n"
1478+ "<td rowspan=\"2\">big</td>\n"
1479+ "<td>small</td>\n"
1480+ "</tr>\n"
1481+ "<tr>\n"
1482+ "<td>small</td>\n"
1483+ "</tr>\n"
1484+ "</tbody>\n"
1485+ "</table>\n" ;
1486+ compare_table_spans_html (runner , markdown , false, html ,
1487+ "table rowspans should work when enabled" );
1488+ }
1489+ {
1490+ static const char markdown [] =
1491+ "| one | two |\n"
1492+ "| --- | ----- |\n"
1493+ "| big | small |\n"
1494+ "| \" | small |\n" ;
1495+ static const char html [] =
1496+ "<table>\n"
1497+ "<thead>\n"
1498+ "<tr>\n"
1499+ "<th>one</th>\n"
1500+ "<th>two</th>\n"
1501+ "</tr>\n"
1502+ "</thead>\n"
1503+ "<tbody>\n"
1504+ "<tr>\n"
1505+ "<td rowspan=\"2\">big</td>\n"
1506+ "<td>small</td>\n"
1507+ "</tr>\n"
1508+ "<tr>\n"
1509+ "<td>small</td>\n"
1510+ "</tr>\n"
1511+ "</tbody>\n"
1512+ "</table>\n" ;
1513+ compare_table_spans_html (runner , markdown , true, html ,
1514+ "rowspan ditto marks should work when enabled" );
1515+ }
1516+ {
1517+ static const char markdown [] =
1518+ "| one | two | three |\n"
1519+ "| --- | --- | ----- |\n"
1520+ "| big || small |\n"
1521+ "| ^ || small |\n" ;
1522+ static const char html [] =
1523+ "<table>\n"
1524+ "<thead>\n"
1525+ "<tr>\n"
1526+ "<th>one</th>\n"
1527+ "<th>two</th>\n"
1528+ "<th>three</th>\n"
1529+ "</tr>\n"
1530+ "</thead>\n"
1531+ "<tbody>\n"
1532+ "<tr>\n"
1533+ "<td colspan=\"2\" rowspan=\"2\">big</td>\n"
1534+ "<td>small</td>\n"
1535+ "</tr>\n"
1536+ "<tr>\n"
1537+ "<td>small</td>\n"
1538+ "</tr>\n"
1539+ "</tbody>\n"
1540+ "</table>\n" ;
1541+ compare_table_spans_html (runner , markdown , false, html ,
1542+ "colspan and rowspan should combine sensibly" );
1543+ }
1544+ {
1545+ static const char markdown [] =
1546+ "| one | two | three |\n"
1547+ "| --- | --- | ----- |\n"
1548+ "| big || small |\n"
1549+ "| \" || small |\n" ;
1550+ static const char html [] =
1551+ "<table>\n"
1552+ "<thead>\n"
1553+ "<tr>\n"
1554+ "<th>one</th>\n"
1555+ "<th>two</th>\n"
1556+ "<th>three</th>\n"
1557+ "</tr>\n"
1558+ "</thead>\n"
1559+ "<tbody>\n"
1560+ "<tr>\n"
1561+ "<td colspan=\"2\" rowspan=\"2\">big</td>\n"
1562+ "<td>small</td>\n"
1563+ "</tr>\n"
1564+ "<tr>\n"
1565+ "<td>small</td>\n"
1566+ "</tr>\n"
1567+ "</tbody>\n"
1568+ "</table>\n" ;
1569+ compare_table_spans_html (runner , markdown , true, html ,
1570+ "colspan and rowspan should combine when ditto marks are enabled" );
1571+ }
1572+ }
1573+
14201574int main () {
14211575 int retval ;
14221576 test_batch_runner * runner = test_batch_runner_new ();
@@ -1452,6 +1606,7 @@ int main() {
14521606 verify_custom_attributes_node (runner );
14531607 verify_custom_attributes_node_with_footnote (runner );
14541608 parser_interrupt (runner );
1609+ table_spans (runner );
14551610
14561611 test_print_summary (runner );
14571612 retval = test_ok (runner ) ? 0 : 1 ;
0 commit comments