From f6f98911f31ccb229e359f0e09dec37b48a1bac7 Mon Sep 17 00:00:00 2001 From: "Fletcher T. Penney" Date: Sat, 4 Mar 2017 09:15:13 -0500 Subject: [PATCH] ADDED: Add TOC support to ODF --- Sources/libMultiMarkdown/odf.c | 192 ++++++++++ tests/MMD6Tests/Table of Contents.fodt | 321 ++++++++++++++++ tests/MMD6Tests/Tables.fodt | 510 +++++++++++++++++++++++++ 3 files changed, 1023 insertions(+) create mode 100644 tests/MMD6Tests/Table of Contents.fodt create mode 100644 tests/MMD6Tests/Tables.fodt diff --git a/Sources/libMultiMarkdown/odf.c b/Sources/libMultiMarkdown/odf.c index 46b9626..5a349d5 100644 --- a/Sources/libMultiMarkdown/odf.c +++ b/Sources/libMultiMarkdown/odf.c @@ -547,6 +547,149 @@ void mmd_export_token_odf(DString * out, const char * source, token * t, scratch print_const(""); scratch->padded = 0; break; + case BLOCK_TABLE: + pad(out, 2, scratch); + print_const("\n"); + + scratch->padded = 2; + read_table_column_alignments(source, t, scratch); + + for (int i = 0; i < scratch->table_column_count; ++i) + { + print_const("\n"); +// switch (scratch->table_alignment[i]) { +// case 'l': +// print_const("\n"); +// break; +// case 'L': +// print_const("\n"); +// break; +// case 'r': +// print_const("\n"); +// break; +// case 'R': +// print_const("\n"); +// break; +// case 'c': +// print_const("\n"); +// break; +// case 'C': +// print_const("\n"); +// break; +// default: +// print_const("\n"); +// break; +// } + } + scratch->padded = 1; + + mmd_export_token_tree_odf(out, source, t->child, scratch); + pad(out, 1, scratch); + print_const("\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("Table Update Fields to calculate numbers:", temp_char); + + t->next->child->child->type = TEXT_EMPTY; + t->next->child->child->mate->type = TEXT_EMPTY; + mmd_export_token_tree_odf(out, source, t->next->child->child, scratch); + + printf("\n", temp_char); + + free(temp_char); + temp_short = 1; + } else { + temp_short = 0; + } + + scratch->padded = 0; + scratch->skip_token = temp_short; + + break; + case BLOCK_TABLE_HEADER: + pad(out, 2, scratch); + scratch->in_table_header = 1; + mmd_export_token_tree_odf(out, source, t->child, scratch); + scratch->in_table_header = 0; + scratch->padded = 1; + break; + case BLOCK_TABLE_SECTION: + pad(out, 2, scratch); + scratch->padded = 2; + mmd_export_token_tree_odf(out, source, t->child, scratch); + scratch->padded = 0; + break; + case BLOCK_TOC: + temp_short = 0; + temp_short2 = 0; + pad(out, 2, scratch); + + for (int i = 0; i < scratch->header_stack->size; ++i) + { + temp_token = stack_peek_index(scratch->header_stack, i); + + if (temp_token->type == temp_short2) { + // Same level -- close list item + print_const("\n"); + } + + if (temp_short == 0) { + // First item + print_const("\n\n"); + temp_short = temp_token->type; + temp_short2 = temp_short; + } + + // Indent? + if (temp_token->type == temp_short2) { + // Same level -- NTD + } else if (temp_token->type == temp_short2 + 1) { + // Indent + print_const("\n\n\n"); + temp_short2++; + } else if (temp_token->type < temp_short2) { + // Outdent + print_const("\n"); + while (temp_short2 > temp_token->type) { + if (temp_short2 > temp_short) + print_const("\n"); + else + temp_short = temp_short2 - 1; + + temp_short2--; + } + } else { + // Skipped more than one level -- ignore + continue; + } + + temp_char = label_from_header(source, temp_token); + + printf("", temp_char); + mmd_export_token_tree_odf(out, source, temp_token->child, scratch); + print_const(""); + free(temp_char); + } + + while (temp_short2 > (temp_short)) { + print_const("\n"); + temp_short2--; + } + + if (temp_short) + print_const("\n\n"); + + scratch->padded = 1; + break; case BLOCK_TERM: pad(out, 2, scratch); print_const(""); @@ -1150,6 +1293,55 @@ void mmd_export_token_odf(DString * out, const char * source, token * t, scratch print_const("^"); } break; + case TABLE_CELL: + print_const("next && t->next->type == TABLE_DIVIDER) { + if (t->next->len > 1) { + printf(" table:number-columns-spanned=\"%d\"", t->next->len); + } + } + + if (scratch->in_table_header) { + print_const(">\n\ntable_alignment[scratch->table_cell_count]) { + case 'l': + case 'L': + default: + print_const(" text:style-name=\"MMD-Table\""); + break; + case 'r': + case 'R': + print_const(" text:style-name=\"MMD-Table-Right\""); + break; + case 'c': + case 'C': + print_const(" text:style-name=\"MMD-Table-Center\""); + break; + } + } + + print_const(">"); + mmd_export_token_tree_odf(out, source, t->child, scratch); + + print_const("\n\n"); + + if (t->next) + scratch->table_cell_count += t->next->len; + else + scratch->table_cell_count++; + + break; + case TABLE_DIVIDER: + break; + case TABLE_ROW: + print_const("\n"); + scratch->table_cell_count = 0; + mmd_export_token_tree_odf(out, source, t->child, scratch); + print_const("\n"); + break; case TEXT_EMPTY: break; case TEXT_LINEBREAK: diff --git a/tests/MMD6Tests/Table of Contents.fodt b/tests/MMD6Tests/Table of Contents.fodt new file mode 100644 index 0000000..606111b --- /dev/null +++ b/tests/MMD6Tests/Table of Contents.fodt @@ -0,0 +1,321 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Bibliography + + + +Table of Contents +article + + + + +Second Level + +First Level + + +Second Level b + + +Third Level + + +Second Level c + + +First Level b + + +Second level d + + +Third level d + + +Fourth level d + + + + +First level + + +Second level + + + +Second Level + +First Level + +Second Level b + +Third Level + +Second Level c + +First Level b + +Third Level b + +Second level d + +Third level d + +Fourth level d + +First level + +Second level + + diff --git a/tests/MMD6Tests/Tables.fodt b/tests/MMD6Tests/Tables.fodt new file mode 100644 index 0000000..04c91a0 --- /dev/null +++ b/tests/MMD6Tests/Tables.fodt @@ -0,0 +1,510 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Bibliography + + + + Tables + + + + + + + + + + foo + + + bar + + + + + + foo + + + bar + + + + + foo bar + + + + + + + + + + + + + foo1 + + + bar1 + + + + + +foo + + + bar + + + + + foo bar + + + + + + + + + + + + + foo2 + + + bar2 + + + + + +foo + + + bar + + + + + foo bar + + + + + + + foo3 + + + bar3 + + + + +foo + + + bar + + + + + foo bar + + + + + + +| foo4 | bar4 | +foo | bar | +| foo bar || + +5 + + + + + + + + foo5 + + + bar5 + + + + + +foo + + + bar + + + + + foo bar | + + + + + + + foo6 + + + bar6 + + + + + :—– + + + —–: + + + + +foo + + + bar + + + + + foo bar + + + + + + + + + + + + + foo + + + bar + + + + + + foo + + + bar + + + + +Table Update Fields to calculate numbers:caption + + + + + + + + + foo + + + bar + + + + + + foo + + + bar + + + + +Table Update Fields to calculate numbers:caption + + +[foo][bar] +| foo | bar | +| — | — | +| foo | bar | + + + -- 2.40.0