From: Fletcher T. Penney Date: Mon, 8 Oct 2018 19:38:12 +0000 (-0400) Subject: FIXED: Prevent line breaks in HTML/ODF attributes X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=08fbc7c4af27d522bb7270e7411a9c13515c8286;p=multimarkdown FIXED: Prevent line breaks in HTML/ODF attributes --- diff --git a/Sources/libMultiMarkdown/epub.c b/Sources/libMultiMarkdown/epub.c index 9d80324..4539220 100644 --- a/Sources/libMultiMarkdown/epub.c +++ b/Sources/libMultiMarkdown/epub.c @@ -133,7 +133,7 @@ char * epub_package_document(scratch_pad * scratch) { if (m) { print_const("urn:uuid:"); - mmd_print_string_html(out, m->value, false); + mmd_print_string_html(out, m->value, false, false); print_const("\n"); } else { print_const("urn:uuid:"); @@ -149,7 +149,7 @@ char * epub_package_document(scratch_pad * scratch) { if (m) { print_const(""); - mmd_print_string_html(out, m->value, false); + mmd_print_string_html(out, m->value, false, false); print_const("\n"); } else { print_const("Untitled\n"); @@ -160,7 +160,7 @@ char * epub_package_document(scratch_pad * scratch) { if (m) { print_const(""); - mmd_print_string_html(out, m->value, false); + mmd_print_string_html(out, m->value, false, false); print_const("\n"); } @@ -170,7 +170,7 @@ char * epub_package_document(scratch_pad * scratch) { if (m) { print_const(""); - mmd_print_string_html(out, m->value, false); + mmd_print_string_html(out, m->value, false, false); print_const("\n"); } else { switch (scratch->language) { @@ -204,7 +204,7 @@ char * epub_package_document(scratch_pad * scratch) { if (m) { print_const(""); - mmd_print_string_html(out, m->value, false); + mmd_print_string_html(out, m->value, false, false); print_const("\n"); } else { time_t t = time(NULL); @@ -303,7 +303,7 @@ char * epub_nav(mmd_engine * e, scratch_pad * scratch) { HASH_FIND_STR(scratch->meta_hash, "title", temp); if (temp) { - mmd_print_string_html(out, temp->value, false); + mmd_print_string_html(out, temp->value, false, false); } else { print_const("Untitled"); } diff --git a/Sources/libMultiMarkdown/html.c b/Sources/libMultiMarkdown/html.c index 877cd4a..de33c01 100644 --- a/Sources/libMultiMarkdown/html.c +++ b/Sources/libMultiMarkdown/html.c @@ -95,7 +95,7 @@ static char * my_strdup(const char * source) { // Use Knuth's pseudo random generator to obfuscate email addresses predictably long ran_num_next(void); -void mmd_print_char_html(DString * out, char c, bool obfuscate) { +void mmd_print_char_html(DString * out, char c, bool obfuscate, bool line_breaks) { switch (c) { case '"': print_const("""); @@ -115,7 +115,11 @@ void mmd_print_char_html(DString * out, char c, bool obfuscate) { case '\n': case '\r': - print_const("
\n"); + if (line_breaks) { + print_const("
\n"); + } else { + print_char(c); + } break; default: @@ -134,10 +138,10 @@ void mmd_print_char_html(DString * out, char c, bool obfuscate) { } -void mmd_print_string_html(DString * out, const char * str, bool obfuscate) { +void mmd_print_string_html(DString * out, const char * str, bool obfuscate, bool line_breaks) { if (str) { while (*str != '\0') { - mmd_print_char_html(out, *str, obfuscate); + mmd_print_char_html(out, *str, obfuscate, line_breaks); str++; } } @@ -281,7 +285,7 @@ void mmd_export_link_html(DString * out, const char * source, token * text, link if (link->url) { print_const("url, false); + mmd_print_string_html(out, link->url, false, false); print_const("\""); } else { print_const("title && link->title[0] != '\0') { print_const(" title=\""); - mmd_print_string_html(out, link->title, false); + mmd_print_string_html(out, link->title, false, false); print_const("\""); } @@ -1145,7 +1149,7 @@ void mmd_export_token_html(DString * out, const char * source, token * t, scratc (source[t->start + 1] == ' ')) { print_const(" "); } else { - mmd_print_char_html(out, source[t->start + 1], false); + mmd_print_char_html(out, source[t->start + 1], false, false); } break; @@ -1334,15 +1338,15 @@ void mmd_export_token_html(DString * out, const char * source, token * t, scratc temp_bool = true; if (strncmp("mailto:", temp_char, 7) != 0) { - mmd_print_string_html(out, "mailto:", true); + mmd_print_string_html(out, "mailto:", true, false); } } else { temp_bool = false; } - mmd_print_string_html(out, temp_char, temp_bool); + mmd_print_string_html(out, temp_char, temp_bool, false); print_const("\">"); - mmd_print_string_html(out, temp_char, temp_bool); + mmd_print_string_html(out, temp_char, temp_bool, false); print_const(""); } else if (scan_html(&source[t->start])) { print_token(t); @@ -1443,7 +1447,7 @@ void mmd_export_token_html(DString * out, const char * source, token * t, scratc if (temp_short2 == scratch->used_abbreviations->size) { // This is a re-use of a previously used note print_const("clean_text, false); + mmd_print_string_html(out, temp_note->clean_text, false, false); print_const("\">"); if (t->child) { @@ -1455,9 +1459,9 @@ void mmd_export_token_html(DString * out, const char * source, token * t, scratc print_const(""); } else { // This is the first time this note was used - mmd_print_string_html(out, temp_note->clean_text, false); + mmd_print_string_html(out, temp_note->clean_text, false, false); print_const(" (clean_text, false); + mmd_print_string_html(out, temp_note->clean_text, false, false); print_const("\">"); if (t->child) { @@ -1470,11 +1474,11 @@ void mmd_export_token_html(DString * out, const char * source, token * t, scratc } } else { // This is an inline definition (and therefore the first use) - mmd_print_string_html(out, temp_note->clean_text, false); + mmd_print_string_html(out, temp_note->clean_text, false, false); print_const(" (clean_text, false); + mmd_print_string_html(out, temp_note->clean_text, false, false); print_const("\">"); - mmd_print_string_html(out, temp_note->label_text, false); + mmd_print_string_html(out, temp_note->label_text, false, false); print_const(")"); } } else { @@ -1652,7 +1656,7 @@ parse_citation: printf("", temp_short, LC("see glossary")); - mmd_print_string_html(out, temp_note->clean_text, false); + mmd_print_string_html(out, temp_note->clean_text, false, true); print_const(""); } else { // This is the first time this note was used @@ -1660,7 +1664,7 @@ parse_citation: printf("", temp_short, temp_short, LC("see glossary")); - mmd_print_string_html(out, temp_note->clean_text, false); + mmd_print_string_html(out, temp_note->clean_text, false, true); print_const(""); } } else { @@ -1675,7 +1679,7 @@ parse_citation: temp_char2 = extract_metadata(scratch, temp_char); if (temp_char2) { - mmd_print_string_html(out, temp_char2, false); + mmd_print_string_html(out, temp_char2, false, true); } else { mmd_export_token_tree_html(out, source, t->child, scratch); } @@ -2109,7 +2113,7 @@ void mmd_export_token_html_raw(DString * out, const char * source, token * t, sc if (t->next && t->next->type == TEXT_EMPTY && source[t->start + 1] == ' ') { } else { - mmd_print_char_html(out, source[t->start + 1], false); + mmd_print_char_html(out, source[t->start + 1], false, false); } break; @@ -2313,10 +2317,10 @@ void mmd_start_complete_html(DString * out, const char * source, scratch_pad * s store_asset(scratch, m->value); asset * a = extract_asset(scratch, m->value); - mmd_print_string_html(out, "assets/", false); - mmd_print_string_html(out, a->asset_path, false); + mmd_print_string_html(out, "assets/", false, false); + mmd_print_string_html(out, a->asset_path, false, false); } else { - mmd_print_string_html(out, m->value, false); + mmd_print_string_html(out, m->value, false, false); } print_const("\"/>\n"); @@ -2340,7 +2344,7 @@ void mmd_start_complete_html(DString * out, const char * source, scratch_pad * s } else if (strcmp(m->key, "quoteslanguage") == 0) { } else if (strcmp(m->key, "title") == 0) { print_const("\t"); - mmd_print_string_html(out, m->value, false); + mmd_print_string_html(out, m->value, false, true); print_const("\n"); } else if (strcmp(m->key, "transcludebase") == 0) { } else if (strcmp(m->key, "xhtmlheader") == 0) { @@ -2349,9 +2353,9 @@ void mmd_start_complete_html(DString * out, const char * source, scratch_pad * s } else if (strcmp(m->key, "xhtmlheaderlevel") == 0) { } else { print_const("\tkey, false); + mmd_print_string_html(out, m->key, false, false); print_const("\" content=\""); - mmd_print_string_html(out, m->value, false); + mmd_print_string_html(out, m->value, false, false); print_const("\"/>\n"); } } @@ -2470,7 +2474,7 @@ void mmd_export_glossary_list_html(DString * out, const char * source, scratch_p content = note->content; // Print term - mmd_print_string_html(out, note->clean_text, false); + mmd_print_string_html(out, note->clean_text, false, true); print_const(": "); // Print contents diff --git a/Sources/libMultiMarkdown/html.h b/Sources/libMultiMarkdown/html.h index 26386bf..3a0bc84 100644 --- a/Sources/libMultiMarkdown/html.h +++ b/Sources/libMultiMarkdown/html.h @@ -75,7 +75,7 @@ void mmd_export_glossary_list_html(DString * out, const char * source, scratch_p void mmd_start_complete_html(DString * out, const char * source, scratch_pad * scratch); void mmd_end_complete_html(DString * out, const char * source, scratch_pad * scratch); -void mmd_print_string_html(DString * out, const char * str, bool obfuscate); +void mmd_print_string_html(DString * out, const char * str, bool obfuscate, bool line_breaks); #endif diff --git a/Sources/libMultiMarkdown/opendocument-content.c b/Sources/libMultiMarkdown/opendocument-content.c index 37bafd1..69d0be2 100644 --- a/Sources/libMultiMarkdown/opendocument-content.c +++ b/Sources/libMultiMarkdown/opendocument-content.c @@ -136,7 +136,7 @@ static char * my_strdup(const char * source) { } -void mmd_print_char_opendocument(DString * out, char c) { +void mmd_print_char_opendocument(DString * out, char c, bool line_breaks) { switch (c) { case '"': print_const("""); @@ -156,7 +156,11 @@ void mmd_print_char_opendocument(DString * out, char c) { case '\n': case '\r': - print_const("\n"); + if (line_breaks) { + print_const("\n"); + } else { + print_char(c); + } break; case '\t': @@ -169,13 +173,13 @@ void mmd_print_char_opendocument(DString * out, char c) { } -void mmd_print_string_opendocument(DString * out, const char * str) { +void mmd_print_string_opendocument(DString * out, const char * str, bool line_breaks) { if (str == NULL) { return; } while (*str != '\0') { - mmd_print_char_opendocument(out, *str); + mmd_print_char_opendocument(out, *str, line_breaks); str++; } } @@ -321,7 +325,7 @@ void mmd_export_token_opendocument_raw(DString * out, const char * source, token if (t->next && t->next->type == TEXT_EMPTY && source[t->start + 1] == ' ') { } else { - mmd_print_char_opendocument(out, source[t->start + 1]); + mmd_print_char_opendocument(out, source[t->start + 1], false); } break; @@ -513,7 +517,7 @@ void mmd_export_token_opendocument_math(DString * out, const char * source, toke void mmd_export_link_opendocument(DString * out, const char * source, token * text, link * link, scratch_pad * scratch) { if (link->url) { print_const("url); + mmd_print_string_opendocument(out, link->url, false); print_const("\""); } else { print_const("title && link->title[0] != '\0') { print_const(" office:name=\""); - mmd_print_string_opendocument(out, link->title); + mmd_print_string_opendocument(out, link->title, false); print_const("\""); } @@ -1244,7 +1248,7 @@ void mmd_export_token_opendocument(DString * out, const char * source, token * t (source[t->start + 1] == ' ')) { print_const(" "); // This is a non-breaking space character } else { - mmd_print_char_opendocument(out, source[t->start + 1]); + mmd_print_char_opendocument(out, source[t->start + 1], false); } break; @@ -1383,9 +1387,9 @@ void mmd_export_token_opendocument(DString * out, const char * source, token * t temp_bool = false; } - mmd_print_string_opendocument(out, temp_char); + mmd_print_string_opendocument(out, temp_char, false); print_const("\">"); - mmd_print_string_opendocument(out, temp_char); + mmd_print_string_opendocument(out, temp_char, false); print_const(""); } else if (scan_html(&source[t->start])) { // We ignore HTML blocks @@ -1700,11 +1704,11 @@ parse_citation: if (temp_short3 == scratch->inline_abbreviations_to_free->size) { // This is a reference definition - mmd_print_string_opendocument(out, temp_note->label_text); + mmd_print_string_opendocument(out, temp_note->label_text, true); // mmd_export_token_tree_opendocument(out, source, t->child, scratch); } else { // This is an inline definition - mmd_print_string_opendocument(out, temp_note->label_text); + mmd_print_string_opendocument(out, temp_note->label_text, true); // mmd_export_token_tree_opendocument(out, source, t->child, scratch); } } else { @@ -1714,15 +1718,15 @@ parse_citation: if (temp_short3 == scratch->inline_abbreviations_to_free->size) { // This is a reference definition - mmd_print_string_opendocument(out, temp_note->clean_text); + mmd_print_string_opendocument(out, temp_note->clean_text, true); print_const(" ("); - mmd_print_string_opendocument(out, temp_note->label_text); + mmd_print_string_opendocument(out, temp_note->label_text, true); print_const(")"); } else { // This is an inline definition - mmd_print_string_opendocument(out, temp_note->clean_text); + mmd_print_string_opendocument(out, temp_note->clean_text, true); print_const(" ("); - mmd_print_string_opendocument(out, temp_note->label_text); + mmd_print_string_opendocument(out, temp_note->label_text, true); print_const(")"); } @@ -1762,11 +1766,11 @@ parse_citation: if (temp_short2 == scratch->used_glossaries->size) { // This is a re-use of a previously used note - mmd_print_string_opendocument(out, temp_note->clean_text); + mmd_print_string_opendocument(out, temp_note->clean_text, true); } else { // This is the first time this note was used - mmd_print_string_opendocument(out, temp_note->clean_text); + mmd_print_string_opendocument(out, temp_note->clean_text, true); printf("", temp_short); mmd_export_token_tree_opendocument(out, source, temp_note->content, scratch); @@ -1786,7 +1790,7 @@ parse_citation: temp_char2 = extract_metadata(scratch, temp_char); if (temp_char2) { - mmd_print_string_opendocument(out, temp_char2); + mmd_print_string_opendocument(out, temp_char2, true); } else { mmd_export_token_tree_opendocument(out, source, t->child, scratch); } diff --git a/Sources/libMultiMarkdown/opendocument-content.h b/Sources/libMultiMarkdown/opendocument-content.h index b795cb9..cd486ba 100644 --- a/Sources/libMultiMarkdown/opendocument-content.h +++ b/Sources/libMultiMarkdown/opendocument-content.h @@ -107,8 +107,8 @@ #include "writer.h" -void mmd_print_char_opendocument(DString * out, char c); -void mmd_print_string_opendocument(DString * out, const char * str); +void mmd_print_char_opendocument(DString * out, char c, bool line_breaks); +void mmd_print_string_opendocument(DString * out, const char * str, bool line_breaks); void mmd_print_localized_char_opendocument(DString * out, unsigned short type, scratch_pad * scratch); void mmd_export_token_opendocument_raw(DString * out, const char * source, token * t, scratch_pad * scratch); diff --git a/Sources/libMultiMarkdown/opendocument.c b/Sources/libMultiMarkdown/opendocument.c index a59ff04..ba0239c 100644 --- a/Sources/libMultiMarkdown/opendocument.c +++ b/Sources/libMultiMarkdown/opendocument.c @@ -176,7 +176,7 @@ char * opendocument_metadata(mmd_engine * e, scratch_pad * scratch) { for (m = scratch->meta_hash; m != NULL; m = m->hh.next) { if (strcmp(m->key, "author") == 0) { print_const("\t"); - mmd_print_string_opendocument(out, m->value); + mmd_print_string_opendocument(out, m->value, false); print_const("\n"); } else if (strcmp(m->key, "baseheaderlevel") == 0) { } else if (strcmp(m->key, "bibliostyle") == 0) { @@ -197,20 +197,20 @@ char * opendocument_metadata(mmd_engine * e, scratch_pad * scratch) { } else if (strcmp(m->key, "mmdfooter") == 0) { } else if (strcmp(m->key, "mmdheader") == 0) { } else if (strcmp(m->key, "odfheader") == 0) { - mmd_print_string_opendocument(out, m->value); + mmd_print_string_opendocument(out, m->value, false); } else if (strcmp(m->key, "quoteslanguage") == 0) { } else if (strcmp(m->key, "title") == 0) { print_const("\t"); - mmd_print_string_opendocument(out, m->value); + mmd_print_string_opendocument(out, m->value, false); print_const("\n"); } else if (strcmp(m->key, "transcludebase") == 0) { } else if (strcmp(m->key, "xhtmlheader") == 0) { } else if (strcmp(m->key, "xhtmlheaderlevel") == 0) { } else { print_const("\tkey); + mmd_print_string_opendocument(out, m->key, false); print_const("\">"); - mmd_print_string_opendocument(out, m->value); + mmd_print_string_opendocument(out, m->value, false); print_const("\n"); } } diff --git a/tests/MMD6Tests/Metadata.fodt b/tests/MMD6Tests/Metadata.fodt index d0a51ec..5d9cc9a 100644 --- a/tests/MMD6Tests/Metadata.fodt +++ b/tests/MMD6Tests/Metadata.fodt @@ -277,7 +277,7 @@ office:mimetype="application/vnd.oasis.opendocument.text"> *foo* "bar" bar foo bar foo bar - first line + first line second line diff --git a/tests/MMD6Tests/Metadata.html b/tests/MMD6Tests/Metadata.html index d57906e..fa971d7 100644 --- a/tests/MMD6Tests/Metadata.html +++ b/tests/MMD6Tests/Metadata.html @@ -7,7 +7,7 @@ - diff --git a/tests/MMD6Tests/Reference Links.fodt b/tests/MMD6Tests/Reference Links.fodt index 7ad598f..4fe5a9d 100644 --- a/tests/MMD6Tests/Reference Links.fodt +++ b/tests/MMD6Tests/Reference Links.fodt @@ -310,6 +310,9 @@ office:mimetype="application/vnd.oasis.opendocument.text"> foo bar + +Markdown diff --git a/tests/MMD6Tests/Reference Links.html b/tests/MMD6Tests/Reference Links.html index 2735271..cd08867 100644 --- a/tests/MMD6Tests/Reference Links.html +++ b/tests/MMD6Tests/Reference Links.html @@ -39,6 +39,9 @@

foo bar

+

Markdown

+ diff --git a/tests/MMD6Tests/Reference Links.htmlc b/tests/MMD6Tests/Reference Links.htmlc index 40b7728..59d32ae 100644 --- a/tests/MMD6Tests/Reference Links.htmlc +++ b/tests/MMD6Tests/Reference Links.htmlc @@ -33,3 +33,5 @@ latexconfig: article

foo bar

+ +

[Markdown]

diff --git a/tests/MMD6Tests/Reference Links.opml b/tests/MMD6Tests/Reference Links.opml index e56e1c8..80951a4 100644 --- a/tests/MMD6Tests/Reference Links.opml +++ b/tests/MMD6Tests/Reference Links.opml @@ -2,7 +2,7 @@ Reference Links - + diff --git a/tests/MMD6Tests/Reference Links.tex b/tests/MMD6Tests/Reference Links.tex index 1003d03..491a996 100644 --- a/tests/MMD6Tests/Reference Links.tex +++ b/tests/MMD6Tests/Reference Links.tex @@ -35,5 +35,7 @@ \href{http://test.0/}{foo}\footnote{\href{http://test.0/}{http:\slash \slash test.0\slash }} \href{http://test.1/file.txt}{bar}\footnote{\href{http://test.1/file.txt}{http:\slash \slash test.1\slash file.txt}} +\href{http://daringfireball.net/projects/markdown/}{Markdown}\footnote{\href{http://daringfireball.net/projects/markdown/}{http:\slash \slash daringfireball.net\slash projects\slash markdown\slash }} + \input{mmd6-article-footer} \end{document} diff --git a/tests/MMD6Tests/Reference Links.text b/tests/MMD6Tests/Reference Links.text index 63342fc..014a482 100644 --- a/tests/MMD6Tests/Reference Links.text +++ b/tests/MMD6Tests/Reference Links.text @@ -34,6 +34,8 @@ latexconfig: article [foo] [bar] +[Markdown] + [foo]: http://test.0/ [bar]: http://test.1/file.txt @@ -43,3 +45,5 @@ latexconfig: article [foo bar]: http://test.5/ "" [long]: http://test.6/ "title" +[Markdown]: http://daringfireball.net/projects/markdown/ "Daring Fireball: +Markdown"