]> granicus.if.org Git - multimarkdown/commitdiff
ADDED: Add support for table captions
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Wed, 8 Feb 2017 21:35:47 +0000 (16:35 -0500)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Wed, 8 Feb 2017 21:35:47 +0000 (16:35 -0500)
README.md
src/html.c
src/writer.c
src/writer.h
templates/README.md.in
tests/MMD6Tests/Tables.html
tests/MMD6Tests/Tables.htmlc
tests/MMD6Tests/Tables.text

index 701f0e2a13135d3d054b51a3c04d4ae328455934..40a6a35f9929720adbac79a3d9f21e2fe4381de9 100644 (file)
--- 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 ###
index e2e1659bfa325cc0ad7747db57c9a3c0dae96555..dd11e49fa96674bdc0106b59b9fadd6d9f19fa97 100644 (file)
@@ -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("<table>\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("<caption id=\"%s\">", 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("</caption>\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("</table>");
                        scratch->padded = 0;
+
+                       scratch->skip_token = temp_short;
+
                        break;
                case BLOCK_TABLE_HEADER:
                        pad(out, 2, scratch);
index 5a0ebe3ec6a9f6af5bce365a935b68dd586aa175..a66bd884179311403354da6ac7c70bef0351ebac 100644 (file)
@@ -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;
+}
+
index bc35c2c4e95dfe63ab810948debb0838d0ba211b..b47babe66f49a48d5c49b7c6f4a9561004ec0598 100644 (file)
@@ -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
 
index 345cd8b3d4f303a38d04295db0197183a2ea9340..d4365ee0d6fc45641f903fa5a8fb5d353acd7c52 100644 (file)
@@ -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 ###
index 32a29361e9d5081da7d672bb5af23db217c6b757..15d4fd8b4d87a34a6ae897e812dbb6748f8abe94 100644 (file)
 </tr>
 </tbody>
 </table>
+
+<table>
+<caption id="bar"><em>foo</em></caption>
+<colgroup>
+<col />
+<col />
+</colgroup>
+
+<thead>
+<tr>
+       <th> foo </th>
+       <th> bar </th>
+</tr>
+</thead>
+
+<tbody>
+<tr>
+       <td> foo </td>
+       <td> bar </td>
+</tr>
+</tbody>
+</table>
+
+<table>
+<caption id="foo"><em>foo</em></caption>
+<colgroup>
+<col />
+<col />
+</colgroup>
+
+<thead>
+<tr>
+       <th> foo </th>
+       <th> bar </th>
+</tr>
+</thead>
+
+<tbody>
+<tr>
+       <td> foo </td>
+       <td> bar </td>
+</tr>
+</tbody>
+</table>
+
+<p>[<em>foo</em>][bar]
+| foo | bar |
+| &#8212; | &#8212; |
+| foo | bar |</p>
index 8a80926449602a074e17d137755f987c4e955789..80ae6aed9fc96fa84b11ea6069ed77735ad073fe 100644 (file)
 | :---- | ----: |
 <em>foo</em> | <em>bar</em> |
 | <strong>foo bar</strong> ||</p>
+
+<p>| foo | bar |
+| --- | --- |
+| foo | bar |
+[<em>foo</em>][bar]</p>
+
+<p>| foo | bar |
+| --- | --- |
+| foo | bar |
+[<em>foo</em>]</p>
+
+<p>[<em>foo</em>][bar]
+| foo | bar |
+| --- | --- |
+| foo | bar |</p>
index 696e78f4891ac53ace70d4e8422c3a3d8c947caf..4b5dcf2a393b739df15e464931288c591e31967f 100644 (file)
 | 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 |