From 06b2c7743152763e0d91fc81e85ba97d1d1765ea Mon Sep 17 00:00:00 2001 From: "Fletcher T. Penney" Date: Fri, 3 Mar 2017 15:27:57 -0500 Subject: [PATCH] ADDED: Added LaTeX support for escaped characters, fenced code blocks, images, links --- Sources/libMultiMarkdown/latex.c | 4 +- Sources/libMultiMarkdown/odf.c | 132 ++++++--- tests/MMD6Tests/Escapes.fodt | 348 ++++++++++++++++++++++++ tests/MMD6Tests/Fenced Code Blocks.fodt | 283 +++++++++++++++++++ tests/MMD6Tests/Figure Images.fodt | 293 ++++++++++++++++++++ tests/MMD6Tests/Inline Links.fodt | 303 +++++++++++++++++++++ tests/MMD6Tests/Link Attributes.fodt | 283 +++++++++++++++++++ tests/MMD6Tests/Reference Links.fodt | 291 ++++++++++++++++++++ 8 files changed, 1890 insertions(+), 47 deletions(-) create mode 100644 tests/MMD6Tests/Escapes.fodt create mode 100644 tests/MMD6Tests/Fenced Code Blocks.fodt create mode 100644 tests/MMD6Tests/Figure Images.fodt create mode 100644 tests/MMD6Tests/Inline Links.fodt create mode 100644 tests/MMD6Tests/Link Attributes.fodt create mode 100644 tests/MMD6Tests/Reference Links.fodt diff --git a/Sources/libMultiMarkdown/latex.c b/Sources/libMultiMarkdown/latex.c index b0e5875..cab0d58 100644 --- a/Sources/libMultiMarkdown/latex.c +++ b/Sources/libMultiMarkdown/latex.c @@ -253,7 +253,7 @@ void mmd_export_link_latex(DString * out, const char * source, token * text, lin } -char * correct_dimension_units(char *original) { +static char * correct_dimension_units(char *original) { char *result; int i; @@ -917,7 +917,7 @@ void mmd_export_token_latex(DString * out, const char * source, token * t, scrat print_const("mailto:"); } } - + print(temp_char); print_const("}{"); mmd_print_string_latex(out, temp_char); diff --git a/Sources/libMultiMarkdown/odf.c b/Sources/libMultiMarkdown/odf.c index a418455..1c05b6c 100644 --- a/Sources/libMultiMarkdown/odf.c +++ b/Sources/libMultiMarkdown/odf.c @@ -206,15 +206,6 @@ void mmd_export_link_odf(DString * out, const char * source, token * text, link print_const("\""); } - while (a) { - print_const(" "); - print(a->key); - print_const("=\""); - print(a->value); - print_const("\""); - a = a->next; - } - print_const(">"); // If we're printing contents of bracket as text, then ensure we include it all @@ -229,60 +220,77 @@ void mmd_export_link_odf(DString * out, const char * source, token * text, link } +static char * correct_dimension_units(char *original) { + char *result; + int i; + + result = strdup(original); + + for (i = 0; result[i]; i++) + result[i] = tolower(result[i]); + + if (strstr(&result[strlen(result)-2],"px")) { + result[strlen(result)-2] = '\0'; + strcat(result, "pt"); + } + + return result; +} + + void mmd_export_image_odf(DString * out, const char * source, token * text, link * link, scratch_pad * scratch, bool is_figure) { attr * a = link->attributes; + char * height = NULL; + char * width = NULL; - // Compatibility mode doesn't allow figures - if (scratch->extensions & EXT_COMPATIBILITY) - is_figure = false; - - if (is_figure) { - // Remove wrapping

markers - d_string_erase(out, out->currentStringLength - 3, 3); - print_const("

\n"); - scratch->close_para = false; - } + print_const("url) - printf("url); - else - print_const("key) == 0) { + height = correct_dimension_units(a->value); + } else if (strcmp("width", a->key) == 0) { + width = correct_dimension_units(a->value); + } - if (text) { - print_const(" alt=\""); - print_token_tree_raw(out, source, text->child); - print_const("\""); + a = a->next; } - if (link->label && !(scratch->extensions & EXT_COMPATIBILITY)) { - // \todo: Need to decide on approach to id's - char * label = label_from_token(source, link->label); - printf(" id=\"%s\"", label); - free(label); + if (width) { + printf(" svg:width=\"%s\">\n", width); + } else { + print_const(" svg:width=\"95%\">\n"); } - if (link->title && link->title[0] != '\0') - printf(" title=\"%s\"", link->title); + print_const("key); - print_const("=\""); - print(a->value); - print_const("\""); - a = a->next; + if (height && width) { + printf("svg:height=\"%s\" ", height); + printf("svg:width=\"%s\" ", width); } - print_const(" />"); + if (height) + free(height); + + if (width) + free(width); + + if (link->url) + printf(">\nurl); + + print_const(" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\" draw:filter-name=\"<All formats>\"/>\n"); if (is_figure) { if (text) { - print_const("\n
"); + print_const("\nFigure Update Fields to calculate numbers: "); mmd_export_token_tree_odf(out, source, text->child, scratch); - print_const("
"); + print_const(""); } - print_const("\n
"); } + + print_const("\n\n"); + + scratch->padded = 1; } @@ -473,6 +481,14 @@ void mmd_export_token_odf(DString * out, const char * source, token * t, scratch print_const(""); scratch->padded = 0; break; + case BRACKET_CITATION_LEFT: + print_const("[#"); + case BRACKET_LEFT: + print_const("["); + break; + case BRACKET_RIGHT: + print_const("]"); + break; case COLON: print_char(':'); break; @@ -506,6 +522,14 @@ void mmd_export_token_odf(DString * out, const char * source, token * t, scratch case EQUAL: print_char('='); break; + case ESCAPED_CHARACTER: + if (!(scratch->extensions & EXT_COMPATIBILITY) && + (source[t->start + 1] == ' ')) { + print_const(" "); + } else { + mmd_print_char_odf(out, source[t->start + 1]); + } + break; case INDENT_SPACE: print_char(' '); break; @@ -694,6 +718,24 @@ void mmd_export_token_odf(DString * out, const char * source, token * t, scratch case PAREN_RIGHT: print_char(')'); break; + case QUOTE_SINGLE: + if ((t->mate == NULL) || (!(scratch->extensions & EXT_SMART))) + print_const("'"); + else + (t->start < t->mate->start) ? ( print_localized(QUOTE_LEFT_SINGLE) ) : ( print_localized(QUOTE_RIGHT_SINGLE) ); + break; + case QUOTE_DOUBLE: + if ((t->mate == NULL) || (!(scratch->extensions & EXT_SMART))) + print_const("""); + else + (t->start < t->mate->start) ? ( print_localized(QUOTE_LEFT_DOUBLE) ) : ( print_localized(QUOTE_RIGHT_DOUBLE) ); + break; + case QUOTE_RIGHT_ALT: + if ((t->mate == NULL) || (!(scratch->extensions & EXT_SMART))) + print_const("''"); + else + print_localized(QUOTE_RIGHT_DOUBLE); + break; case SLASH: print_char('/'); break; diff --git a/tests/MMD6Tests/Escapes.fodt b/tests/MMD6Tests/Escapes.fodt new file mode 100644 index 0000000..471c686 --- /dev/null +++ b/tests/MMD6Tests/Escapes.fodt @@ -0,0 +1,348 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Bibliography + + + + +. + +! + +? + +, + +; + +5 + +: + +" + +' + +` + +~ + +10 + +( + +) + +{ + +} + +[ + +15 + +] + +# + +$ + +% + ++ + +20 + +- + += + +< + +> + +& + +25 + +@ + +\ + +/ + +^ + +* + +30 + +_ + +| + +\-\&\%\\\` + +\- \& \% \\ \` + +*foo* + +35 + +_bar_ + +`foo` + +foo bar + + + diff --git a/tests/MMD6Tests/Fenced Code Blocks.fodt b/tests/MMD6Tests/Fenced Code Blocks.fodt new file mode 100644 index 0000000..4936dd6 --- /dev/null +++ b/tests/MMD6Tests/Fenced Code Blocks.fodt @@ -0,0 +1,283 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Bibliography + + + + +*foo* + +*foo*bar + + + +foo + +*foo* + + +foo + +*foo*bar + + + +\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation} + +\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation} + +5 + +foo + + + diff --git a/tests/MMD6Tests/Figure Images.fodt b/tests/MMD6Tests/Figure Images.fodt new file mode 100644 index 0000000..e420bbb --- /dev/null +++ b/tests/MMD6Tests/Figure Images.fodt @@ -0,0 +1,293 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Bibliography + + + + + + + + +Figure Update Fields to calculate numbers: foo + + + + + + + +Figure Update Fields to calculate numbers: bar + + + + + + + + + bar + + + + + +Figure Update Fields to calculate numbers: foo + + + + + diff --git a/tests/MMD6Tests/Inline Links.fodt b/tests/MMD6Tests/Inline Links.fodt new file mode 100644 index 0000000..7e8d93b --- /dev/null +++ b/tests/MMD6Tests/Inline Links.fodt @@ -0,0 +1,303 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Bibliography + + + + +Just a URL. + +URL and title. + +URL and title. + +URL and title. + +URL and title. + +5 + +Empty. + +URL and title. + +URL and title. + +URL and title. + +URL and title. + +10 + +URL and title. + +URL and title. + +[URL and title] (/url/file.txt “title”). + +[URL and title] +(/url/file.txt “title”). + +URL and title. + +15 + +URL and title. + +URL and title. + +URL and title. + +URL and title. + + + diff --git a/tests/MMD6Tests/Link Attributes.fodt b/tests/MMD6Tests/Link Attributes.fodt new file mode 100644 index 0000000..51011fb --- /dev/null +++ b/tests/MMD6Tests/Link Attributes.fodt @@ -0,0 +1,283 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Bibliography + + + + +foo + + + + + + +foo link + +foo link2 + +foo link3 + + + + + +Figure Update Fields to calculate numbers: test + + + +5 + + + diff --git a/tests/MMD6Tests/Reference Links.fodt b/tests/MMD6Tests/Reference Links.fodt new file mode 100644 index 0000000..003c175 --- /dev/null +++ b/tests/MMD6Tests/Reference Links.fodt @@ -0,0 +1,291 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Bibliography + + + + +foo. + +foo. + +foo. + +foo. + +foo. + +5 + +foo. + +foo. + +foo. + +foo + +foo + +10 + +foo + +foo + +foo bar + +foo +bar + + + -- 2.40.0