#include "beamer.h"
#define print(x) d_string_append(out, x)
+#define print_const(x) d_string_append_c_array(out, x, sizeof(x) - 1)
#define print_char(x) d_string_append_c(out, x)
#define printf(...) d_string_append_printf(out, __VA_ARGS__)
#define print_token(t) d_string_append_c_array(out, &(source[t->start]), t->len)
switch (t_level) {
case 3:
pad(out, 1, scratch);
- print("\\end{frame}\n\n");
+ print_const("\\end{frame}\n\n");
scratch->padded = 2;
break;
case 4:
pad(out, 1, scratch);
- print("}\n\n");
+ print_const("}\n\n");
scratch->padded = 2;
break;
}
switch (level) {
case 3:
pad(out, 2, scratch);
- print("\\begin{frame}[fragile]\n");
+ print_const("\\begin{frame}[fragile]\n");
scratch->padded = 1;
stack_push(s, current);
break;
case 4:
pad(out, 2, scratch);
- print("\\mode<article>{");
+ print_const("\\mode<article>{");
scratch->padded = 0;
stack_push(s, current);
break;
if (temp_char) {
printf("\\begin{lstlisting}[language=%s]\n", temp_char);
} else {
- print("\\begin{verbatim}\n");
+ print_const("\\begin{verbatim}\n");
}
mmd_export_token_tree_latex_raw(out, source, t->child->next, scratch);
if (temp_char) {
- print("\\end{lstlisting}");
+ print_const("\\end{lstlisting}");
free(temp_char);
} else {
- print("\\end{verbatim}");
+ print_const("\\end{verbatim}");
}
scratch->padded = 0;
break;
case BLOCK_CODE_INDENTED:
pad(out, 2, scratch);
- print("\\begin{verbatim}\n");
+ print_const("\\begin{verbatim}\n");
mmd_export_token_tree_latex_raw(out, source, t->child, scratch);
- print("\\end{verbatim}");
+ print_const("\\end{verbatim}");
scratch->padded = 0;
break;
case BLOCK_H1:
switch (temp_short + scratch->base_header_level - 1) {
case 1:
- print("\\part{");
+ print_const("\\part{");
break;
case 2:
- print("\\section{");
+ print_const("\\section{");
break;
case 3:
- print("\\frametitle{");
+ print_const("\\frametitle{");
break;
default:
- print("\\emph{");
+ print_const("\\emph{");
break;
}
mmd_export_token_tree_beamer(out, source, t->child, scratch);
if (scratch->extensions & EXT_NO_LABELS) {
- print("}");
+ print_const("}");
} else {
temp_token = manual_label_from_header(t, source);
if (temp_token) {
token * content;
pad(out, 2, scratch);
- print("\\part{Bibliography}\n\\begin{frame}[allowframebreaks]\n\\frametitle{Bibliography}\n\\def\\newblock{}\n\\begin{thebibliography}{0}");
+ print_const("\\part{Bibliography}\n\\begin{frame}[allowframebreaks]\n\\frametitle{Bibliography}\n\\def\\newblock{}\n\\begin{thebibliography}{0}");
scratch->padded = 0;
for (int i = 0; i < scratch->used_citations->size; ++i)
}
pad(out, 1, scratch);
- print("\\end{thebibliography}\n\\end{frame}");
+ print_const("\\end{thebibliography}\n\\end{frame}");
scratch->padded = 0;
scratch->citation_being_printed = 0;
}
void mmd_end_complete_beamer(DString * out, const char * source, scratch_pad * scratch) {
pad(out, 2, scratch);
- print("\\mode<all>\n");
+ print_const("\\mode<all>\n");
meta * m = extract_meta_from_stack(scratch, "latexfooter");
if (m) {
printf("\\input{%s}\n\n", m->value);
}
- print("\\end{document}");
- print("\\mode*\n");
+ print_const("\\end{document}");
+ print_const("\\mode*\n");
scratch->padded = 0;
}
#define print(x) d_string_append(out, x)
+#define print_const(x) d_string_append_c_array(out, x, sizeof(x) - 1)
#define print_char(x) d_string_append_c(out, x)
#define printf(...) d_string_append_printf(out, __VA_ARGS__)
#define print_token(t) d_string_append_c_array(out, &(source[t->start]), t->len)
void mmd_print_char_html(DString * out, char c, bool obfuscate) {
switch (c) {
case '"':
- print(""");
+ print_const(""");
break;
case '&':
- print("&");
+ print_const("&");
break;
case '<':
- print("<");
+ print_const("<");
break;
case '>':
- print(">");
+ print_const(">");
break;
default:
if (obfuscate && ((int) c == (((int) c) & 127))) {
void mmd_print_localized_char_html(DString * out, unsigned short type, scratch_pad * scratch) {
switch (type) {
case DASH_N:
- print("–");
+ print_const("–");
break;
case DASH_M:
- print("—");
+ print_const("—");
break;
case ELLIPSIS:
- print("…");
+ print_const("…");
break;
case APOSTROPHE:
- print("’");
+ print_const("’");
break;
case QUOTE_LEFT_SINGLE:
switch (scratch->quotes_lang) {
print( "’");
break;
case FRENCH:
- print("'");
+ print_const("'");
break;
case GERMAN:
- print("‚");
+ print_const("‚");
break;
case GERMANGUILL:
- print("›");
+ print_const("›");
break;
default:
- print("‘");
+ print_const("‘");
}
break;
case QUOTE_RIGHT_SINGLE:
switch (scratch->quotes_lang) {
case GERMAN:
- print("‘");
+ print_const("‘");
break;
case GERMANGUILL:
- print("‹");
+ print_const("‹");
break;
default:
- print("’");
+ print_const("’");
}
break;
case QUOTE_LEFT_DOUBLE:
switch (scratch->quotes_lang) {
case DUTCH:
case GERMAN:
- print("„");
+ print_const("„");
break;
case GERMANGUILL:
- print("»");
+ print_const("»");
break;
case FRENCH:
- print("«");
+ print_const("«");
break;
case SWEDISH:
print( "”");
break;
default:
- print("“");
+ print_const("“");
}
break;
case QUOTE_RIGHT_DOUBLE:
switch (scratch->quotes_lang) {
case GERMAN:
- print("“");
+ print_const("“");
break;
case GERMANGUILL:
- print("«");
+ print_const("«");
break;
case FRENCH:
- print("»");
+ print_const("»");
break;
case SWEDISH:
case DUTCH:
default:
- print("”");
+ print_const("”");
}
break;
}
attr * a = link->attributes;
if (link->url) {
- print("<a href=\"");
+ print_const("<a href=\"");
mmd_print_string_html(out, link->url, false);
- print("\"");
+ print_const("\"");
} else
- print("<a href=\"\"");
+ print_const("<a href=\"\"");
if (link->title && link->title[0] != '\0') {
- print(" title=\"");
+ print_const(" title=\"");
mmd_print_string_html(out, link->title, false);
- print("\"");
+ print_const("\"");
}
while (a) {
- print(" ");
+ print_const(" ");
print(a->key);
- print("=\"");
+ print_const("=\"");
print(a->value);
- print("\"");
+ print_const("\"");
a = a->next;
}
- print(">");
+ print_const(">");
// If we're printing contents of bracket as text, then ensure we include it all
if (text && text->child && text->child->len > 1) {
mmd_export_token_tree_html(out, source, text->child, offset, scratch);
- print("</a>");
+ print_const("</a>");
}
if (is_figure) {
// Remove wrapping <p> markers
d_string_erase(out, out->currentStringLength - 3, 3);
- print("<figure>\n");
+ print_const("<figure>\n");
scratch->close_para = false;
}
if (link->url)
printf("<img src=\"%s\"", link->url);
else
- print("<img src=\"\"");
+ print_const("<img src=\"\"");
if (text) {
- print(" alt=\"");
+ print_const(" alt=\"");
print_token_tree_raw(out, source, text->child);
- print("\"");
+ print_const("\"");
}
if (link->label && !(scratch->extensions & EXT_COMPATIBILITY)) {
printf(" title=\"%s\"", link->title);
while (a) {
- print(" ");
+ print_const(" ");
print(a->key);
- print("=\"");
+ print_const("=\"");
print(a->value);
- print("\"");
+ print_const("\"");
a = a->next;
}
- print(" />");
+ print_const(" />");
if (is_figure) {
if (text) {
- print("\n<figcaption>");
+ print_const("\n<figcaption>");
mmd_export_token_tree_html(out, source, text->child, offset, scratch);
- print("</figcaption>");
+ print_const("</figcaption>");
}
- print("\n</figure>");
+ print_const("\n</figure>");
}
}
switch (t->type) {
case AMPERSAND:
case AMPERSAND_LONG:
- print("&");
+ print_const("&");
break;
case ANGLE_LEFT:
- print("<");
+ print_const("<");
break;
case ANGLE_RIGHT:
- print(">");
+ print_const(">");
break;
case APOSTROPHE:
if (!(scratch->extensions & EXT_SMART)) {
print_localized(QUOTE_LEFT_DOUBLE);
}
else if (t->start < t->mate->start) {
- print("<code>");
+ print_const("<code>");
} else {
- print("</code>");
+ print_const("</code>");
}
break;
case BLOCK_BLOCKQUOTE:
pad(out, 2, scratch);
- print("<blockquote>\n");
+ print_const("<blockquote>\n");
scratch->padded = 2;
mmd_export_token_tree_html(out, source, t->child, t->start + offset, scratch);
pad(out, 1, scratch);
- print("</blockquote>");
+ print_const("</blockquote>");
scratch->padded = 0;
break;
case BLOCK_DEFINITION:
pad(out, 2, scratch);
- print("<dd>");
+ print_const("<dd>");
temp_short = scratch->list_is_tight;
if (!(t->child->next && (t->child->next->type == BLOCK_EMPTY) && t->child->next->next))
scratch->list_is_tight = true;
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
- print("</dd>");
+ print_const("</dd>");
scratch->padded = 0;
scratch->list_is_tight = temp_short;
// lemon's LALR(1) parser can't properly handle this (to my understanding).
if (!(t->prev && (t->prev->type == BLOCK_DEFLIST)))
- print("<dl>\n");
+ print_const("<dl>\n");
scratch->padded = 2;
pad(out, 1, scratch);
if (!(t->next && (t->next->type == BLOCK_DEFLIST)))
- print("</dl>\n");
+ print_const("</dl>\n");
scratch->padded = 1;
break;
case BLOCK_CODE_FENCED:
pad(out, 2, scratch);
- print("<pre><code");
+ print_const("<pre><code");
temp_char = get_fence_language_specifier(t->child->child, source);
if (temp_char) {
free(temp_char);
}
- print(">");
+ print_const(">");
mmd_export_token_tree_html_raw(out, source, t->child->next, t->start + offset, scratch);
- print("</code></pre>");
+ print_const("</code></pre>");
scratch->padded = 0;
break;
case BLOCK_CODE_INDENTED:
pad(out, 2, scratch);
- print("<pre><code>");
+ print_const("<pre><code>");
mmd_export_token_tree_html_raw(out, source, t->child, t->start + offset, scratch);
- print("</code></pre>");
+ print_const("</code></pre>");
scratch->padded = 0;
break;
case BLOCK_EMPTY:
break;
case BLOCK_HR:
pad(out, 2, scratch);
- print("<hr />");
+ print_const("<hr />");
scratch->padded = 0;
break;
case BLOCK_HTML:
break;
}
pad(out, 2, scratch);
- print("<ul>");
+ print_const("<ul>");
scratch->padded = 0;
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
pad(out, 1, scratch);
- print("</ul>");
+ print_const("</ul>");
scratch->padded = 0;
scratch->list_is_tight = temp_short;
break;
break;
}
pad(out, 2, scratch);
- print("<ol>");
+ print_const("<ol>");
scratch->padded = 0;
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
pad(out, 1, scratch);
- print("</ol>");
+ print_const("</ol>");
scratch->padded = 0;
scratch->list_is_tight = temp_short;
break;
case BLOCK_LIST_ITEM:
pad(out, 1, scratch);
- print("<li>");
+ print_const("<li>");
scratch->padded = 2;
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
- print("</li>");
+ print_const("</li>");
scratch->padded = 0;
break;
case BLOCK_LIST_ITEM_TIGHT:
pad(out, 1, scratch);
- print("<li>");
+ print_const("<li>");
if (!scratch->list_is_tight)
- print("<p>");
+ print_const("<p>");
scratch->padded = 2;
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
if (scratch->close_para) {
if (!scratch->list_is_tight)
- print("</p>");
+ print_const("</p>");
} else {
scratch->close_para = true;
}
- print("</li>");
+ print_const("</li>");
scratch->padded = 0;
break;
case BLOCK_META:
pad(out, 2, scratch);
if (!scratch->list_is_tight)
- print("<p>");
+ print_const("<p>");
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
if (scratch->close_para) {
if (!scratch->list_is_tight)
- print("</p>");
+ print_const("</p>");
} else {
scratch->close_para = true;
}
break;
case BLOCK_TABLE:
pad(out, 2, scratch);
- print("<table>\n");
+ print_const("<table>\n");
// Are we followed by a caption?
if (table_has_caption(t)) {
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");
+ print_const("</caption>\n");
temp_short = 1;
} else {
temp_short = 0;
scratch->padded = 2;
read_table_column_alignments(source, t, scratch);
- print("<colgroup>\n");
+ print_const("<colgroup>\n");
for (int i = 0; i < scratch->table_column_count; ++i)
{
switch (scratch->table_alignment[i]) {
case 'l':
- print("<col style=\"text-align:left;\"/>\n");
+ print_const("<col style=\"text-align:left;\"/>\n");
break;
case 'L':
- print("<col style=\"text-align:left;\" class=\"extended\"/>\n");
+ print_const("<col style=\"text-align:left;\" class=\"extended\"/>\n");
break;
case 'r':
- print("<col style=\"text-align:right;\"/>\n");
+ print_const("<col style=\"text-align:right;\"/>\n");
break;
case 'R':
- print("<col style=\"text-align:right;\" class=\"extended\"/>\n");
+ print_const("<col style=\"text-align:right;\" class=\"extended\"/>\n");
break;
case 'c':
- print("<col style=\"text-align:center;\"/>\n");
+ print_const("<col style=\"text-align:center;\"/>\n");
break;
case 'C':
- print("<col style=\"text-align:center;\" class=\"extended\"/>\n");
+ print_const("<col style=\"text-align:center;\" class=\"extended\"/>\n");
break;
default:
- print("<col />\n");
+ print_const("<col />\n");
break;
}
}
- print("</colgroup>\n");
+ print_const("</colgroup>\n");
scratch->padded = 1;
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
pad(out, 1, scratch);
- print("</table>");
+ print_const("</table>");
scratch->padded = 0;
scratch->skip_token = temp_short;
break;
case BLOCK_TABLE_HEADER:
pad(out, 2, scratch);
- print("<thead>\n");
+ print_const("<thead>\n");
scratch->in_table_header = 1;
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
scratch->in_table_header = 0;
- print("</thead>\n");
+ print_const("</thead>\n");
scratch->padded = 1;
break;
case BLOCK_TABLE_SECTION:
pad(out, 2, scratch);
- print("<tbody>\n");
+ print_const("<tbody>\n");
scratch->padded = 2;
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
- print("</tbody>");
+ print_const("</tbody>");
scratch->padded = 0;
break;
case BLOCK_TERM:
pad(out, 2, scratch);
- print("<dt>");
+ print_const("<dt>");
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
- print("</dt>\n");
+ print_const("</dt>\n");
scratch->padded = 2;
break;
case BLOCK_TOC:
temp_short = 0;
temp_short2 = 0;
pad(out, 2, scratch);
- print("<div class=\"TOC\">");
+ print_const("<div class=\"TOC\">");
for (int i = 0; i < scratch->header_stack->size; ++i)
{
if (temp_token->type == temp_short2) {
// Same level -- close list item
- print("</li>\n");
+ print_const("</li>\n");
}
if (temp_short == 0) {
// First item
- print("\n<ul>\n");
+ print_const("\n<ul>\n");
temp_short = temp_token->type;
temp_short2 = temp_short;
}
// Same level -- NTD
} else if (temp_token->type == temp_short2 + 1) {
// Indent
- print("\n\n<ul>\n");
+ print_const("\n\n<ul>\n");
temp_short2++;
} else if (temp_token->type < temp_short2) {
// Outdent
- print("</li>\n");
+ print_const("</li>\n");
while (temp_short2 > temp_token->type) {
if (temp_short2 > temp_short)
- print("</ul></li>\n");
+ print_const("</ul></li>\n");
else
temp_short = temp_short2 - 1;
printf("<li><a href=\"#%s\">", temp_char);
mmd_export_token_tree_html(out, source, temp_token->child, offset, scratch);
- print("</a>");
+ print_const("</a>");
free(temp_char);
}
while (temp_short2 > (temp_short)) {
- print("</ul>\n");
+ print_const("</ul>\n");
temp_short2--;
}
if (temp_short)
- print("</li>\n</ul>\n");
+ print_const("</li>\n</ul>\n");
- print("</div>");
+ print_const("</div>");
scratch->padded = 0;
break;
case BRACE_DOUBLE_LEFT:
- print("{{");
+ print_const("{{");
break;
case BRACE_DOUBLE_RIGHT:
- print("}}");
+ print_const("}}");
break;
case BRACKET_LEFT:
- print("[");
+ print_const("[");
break;
case BRACKET_CITATION_LEFT:
- print("[#");
+ print_const("[#");
break;
case BRACKET_FOOTNOTE_LEFT:
- print("[^");
+ print_const("[^");
break;
case BRACKET_IMAGE_LEFT:
- print("![");
+ print_const("![");
break;
case BRACKET_VARIABLE_LEFT:
- print("[\%");
+ print_const("[\%");
break;
case BRACKET_RIGHT:
- print("]");
+ print_const("]");
break;
case COLON:
- print(":");
+ print_const(":");
break;
case CRITIC_ADD_OPEN:
- print("{++");
+ print_const("{++");
break;
case CRITIC_ADD_CLOSE:
- print("++}");
+ print_const("++}");
break;
case CRITIC_COM_OPEN:
- print("{>>");
+ print_const("{>>");
break;
case CRITIC_COM_CLOSE:
- print("<<}");
+ print_const("<<}");
break;
case CRITIC_DEL_OPEN:
- print("{--");
+ print_const("{--");
break;
case CRITIC_DEL_CLOSE:
- print("--}");
+ print_const("--}");
break;
case CRITIC_HI_OPEN:
- print("{==");
+ print_const("{==");
break;
case CRITIC_HI_CLOSE:
- print("==}");
+ print_const("==}");
break;
case CRITIC_SUB_OPEN:
- print("{~~");
+ print_const("{~~");
break;
case CRITIC_SUB_DIV:
- print("~>");
+ print_const("~>");
break;
case CRITIC_SUB_CLOSE:
- print("~~}");
+ print_const("~~}");
break;
case DASH_M:
if (!(scratch->extensions & EXT_SMART)) {
}
break;
case EMPH_START:
- print("<em>");
+ print_const("<em>");
break;
case EMPH_STOP:
- print("</em>");
+ print_const("</em>");
break;
case EQUAL:
- print("=");
+ print_const("=");
break;
case ESCAPED_CHARACTER:
if (!(scratch->extensions & EXT_COMPATIBILITY) &&
(source[t->start + 1] == ' ')) {
- print(" ");
+ print_const(" ");
} else {
mmd_print_char_html(out, source[t->start + 1], false);
}
break;
case MATH_BRACKET_OPEN:
if (t->mate) {
- print("<span class=\"math\">\\[");
+ print_const("<span class=\"math\">\\[");
} else
- print("\\[");
+ print_const("\\[");
break;
case MATH_BRACKET_CLOSE:
if (t->mate) {
- print("\\]</span>");
+ print_const("\\]</span>");
} else
- print("\\]");
+ print_const("\\]");
break;
case MATH_DOLLAR_SINGLE:
if (t->mate) {
- (t->start < t->mate->start) ? ( print("<span class=\"math\">\\(") ) : ( print("\\)</span>") );
+ (t->start < t->mate->start) ? ( print_const("<span class=\"math\">\\(") ) : ( print_const("\\)</span>") );
} else {
- print("$");
+ print_const("$");
}
break;
case MATH_DOLLAR_DOUBLE:
if (t->mate) {
- (t->start < t->mate->start) ? ( print("<span class=\"math\">\\[") ) : ( print("\\]</span>") );
+ (t->start < t->mate->start) ? ( print_const("<span class=\"math\">\\[") ) : ( print_const("\\]</span>") );
} else {
- print("$$");
+ print_const("$$");
}
break;
case MATH_PAREN_OPEN:
if (t->mate) {
- print("<span class=\"math\">\\(");
+ print_const("<span class=\"math\">\\(");
} else
- print("\\(");
+ print_const("\\(");
break;
case MATH_PAREN_CLOSE:
if (t->mate) {
- print("\\)</span>");
+ print_const("\\)</span>");
} else
- print("\\)");
+ print_const("\\)");
break;
case NON_INDENT_SPACE:
print_char(' ');
}
t->child->type = TEXT_EMPTY;
t->child->mate->type = TEXT_EMPTY;
- print("<code>");
+ print_const("<code>");
mmd_export_token_tree_html_raw(out, source, t->child, offset, scratch);
- print("</code>");
+ print_const("</code>");
break;
case PAIR_ANGLE:
temp_char = url_accept(source, t->start + 1, t->len - 2, NULL, true);
temp_bool = true;
else
temp_bool = false;
- print("<a href=\"");
+ print_const("<a href=\"");
mmd_print_string_html(out, temp_char, temp_bool);
- print("\">");
+ print_const("\">");
mmd_print_string_html(out, temp_char, temp_bool);
- print("</a>");
+ print_const("</a>");
} else if (scan_html(&source[t->start])) {
print_token(t);
} else {
if (scratch->extensions & EXT_CRITIC_ACCEPT) {
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
} else {
- print("<ins>");
+ print_const("<ins>");
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
- print("</ins>");
+ print_const("</ins>");
}
} else {
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
if (scratch->extensions & EXT_CRITIC_REJECT) {
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
} else {
- print("<del>");
+ print_const("<del>");
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
- print("</del>");
+ print_const("</del>");
}
} else {
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
if (scratch->extensions & EXT_CRITIC) {
t->child->type = TEXT_EMPTY;
t->child->mate->type = TEXT_EMPTY;
- print("<span class=\"critic comment\">");
+ print_const("<span class=\"critic comment\">");
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
- print("</span>");
+ print_const("</span>");
} else {
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
}
if (scratch->extensions & EXT_CRITIC) {
t->child->type = TEXT_EMPTY;
t->child->mate->type = TEXT_EMPTY;
- print("<mark>");
+ print_const("<mark>");
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
- print("</mark>");
+ print_const("</mark>");
} else {
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
}
break;
case CRITIC_SUB_DIV_A:
- print("~");
+ print_const("~");
break;
case CRITIC_SUB_DIV_B:
- print(">");
+ print_const(">");
break;
case PAIR_CRITIC_SUB_DEL:
if ((scratch->extensions & EXT_CRITIC) &&
} else if (scratch->extensions & EXT_CRITIC_REJECT) {
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
} else {
- print("<del>");
+ print_const("<del>");
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
- print("</del>");
+ print_const("</del>");
}
} else {
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
} else if (scratch->extensions & EXT_CRITIC_ACCEPT) {
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
} else {
- print("<ins>");
+ print_const("<ins>");
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
- print("</ins>");
+ print_const("</ins>");
}
} else {
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
break;
case PAREN_LEFT:
- print("(");
+ print_const("(");
break;
case PAREN_RIGHT:
- print(")");
+ print_const(")");
break;
case PIPE:
print_token(t);
break;
case QUOTE_SINGLE:
if ((t->mate == NULL) || (!(scratch->extensions & EXT_SMART)))
- print("'");
+ 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(""");
+ 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("''");
+ print_const("''");
else
print_localized(QUOTE_RIGHT_DOUBLE);
break;
print_token(t);
break;
case STRONG_START:
- print("<strong>");
+ print_const("<strong>");
break;
case STRONG_STOP:
- print("</strong>");
+ print_const("</strong>");
break;
case SUBSCRIPT:
if (t->mate) {
- (t->start < t->mate->start) ? (print("<sub>")) : (print("</sub>"));
+ (t->start < t->mate->start) ? (print_const("<sub>")) : (print_const("</sub>"));
} else if (t->len != 1) {
- print("<sub>");
+ print_const("<sub>");
mmd_export_token_html(out, source, t->child, offset, scratch);
- print("</sub>");
+ print_const("</sub>");
} else {
- print("~");
+ print_const("~");
}
break;
case SUPERSCRIPT:
if (t->mate) {
- (t->start < t->mate->start) ? (print("<sup>")) : (print("</sup>"));
+ (t->start < t->mate->start) ? (print_const("<sup>")) : (print_const("</sup>"));
} else if (t->len != 1) {
- print("<sup>");
+ print_const("<sup>");
mmd_export_token_html(out, source, t->child, offset, scratch);
- print("</sup>");
+ print_const("</sup>");
} else {
- print("^");
+ print_const("^");
}
break;
case TABLE_CELL:
if (scratch->in_table_header) {
- print("\t<th");
+ print_const("\t<th");
} else {
- print("\t<td");
+ print_const("\t<td");
}
switch (scratch->table_alignment[scratch->table_cell_count]) {
case 'l':
case 'L':
- print(" style=\"text-align:left;\"");
+ print_const(" style=\"text-align:left;\"");
break;
case 'r':
case 'R':
- print(" style=\"text-align:right;\"");
+ print_const(" style=\"text-align:right;\"");
break;
case 'c':
case 'C':
- print(" style=\"text-align:center;\"");
+ print_const(" style=\"text-align:center;\"");
break;
}
if (t->next && t->next->type == TABLE_DIVIDER) {
printf(" colspan=\"%d\"", t->next->len);
}
}
- print(">");
+ print_const(">");
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
if (scratch->in_table_header) {
- print("</th>\n");
+ print_const("</th>\n");
} else {
- print("</td>\n");
+ print_const("</td>\n");
}
if (t->next)
scratch->table_cell_count += t->next->len;
case TABLE_DIVIDER:
break;
case TABLE_ROW:
- print("<tr>\n");
+ print_const("<tr>\n");
scratch->table_cell_count = 0;
mmd_export_token_tree_html(out, source, t->child, offset, scratch);
- print("</tr>\n");
+ print_const("</tr>\n");
break;
case TEXT_LINEBREAK:
if (t->next) {
- print("<br />\n");
+ print_const("<br />\n");
scratch->padded = 1;
}
break;
print_token(t);
break;
case AMPERSAND:
- print("&");
+ print_const("&");
break;
case AMPERSAND_LONG:
- print("&amp;");
+ print_const("&amp;");
break;
case ANGLE_RIGHT:
- print(">");
+ print_const(">");
break;
case ANGLE_LEFT:
- print("<");
+ print_const("<");
break;
case ESCAPED_CHARACTER:
- print("\\");
+ print_const("\\");
mmd_print_char_html(out, source[t->start + 1], false);
break;
case QUOTE_DOUBLE:
- print(""");
+ print_const(""");
break;
case CODE_FENCE:
if (t->next)
void mmd_start_complete_html(DString * out, const char * source, scratch_pad * scratch) {
- print("<!DOCTYPE html>\n<html>\n<head>\n\t<meta charset=\"utf-8\"/>\n");
+ print_const("<!DOCTYPE html>\n<html>\n<head>\n\t<meta charset=\"utf-8\"/>\n");
// Iterate over metadata keys
meta * m;
if (strcmp(m->key, "baseheaderlevel") == 0) {
} else if (strcmp(m->key, "bibtex") == 0) {
} else if (strcmp(m->key, "css") == 0) {
- print("\t<link type=\"text/css\" rel=\"stylesheet\" href=\"");
+ print_const("\t<link type=\"text/css\" rel=\"stylesheet\" href=\"");
mmd_print_string_html(out, m->value, false);
- print("\"/>\n");
+ print_const("\"/>\n");
} else if (strcmp(m->key, "htmlfooter") == 0) {
} else if (strcmp(m->key, "htmlheader") == 0) {
print(m->value);
} else if (strcmp(m->key, "mmdheader") == 0) {
} else if (strcmp(m->key, "quoteslanguage") == 0) {
} else if (strcmp(m->key, "title") == 0) {
- print("\t<title>");
+ print_const("\t<title>");
mmd_print_string_html(out, m->value, false);
- print("</title>\n");
+ print_const("</title>\n");
} else if (strcmp(m->key, "transcludebase") == 0) {
} else if (strcmp(m->key, "xhtmlheader") == 0) {
print(m->value);
print_char('\n');
} else if (strcmp(m->key, "xhtmlheaderlevel") == 0) {
} else {
- print("\t<meta name=\"");
+ print_const("\t<meta name=\"");
mmd_print_string_html(out, m->key, false);
- print("\" content=\"");
+ print_const("\" content=\"");
mmd_print_string_html(out, m->value, false);
- print("\"/>\n");
+ print_const("\"/>\n");
}
}
- print("</head>\n<body>\n\n");
+ print_const("</head>\n<body>\n\n");
}
void mmd_end_complete_html(DString * out, const char * source, scratch_pad * scratch) {
- print("\n\n</body>\n</html>\n");
+ print_const("\n\n</body>\n</html>\n");
}
token * content;
pad(out, 2, scratch);
- print("<div class=\"footnotes\">\n<hr />\n<ol>");
+ print_const("<div class=\"footnotes\">\n<hr />\n<ol>");
scratch->padded = 0;
for (int i = 0; i < scratch->used_footnotes->size; ++i)
}
pad(out, 2, scratch);
- print("</ol>\n</div>");
+ print_const("</ol>\n</div>");
scratch->padded = 0;
scratch->footnote_being_printed = 0;
}
token * content;
pad(out, 2, scratch);
- print("<div class=\"citations\">\n<hr />\n<ol>");
+ print_const("<div class=\"citations\">\n<hr />\n<ol>");
scratch->padded = 0;
for (int i = 0; i < scratch->used_citations->size; ++i)
}
pad(out, 2, scratch);
- print("</ol>\n</div>");
+ print_const("</ol>\n</div>");
scratch->padded = 0;
scratch->citation_being_printed = 0;
}
#include "scanners.h"
#define print(x) d_string_append(out, x)
+#define print_const(x) d_string_append_c_array(out, x, sizeof(x) - 1)
#define print_char(x) d_string_append_c(out, x)
#define printf(...) d_string_append_printf(out, __VA_ARGS__)
#define print_token(t) d_string_append_c_array(out, &(source[t->start]), t->len)
void mmd_print_char_latex(DString * out, char c) {
switch (c) {
case '\\':
- print("\\textbackslash{}");
+ print_const("\\textbackslash{}");
break;
case '~':
- print("\\ensuremath{\\sim}");
+ print_const("\\ensuremath{\\sim}");
break;
case '/':
- print("\\slash ");
+ print_const("\\slash ");
break;
case '^':
- print("\\^{}");
+ print_const("\\^{}");
break;
case '<':
case '>':
print_char('$');
break;
case '|':
- print("\\textbar{}");
+ print_const("\\textbar{}");
break;
case '#':
case '{':
void mmd_print_localized_char_latex(DString * out, unsigned short type, scratch_pad * scratch) {
switch (type) {
case DASH_N:
- print("--");
+ print_const("--");
break;
case DASH_M:
- print("---");
+ print_const("---");
break;
case ELLIPSIS:
- print("{\\ldots}");
+ print_const("{\\ldots}");
break;
case APOSTROPHE:
- print("'");
+ print_const("'");
break;
case QUOTE_LEFT_SINGLE:
switch (scratch->quotes_lang) {
case SWEDISH:
- print("'");
+ print_const("'");
break;
case FRENCH:
- print("'");
+ print_const("'");
break;
case GERMAN:
- print("‚");
+ print_const("‚");
break;
case GERMANGUILL:
- print("›");
+ print_const("›");
break;
default:
- print("`");
+ print_const("`");
}
break;
case QUOTE_RIGHT_SINGLE:
switch (scratch->quotes_lang) {
case GERMAN:
- print("`");
+ print_const("`");
break;
case GERMANGUILL:
- print("‹");
+ print_const("‹");
break;
default:
- print("'");
+ print_const("'");
}
break;
case QUOTE_LEFT_DOUBLE:
switch (scratch->quotes_lang) {
case DUTCH:
case GERMAN:
- print("„");
+ print_const("„");
break;
case GERMANGUILL:
- print("»");
+ print_const("»");
break;
case FRENCH:
- print("«");
+ print_const("«");
break;
case SWEDISH:
- print("''");
+ print_const("''");
break;
default:
- print("``");
+ print_const("``");
}
break;
case QUOTE_RIGHT_DOUBLE:
switch (scratch->quotes_lang) {
case GERMAN:
- print("``");
+ print_const("``");
break;
case GERMANGUILL:
- print("«");
+ print_const("«");
break;
case FRENCH:
- print("»");
+ print_const("»");
break;
case SWEDISH:
case DUTCH:
default:
- print("''");
+ print_const("''");
}
break;
}
printf("\\autoref{%s}", &(link->url)[1]);
} else {
mmd_export_token_tree_latex(out, source, text->child, scratch);
- print(" (");
+ print_const(" (");
printf("\\autoref{%s}", &(link->url)[1]);
- print(")");
+ print_const(")");
}
free(temp_char);
printf("\\href{%s}", link->url);
}
} else
- print("\\href{}");
+ print_const("\\href{}");
- print("{");
+ print_const("{");
// If we're printing contents of bracket as text, then ensure we include it all
if (text && text->child && text->child->len > 1) {
mmd_export_token_tree_latex(out, source, text->child, scratch);
- print("}");
+ print_const("}");
// Reprint as footnote for printed copies
printf("\\footnote{\\href{%s}{", link->url);
mmd_print_string_latex(out, link->url);
- print("}}");
+ print_const("}}");
}
is_figure = false;
if (is_figure) {
- print("\\begin{figure}[htbp]\n\\centering\n");
+ print_const("\\begin{figure}[htbp]\n\\centering\n");
scratch->close_para = false;
}
a = a->next;
}
- print("\\includegraphics[");
+ print_const("\\includegraphics[");
if (height || width) {
if (!height || !width) {
// One not specified, preserve aspect
- print("keepaspectratio,");
+ print_const("keepaspectratio,");
}
if (width) {
free(width);
} else {
// Default width
- print("width=\\textwidth,");
+ print_const("width=\\textwidth,");
}
if (height) {
free(height);
} else {
// Default height
- print("height=0.75\\textheight");
+ print_const("height=0.75\\textheight");
}
} else {
// no dimensions specified, use sensible defaults
- print("keepaspectratio,width=\\textwidth,height=0.75\\textheight");
+ print_const("keepaspectratio,width=\\textwidth,height=0.75\\textheight");
}
if (link->url)
printf("]{%s}", link->url);
else
- print("]{}");
+ print_const("]{}");
if (is_figure) {
- print("\n");
+ print_const("\n");
if (text) {
- print("\\caption{");
+ print_const("\\caption{");
mmd_export_token_tree_latex(out, source, text->child, scratch);
- print("}\n");
+ print_const("}\n");
}
if (link->label) {
// \todo: Need to decide on approach to id's
free(label);
}
- print("\\end{figure}");
+ print_const("\\end{figure}");
}
}
switch (t->type) {
case AMPERSAND:
case AMPERSAND_LONG:
- print("\\&");
+ print_const("\\&");
break;
case ANGLE_LEFT:
- print("$<$");
+ print_const("$<$");
break;
case ANGLE_RIGHT:
- print("$>$");
+ print_const("$>$");
break;
case APOSTROPHE:
if (!(scratch->extensions & EXT_SMART)) {
break;
case BLOCK_BLOCKQUOTE:
pad(out, 2, scratch);
- print("\\begin{quote}\n");
+ print_const("\\begin{quote}\n");
scratch->padded = 2;
mmd_export_token_tree_latex(out, source, t->child, scratch);
pad(out, 1, scratch);
- print("\\end{quote}");
+ print_const("\\end{quote}");
scratch->padded = 0;
break;
case BLOCK_CODE_FENCED:
if (temp_char) {
printf("\\begin{lstlisting}[language=%s]\n", temp_char);
} else {
- print("\\begin{verbatim}\n");
+ print_const("\\begin{verbatim}\n");
}
mmd_export_token_tree_latex_raw(out, source, t->child->next, scratch);
if (temp_char) {
- print("\\end{lstlisting}");
+ print_const("\\end{lstlisting}");
free(temp_char);
} else {
- print("\\end{verbatim}");
+ print_const("\\end{verbatim}");
}
scratch->padded = 0;
break;
case BLOCK_CODE_INDENTED:
pad(out, 2, scratch);
- print("\\begin{verbatim}\n");
+ print_const("\\begin{verbatim}\n");
mmd_export_token_tree_latex_raw(out, source, t->child, scratch);
- print("\\end{verbatim}");
+ print_const("\\end{verbatim}");
scratch->padded = 0;
break;
case BLOCK_DEFINITION:
// lemon's LALR(1) parser can't properly handle this (to my understanding).
if (!(t->prev && (t->prev->type == BLOCK_DEFLIST)))
- print("\\begin{description}\n");
+ print_const("\\begin{description}\n");
scratch->padded = 2;
pad(out, 1, scratch);
if (!(t->next && (t->next->type == BLOCK_DEFLIST)))
- print("\\end{description}\n");
+ print_const("\\end{description}\n");
scratch->padded = 1;
break;
switch (temp_short + scratch->base_header_level - 1) {
case 1:
- print("\\part{");
+ print_const("\\part{");
break;
case 2:
- print("\\chapter{");
+ print_const("\\chapter{");
break;
case 3:
- print("\\section{");
+ print_const("\\section{");
break;
case 4:
- print("\\subsection{");
+ print_const("\\subsection{");
break;
case 5:
- print("\\subsubsection{");
+ print_const("\\subsubsection{");
break;
case 6:
- print("\\paragraph{");
+ print_const("\\paragraph{");
break;
case 7:
- print("\\subparagraph{");
+ print_const("\\subparagraph{");
break;
}
mmd_export_token_tree_latex(out, source, t->child, scratch);
if (scratch->extensions & EXT_NO_LABELS) {
- print("}");
+ print_const("}");
} else {
temp_token = manual_label_from_header(t, source);
if (temp_token) {
break;
case BLOCK_HR:
pad(out, 2, scratch);
- print("\\begin{center}\\rule{3in}{0.4pt}\\end{center}");
+ print_const("\\begin{center}\\rule{3in}{0.4pt}\\end{center}");
scratch->padded = 0;
break;
case BLOCK_HTML:
break;
}
pad(out, 2, scratch);
- print("\\begin{itemize}");
+ print_const("\\begin{itemize}");
scratch->padded = 1;
mmd_export_token_tree_latex(out, source, t->child, scratch);
pad(out, 2, scratch);
- print("\\end{itemize}");
+ print_const("\\end{itemize}");
scratch->padded = 0;
scratch->list_is_tight = temp_short;
break;
break;
}
pad(out, 2, scratch);
- print("\\begin{enumerate}");
+ print_const("\\begin{enumerate}");
scratch->padded = 1;
mmd_export_token_tree_latex(out, source, t->child, scratch);
pad(out, 2, scratch);
- print("\\end{enumerate}");
+ print_const("\\end{enumerate}");
scratch->padded = 0;
scratch->list_is_tight = temp_short;
break;
case BLOCK_LIST_ITEM:
pad(out, 2, scratch);
- print("\\item ");
+ print_const("\\item ");
scratch->padded = 2;
mmd_export_token_tree_latex(out, source, t->child, scratch);
scratch->padded = 0;
break;
case BLOCK_LIST_ITEM_TIGHT:
pad(out, 2, scratch);
- print("\\item ");
+ print_const("\\item ");
scratch->padded = 2;
mmd_export_token_tree_latex(out, source, t->child, scratch);
scratch->padded = 0;
case BLOCK_TABLE:
pad(out, 2, scratch);
- print("\\begin{table}[htbp]\n");
+ print_const("\\begin{table}[htbp]\n");
- print("\\begin{minipage}{\\linewidth}\n\\setlength{\\tymax}{0.5\\linewidth}\n\\centering\n\\small\n");
+ print_const("\\begin{minipage}{\\linewidth}\n\\setlength{\\tymax}{0.5\\linewidth}\n\\centering\n\\small\n");
// Are we followed by a caption?
if (table_has_caption(t)) {
t->next->child->child->type = TEXT_EMPTY;
t->next->child->child->mate->type = TEXT_EMPTY;
- print("\\caption{");
+ print_const("\\caption{");
mmd_export_token_tree_latex(out, source, t->next->child->child, scratch);
- print("}\n");
+ print_const("}\n");
printf("\\label{%s}\n", temp_char);
free(temp_char);
mmd_export_token_tree_latex(out, source, t->child, scratch);
pad(out, 1, scratch);
- print("\n\\end{tabulary}\n\\end{minipage}");
+ print_const("\n\\end{tabulary}\n\\end{minipage}");
- print("\n\\end{table}");
+ print_const("\n\\end{table}");
scratch->skip_token = temp_short;
scratch->padded = 0;
case BLOCK_TABLE_HEADER:
pad(out, 2, scratch);
- print("\\begin{tabulary}{\\textwidth}{@{}");
+ print_const("\\begin{tabulary}{\\textwidth}{@{}");
for (int i = 0; i < scratch->table_column_count; ++i)
{
}
}
- print("@{}} \\toprule\n");
+ print_const("@{}} \\toprule\n");
scratch->in_table_header = 1;
mmd_export_token_tree_latex(out, source, t->child, scratch);
scratch->in_table_header = 0;
- print("\\midrule\n");
+ print_const("\\midrule\n");
scratch->padded = 1;
break;
pad(out, 2, scratch);
scratch->padded = 2;
mmd_export_token_tree_latex(out, source, t->child, scratch);
- print("\\bottomrule");
+ print_const("\\bottomrule");
scratch->padded = 0;
break;
case BLOCK_TERM:
pad(out, 2, scratch);
- print("\\item[");
+ print_const("\\item[");
mmd_export_token_tree_latex(out, source, t->child, scratch);
- print("]");
+ print_const("]");
scratch->padded = 0;
break;
case BLOCK_TOC:
if (temp_short == 0) {
// First item
pad(out, 2, scratch);
- print("\\begin{itemize}");
+ print_const("\\begin{itemize}");
scratch->padded = 0;
temp_short = temp_token->type;
temp_short2 = temp_short;
} else if (temp_token->type == temp_short2 + 1) {
// Indent
pad(out, 2, scratch);
- print("\\begin{itemize}");
+ print_const("\\begin{itemize}");
scratch->padded = 0;
temp_short2++;
} else if (temp_token->type < temp_short2) {
while (temp_short2 > temp_token->type) {
if (temp_short2 > temp_short) {
pad(out, 2, scratch);
- print("\\end{itemize}");
+ print_const("\\end{itemize}");
scratch->padded = 0;
} else
temp_short = temp_short2 - 1;
temp_char = label_from_header(source, temp_token);
pad(out, 2, scratch);
- print("\\item ");
+ print_const("\\item ");
mmd_export_token_tree_latex(out, source, temp_token->child, scratch);
printf("(\\autoref{%s})", temp_char);
scratch->padded = 0;
while (temp_short2 > (temp_short)) {
pad(out, 2, scratch);
- print("\\end{itemize}");
+ print_const("\\end{itemize}");
scratch->padded = 0;
temp_short2--;
}
if (temp_short) {
pad(out, 2, scratch);
- print("\\end{itemize}");
+ print_const("\\end{itemize}");
scratch->padded = 0;
}
scratch->padded = 0;
break;
case BRACE_DOUBLE_LEFT:
- print("\\{\\{");
+ print_const("\\{\\{");
break;
case BRACE_DOUBLE_RIGHT:
- print("\\}\\}");
+ print_const("\\}\\}");
break;
case BRACKET_LEFT:
- print("[");
+ print_const("[");
break;
case BRACKET_CITATION_LEFT:
- print("[#");
+ print_const("[#");
break;
case BRACKET_FOOTNOTE_LEFT:
- print("[^");
+ print_const("[^");
break;
case BRACKET_IMAGE_LEFT:
- print("![");
+ print_const("![");
break;
case BRACKET_VARIABLE_LEFT:
- print("[\%");
+ print_const("[\%");
break;
case BRACKET_RIGHT:
- print("]");
+ print_const("]");
break;
case CODE_FENCE:
break;
case COLON:
- print(":");
+ print_const(":");
break;
case DASH_M:
if (!(scratch->extensions & EXT_SMART)) {
}
break;
case EMPH_START:
- print("\\emph{");
+ print_const("\\emph{");
break;
case EMPH_STOP:
- print("}");
+ print_const("}");
break;
case EQUAL:
- print("=");
+ print_const("=");
break;
case ESCAPED_CHARACTER:
if (!(scratch->extensions & EXT_COMPATIBILITY) &&
(source[t->start + 1] == ' ')) {
- print("~");
+ print_const("~");
} else {
mmd_print_char_latex(out, source[t->start + 1]);
}
case MARKER_LIST_ENUMERATOR:
break;
case MATH_BRACKET_OPEN:
- print("\\[");
+ print_const("\\[");
break;
case MATH_BRACKET_CLOSE:
- print("\\]");
+ print_const("\\]");
break;
case MATH_DOLLAR_SINGLE:
if (t->mate)
- print("$");
+ print_const("$");
else
- print("\\$");
+ print_const("\\$");
break;
case MATH_DOLLAR_DOUBLE:
if (t->mate)
- print("$$");
+ print_const("$$");
else
- print("\\$\\$");
+ print_const("\\$\\$");
break;
case MATH_PAREN_OPEN:
- print("\\(");
+ print_const("\\(");
break;
case MATH_PAREN_CLOSE:
- print("\\)");
+ print_const("\\)");
break;
case NON_INDENT_SPACE:
print_char(' ');
if (temp_char) {
if (scan_email(temp_char)) {
- print("\\href{mailto:");
+ print_const("\\href{mailto:");
print(temp_char);
} else {
- print("\\href{");
+ print_const("\\href{");
print(temp_char);
}
- print("}{");
+ print_const("}{");
mmd_print_string_latex(out, temp_char);
- print("}");
+ print_const("}");
} else if (scan_html(&source[t->start])) {
// We ignore HTML blocks
if (scan_html_comment(&source[t->start])) {
}
t->child->type = TEXT_EMPTY;
t->child->mate->type = TEXT_EMPTY;
- print("\\texttt{");
+ print_const("\\texttt{");
mmd_export_token_tree_latex_tt(out, source, t->child, scratch);
- print("}");
+ print_const("}");
break;
case PAIR_BRACES:
mmd_export_token_tree_latex(out, source, t->child, scratch);
if (temp_char[0] == '\0') {
// No locator
if (temp_char2[strlen(temp_char2) - 1] == ';') {
- print("\\citet");
+ print_const("\\citet");
} else {
- print("~\\citep");
+ print_const("~\\citep");
}
} else {
// Locator present
if (scratch->extensions & EXT_CRITIC_ACCEPT) {
mmd_export_token_tree_latex(out, source, t->child, scratch);
} else {
- print("\\underline{");
+ print_const("\\underline{");
mmd_export_token_tree_latex(out, source, t->child, scratch);
- print("}");
+ print_const("}");
}
} else {
mmd_export_token_tree_latex(out, source, t->child, scratch);
if (scratch->extensions & EXT_CRITIC_REJECT) {
mmd_export_token_tree_latex(out, source, t->child, scratch);
} else {
- print("\\sout{");
+ print_const("\\sout{");
mmd_export_token_tree_latex(out, source, t->child, scratch);
- print("}");
+ print_const("}");
}
} else {
mmd_export_token_tree_latex(out, source, t->child, scratch);
if (scratch->extensions & EXT_CRITIC) {
t->child->type = TEXT_EMPTY;
t->child->mate->type = TEXT_EMPTY;
- print("\\cmnote{");
+ print_const("\\cmnote{");
mmd_export_token_tree_latex(out, source, t->child, scratch);
- print("}");
+ print_const("}");
} else {
mmd_export_token_tree_latex(out, source, t->child, scratch);
}
t->child->type = TEXT_EMPTY;
t->child->mate->type = TEXT_EMPTY;
// 'hl' requires 'soul' package
- print("\\hl{");
+ print_const("\\hl{");
mmd_export_token_tree_latex(out, source, t->child, scratch);
- print("}");
+ print_const("}");
} else {
mmd_export_token_tree_latex(out, source, t->child, scratch);
}
break;
case CRITIC_SUB_DIV_A:
- print("~");
+ print_const("~");
break;
case CRITIC_SUB_DIV_B:
- print(">");
+ print_const(">");
break;
case PAIR_CRITIC_SUB_DEL:
if ((scratch->extensions & EXT_CRITIC) &&
} else if (scratch->extensions & EXT_CRITIC_REJECT) {
mmd_export_token_tree_latex(out, source, t->child, scratch);
} else {
- print("\\sout{");
+ print_const("\\sout{");
mmd_export_token_tree_latex(out, source, t->child, scratch);
- print("}");
+ print_const("}");
}
} else {
mmd_export_token_tree_latex(out, source, t->child, scratch);
} else if (scratch->extensions & EXT_CRITIC_ACCEPT) {
mmd_export_token_tree_latex(out, source, t->child, scratch);
} else {
- print("\\underline{");
+ print_const("\\underline{");
mmd_export_token_tree_latex(out, source, t->child, scratch);
- print("}");
+ print_const("}");
}
} else {
mmd_export_token_tree_latex(out, source, t->child, scratch);
mmd_export_token_tree_latex(out, source, t->child, scratch);
break;
case PAREN_LEFT:
- print("(");
+ print_const("(");
break;
case PAREN_RIGHT:
- print(")");
+ print_const(")");
break;
case PIPE:
for (int i = 0; i < t->len; ++i)
{
- print("\\textbar{}");
+ print_const("\\textbar{}");
}
break;
case PLUS:
break;
case QUOTE_SINGLE:
if ((t->mate == NULL) || (!(scratch->extensions & EXT_SMART)))
- print("'");
+ 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(""");
+ 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("''");
+ print_const("''");
else
print_localized(QUOTE_RIGHT_DOUBLE);
break;
case SLASH:
- print("\\slash ");
+ print_const("\\slash ");
break;
case STAR:
print_token(t);
break;
case STRONG_START:
- print("\\textbf{");
+ print_const("\\textbf{");
break;
case STRONG_STOP:
- print("}");
+ print_const("}");
break;
case SUBSCRIPT:
if (t->mate) {
- (t->start < t->mate->start) ? (print("\\textsubscript{")) : (print("}"));
+ (t->start < t->mate->start) ? (print_const("\\textsubscript{")) : (print_const("}"));
} else if (t->len != 1) {
- print("\\textsubscript{");
+ print_const("\\textsubscript{");
mmd_export_token_latex(out, source, t->child, scratch);
- print("}");
+ print_const("}");
} else {
- print("\\ensuremath{\\sim}");
+ print_const("\\ensuremath{\\sim}");
}
break;
case SUPERSCRIPT:
if (t->mate) {
- (t->start < t->mate->start) ? (print("\\textsuperscript{")) : (print("}"));
+ (t->start < t->mate->start) ? (print_const("\\textsuperscript{")) : (print_const("}"));
} else if (t->len != 1) {
- print("\\textsuperscript{");
+ print_const("\\textsuperscript{");
mmd_export_token_latex(out, source, t->child, scratch);
- print("}");
+ print_const("}");
} else {
- print("\\^{}");
+ print_const("\\^{}");
}
break;
case TABLE_CELL:
switch (scratch->table_alignment[scratch->table_cell_count]) {
case 'l':
case 'L':
- print("l}{");
+ print_const("l}{");
break;
case 'r':
case 'R':
- print("r}{");
+ print_const("r}{");
break;
default:
- print("c}{");
+ print_const("c}{");
break;
}
}
if (t->next && t->next->type == TABLE_DIVIDER) {
if (t->next->len > 1)
- print("}");
+ print_const("}");
}
if (t->next && t->next->type == TABLE_DIVIDER) {
t = t->next;
if (t->next && t->next->type == TABLE_CELL) {
- print("&");
+ print_const("&");
scratch->table_cell_count += t->next->len;
}
} else
case TABLE_ROW:
scratch->table_cell_count = 0;
mmd_export_token_tree_latex(out, source, t->child, scratch);
- print("\\\\\n");
+ print_const("\\\\\n");
break;
case TEXT_BACKSLASH:
- print("\\textbackslash{}");
+ print_const("\\textbackslash{}");
break;
case TEXT_EMPTY:
break;
case TEXT_HASH:
- print("\\#");
+ print_const("\\#");
break;
case TEXT_LINEBREAK:
if (t->next) {
- print("\n");
+ print_const("\n");
scratch->padded = 1;
}
break;
print_char('\n');
break;
case TEXT_PERCENT:
- print("\\%");
+ print_const("\\%");
break;
case TEXT_BRACE_LEFT:
case TEXT_BRACE_RIGHT:
- print("\\");
+ print_const("\\");
case TEXT_NUMBER_POSS_LIST:
case TEXT_PERIOD:
case TEXT_PLAIN:
print_token(t);
break;
case UL:
- print("\\_");
+ print_const("\\_");
break;
default:
fprintf(stderr, "Unknown token type: %d\n", t->type);
switch (t->type) {
case ESCAPED_CHARACTER:
- print("\\");
+ print_const("\\");
print_char(source[t->start + 1]);
// mmd_print_char_latex(out, source[t->start + 1]);
break;
switch (t->type) {
case AMPERSAND:
case AMPERSAND_LONG:
- print("\\&");
+ print_const("\\&");
break;
case ANGLE_LEFT:
- print("$<$");
+ print_const("$<$");
break;
case ANGLE_RIGHT:
- print("$>$");
+ print_const("$>$");
break;
case DASH_N:
if (t->len == 1) {
- print("-");
+ print_const("-");
} else {
- print("-{}-");
+ print_const("-{}-");
}
break;
case DASH_M:
- print("-{}-{}-");
+ print_const("-{}-{}-");
break;
case ESCAPED_CHARACTER:
- print("\\textbackslash{}");
+ print_const("\\textbackslash{}");
mmd_print_char_latex(out, source[t->start + 1]);
break;
case CODE_FENCE:
case TEXT_EMPTY:
break;
case SLASH:
- print("\\slash ");
+ print_const("\\slash ");
break;
case TEXT_BACKSLASH:
- print("\\textbackslash{}");
+ print_const("\\textbackslash{}");
break;
case BRACE_DOUBLE_LEFT:
- print("\\{\\{");
+ print_const("\\{\\{");
break;
case BRACE_DOUBLE_RIGHT:
- print("\\}\\}");
+ print_const("\\}\\}");
break;
case TEXT_BRACE_LEFT:
- print("\\{");
+ print_const("\\{");
break;
case TEXT_BRACE_RIGHT:
- print("\\}");
+ print_const("\\}");
break;
case UL:
- print("\\_");
+ print_const("\\_");
break;
default:
if (t->child)
} else if (strcmp(m->key, "quoteslanguage") == 0) {
} else if ((strcmp(m->key, "title") == 0) ||
(strcmp(m->key, "latextitle") == 0)) {
- print("\\def\\mytitle{");
+ print_const("\\def\\mytitle{");
mmd_print_string_latex(out, m->value);
- print("}\n");
+ print_const("}\n");
} else if ((strcmp(m->key, "author") == 0) ||
(strcmp(m->key, "latexauthor") == 0)) {
- print("\\def\\myauthor{");
+ print_const("\\def\\myauthor{");
mmd_print_string_latex(out, m->value);
- print("}\n");
+ print_const("}\n");
} else if (strcmp(m->key, "date") == 0) {
- print("\\def\\mydate{");
+ print_const("\\def\\mydate{");
mmd_print_string_latex(out, m->value);
- print("}\n");
+ print_const("}\n");
} else if (strcmp(m->key, "copyright") == 0) {
- print("\\def\\mycopyright{");
+ print_const("\\def\\mycopyright{");
mmd_print_string_latex(out, m->value);
- print("}\n");
+ print_const("}\n");
} else if (strcmp(m->key, "bibtex") == 0) {
- print("\\def\\bibliocommand{\\bibliography{");
+ print_const("\\def\\bibliocommand{\\bibliography{");
mmd_print_string_latex(out, m->value);
- print("}}\n");
+ 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("\\def\\");
+ print_const("\\def\\");
mmd_print_string_latex(out, m->key);
- print("{");
+ print_const("{");
mmd_print_string_latex(out, m->value);
- print("}\n");
+ print_const("}\n");
}
}
}
}
- print("\\end{document}");
+ print_const("\\end{document}");
scratch->padded = 0;
}
token * content;
pad(out, 2, scratch);
- print("\\begin{thebibliography}{0}");
+ print_const("\\begin{thebibliography}{0}");
scratch->padded = 0;
for (int i = 0; i < scratch->used_citations->size; ++i)
}
pad(out, 1, scratch);
- print("\\end{thebibliography}");
+ print_const("\\end{thebibliography}");
scratch->padded = 0;
scratch->citation_being_printed = 0;
}
#include "memoir.h"
#define print(x) d_string_append(out, x)
+#define print_const(x) d_string_append_c_array(out, x, sizeof(x) - 1)
#define print_char(x) d_string_append_c(out, x)
#define printf(...) d_string_append_printf(out, __VA_ARGS__)
#define print_token(t) d_string_append_c_array(out, &(source[t->start]), t->len)
if (temp_char) {
printf("\\begin{adjustwidth}{2.5em}{2.5em}\n\\begin{lstlisting}[language=%s]\n", temp_char);
} else {
- print("\\begin{adjustwidth}{2.5em}{2.5em}\n\\begin{verbatim}\n");
+ print_const("\\begin{adjustwidth}{2.5em}{2.5em}\n\\begin{verbatim}\n");
}
mmd_export_token_tree_latex_raw(out, source, t->child->next, scratch);
if (temp_char) {
- print("\\end{lstlisting}\n\\end{adjustwidth}");
+ print_const("\\end{lstlisting}\n\\end{adjustwidth}");
free(temp_char);
} else {
- print("\\end{verbatim}\n\\end{adjustwidth}");
+ print_const("\\end{verbatim}\n\\end{adjustwidth}");
}
scratch->padded = 0;
break;
case BLOCK_CODE_INDENTED:
pad(out, 2, scratch);
- print("\\begin{adjustwidth}{2.5em}{2.5em}\\begin{verbatim}\n");
+ print_const("\\begin{adjustwidth}{2.5em}{2.5em}\\begin{verbatim}\n");
mmd_export_token_tree_latex_raw(out, source, t->child, scratch);
- print("\\end{verbatim}\n\\end{adjustwidth}");
+ print_const("\\end{verbatim}\n\\end{adjustwidth}");
scratch->padded = 0;
break;
default:
/// Parse part of the string into a token tree
token * mmd_engine_parse_substring(mmd_engine * e, size_t byte_start, size_t byte_len) {
-#ifdef kUseObjectPool
- // Ensure token pool is available and ready
- token_pool_init();
-#endif
// Reset definition stack
e->definition_stack->size = 0;
if (e->root)
token_tree_free(e->root);
-#ifdef kUseObjectPool
- // Ensure token pool is available and ready
- token_pool_init();
-#endif
-
// Tokenize the string (up until first empty line)
token * doc = mmd_tokenize_string(e, &e->dstr->str[0], e->dstr->currentStringLength, true);
/// strndup not available on all platforms
static char * my_strndup(const char * source, size_t n) {
- size_t len = strlen(source);
+ size_t len = 0;
char * result;
+ const char * test = source;
- if (n < len)
- len = n;
+ // strlen is too slow is strlen(source) >> n
+ for (len = 0; len < n; ++len)
+ {
+ if (test == '\0')
+ break;
+
+ test++;
+ }
result = malloc(len + 1);
/// strndup not available on all platforms
static char * my_strndup(const char * source, size_t n) {
- size_t len = strlen(source);
+ size_t len = 0;
char * result;
+ const char * test = source;
- if (n < len)
- len = n;
+ // strlen is too slow is strlen(source) >> n
+ for (len = 0; len < n; ++len)
+ {
+ if (test == '\0')
+ break;
+
+ test++;
+ }
result = malloc(len + 1);