From: Fletcher T. Penney Date: Wed, 8 Feb 2017 21:35:47 +0000 (-0500) Subject: ADDED: Add support for table captions X-Git-Tag: 0.1.3a^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=583bdbe5ee4e058bd11eb2632231599f453a340a;p=multimarkdown ADDED: Add support for table captions --- diff --git a/README.md b/README.md index 701f0e2..40a6a35 100644 --- a/README.md +++ b/README.md @@ -407,6 +407,9 @@ For example, `Reference Footnotes.text` is parsed differently in compatibility mode than MMD-5. This started as a side-effect of the parsing algorithm, but I actually think it makes sense. This may or may not change in the future. +6. Table captions in MMD-6 must come immediately *after* the table, not +before it. + ## Where Does MultiMarkdown 6 Stand? ## @@ -454,7 +457,6 @@ Things yet to be completed: * Abbreviations * Glossaries * File Transclusion -* Table Captions ### Accuracy ### diff --git a/src/html.c b/src/html.c index e2e1659..dd11e49 100644 --- a/src/html.c +++ b/src/html.c @@ -526,6 +526,29 @@ void mmd_export_token_html(DString * out, const char * source, token * t, size_t case BLOCK_TABLE: pad(out, 2, scratch); print("\n"); + + // Are we followed by a caption? + if (table_has_caption(t)) { + temp_token = t->next->child; + + if (temp_token->next && + temp_token->next->type == PAIR_BRACKET) { + temp_token = temp_token->next; + } + + temp_char = label_from_token(source, temp_token); + printf("\n"); + temp_short = 1; + } else { + temp_short = 0; + } + scratch->padded = 2; read_table_column_alignments(source, t, scratch); @@ -563,6 +586,9 @@ void mmd_export_token_html(DString * out, const char * source, token * t, size_t pad(out, 1, scratch); print("
", temp_char); + free(temp_char); + + t->next->child->child->type = TEXT_EMPTY; + t->next->child->child->mate->type = TEXT_EMPTY; + mmd_export_token_tree_html(out, source, t->next->child->child, offset, scratch); + print("
"); scratch->padded = 0; + + scratch->skip_token = temp_short; + break; case BLOCK_TABLE_HEADER: pad(out, 2, scratch); diff --git a/src/writer.c b/src/writer.c index 5a0ebe3..a66bd88 100644 --- a/src/writer.c +++ b/src/writer.c @@ -1526,3 +1526,30 @@ void strip_leading_whitespace(token * chain, const char * source) { chain = chain->next; } } + + +bool table_has_caption(token * t) { + + if (t->next && t->next->type == BLOCK_PARA) { + t = t->next->child; + + if (t->type == PAIR_BRACKET) { + t = t->next; + + if (t && t->next && + t->next->type == PAIR_BRACKET) + t = t->next; + + if (t && t->next && + ((t->next->type == TEXT_NL) || + (t->next->type == TEXT_LINEBREAK))) + t = t->next; + + if (t->next == NULL) + return true; + } + } + + return false; +} + diff --git a/src/writer.h b/src/writer.h index bc35c2c..b47babe 100644 --- a/src/writer.h +++ b/src/writer.h @@ -203,5 +203,7 @@ void read_table_column_alignments(const char * source, token * table, scratch_pa void strip_leading_whitespace(token * chain, const char * source); +bool table_has_caption(token * table); + #endif diff --git a/templates/README.md.in b/templates/README.md.in index 345cd8b..d4365ee 100644 --- a/templates/README.md.in +++ b/templates/README.md.in @@ -407,6 +407,9 @@ For example, `Reference Footnotes.text` is parsed differently in compatibility mode than MMD-5. This started as a side-effect of the parsing algorithm, but I actually think it makes sense. This may or may not change in the future. +6. Table captions in MMD-6 must come immediately *after* the table, not +before it. + ## Where Does MultiMarkdown 6 Stand? ## @@ -454,7 +457,6 @@ Things yet to be completed: * Abbreviations * Glossaries * File Transclusion -* Table Captions ### Accuracy ### diff --git a/tests/MMD6Tests/Tables.html b/tests/MMD6Tests/Tables.html index 32a2936..15d4fd8 100644 --- a/tests/MMD6Tests/Tables.html +++ b/tests/MMD6Tests/Tables.html @@ -131,3 +131,52 @@ + + + ++++ + + + + + + + + + + + + + + +
foo
foo bar
foo bar
+ + + ++++ + + + + + + + + + + + + + + +
foo
foo bar
foo bar
+ +

[foo][bar] +| foo | bar | +| — | — | +| foo | bar |

diff --git a/tests/MMD6Tests/Tables.htmlc b/tests/MMD6Tests/Tables.htmlc index 8a80926..80ae6ae 100644 --- a/tests/MMD6Tests/Tables.htmlc +++ b/tests/MMD6Tests/Tables.htmlc @@ -32,3 +32,18 @@ | :---- | ----: | foo | bar | | foo bar ||

+ +

| foo | bar | +| --- | --- | +| foo | bar | +[foo][bar]

+ +

| foo | bar | +| --- | --- | +| foo | bar | +[foo]

+ +

[foo][bar] +| foo | bar | +| --- | --- | +| foo | bar |

diff --git a/tests/MMD6Tests/Tables.text b/tests/MMD6Tests/Tables.text index 696e78f..4b5dcf2 100644 --- a/tests/MMD6Tests/Tables.text +++ b/tests/MMD6Tests/Tables.text @@ -34,4 +34,20 @@ | foo6 | bar6 | | :---- | ----: | *foo* | *bar* | -| **foo bar** || \ No newline at end of file +| **foo bar** || + + +| foo | bar | +| --- | --- | +| foo | bar | +[*foo*][bar] + +| foo | bar | +| --- | --- | +| foo | bar | +[*foo*] + +[*foo*][bar] +| foo | bar | +| --- | --- | +| foo | bar |