Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions html.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void print_html_node(GString *out, node *n, scratch_pad *scratch) {
/* fprintf(stderr, "str: '%s'\n", n->str); */
print_html_string(out,n->str, scratch);
break;
case ABBRPLURAL:
case ABBR:
if (strlen(n->children->str) == 0) {
g_string_append_printf(out, "<abbr>");
Expand Down Expand Up @@ -139,7 +140,7 @@ void print_html_node(GString *out, node *n, scratch_pad *scratch) {
case VERBATIMFENCE:
pad(out, 2, scratch);
if ((n->children != NULL) && (n->children->key == VERBATIMTYPE)) {
trim_trailing_whitespace(n->children->str);
trim_trailing_whitespace_in_node_str(n->children);
if (strlen(n->children->str) > 0)
g_string_append_printf(out, "<pre><code class=\"%s\">", n->children->str);
else
Expand Down Expand Up @@ -244,11 +245,11 @@ void print_html_node(GString *out, node *n, scratch_pad *scratch) {
print_html_node(out, n->children, scratch);
g_string_append_printf(out, "\"/>\n");
} else if (strcmp(n->str, "xhtmlheader") == 0) {
trim_trailing_whitespace(n->children->str);
trim_trailing_whitespace_in_node_str(n->children);
print_raw_node(out, n->children);
g_string_append_printf(out, "\n");
} else if (strcmp(n->str, "htmlheader") == 0) {
trim_trailing_whitespace(n->children->str);
trim_trailing_whitespace_in_node_str(n->children);
print_raw_node(out, n->children);
g_string_append_printf(out, "\n");
} else if (strcmp(n->str, "mmdfooter") == 0) {
Expand All @@ -261,7 +262,7 @@ void print_html_node(GString *out, node *n, scratch_pad *scratch) {
}
break;
case METAVALUE:
trim_trailing_whitespace(n->str);
trim_trailing_whitespace_in_node_str(n);
print_html_string(out,n->str, scratch);
break;
case FOOTER:
Expand Down
83 changes: 65 additions & 18 deletions latex.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,33 @@ void print_latex_node(GString *out, node *n, scratch_pad *scratch) {
case ABBREVIATION:
/* We combine the short and full names, since stripping non-ascii characters may result
in a conflict otherwise. This at least makes it less likely. */
width = ascii_label_from_node(n->children);
temp = ascii_label_from_string(n->str);
g_string_append_printf(out, "\\newacro{%s%s}[",width,temp);
print_latex_node_tree(out, n->children, scratch);
g_string_append_printf(out, "]{");
trim_trailing_whitespace(n->str);
temp_str = g_string_new("");

if(LATEX_ACRONYM_LABEL_STYLE_ABBR == (scratch->latex_acronym_config&LATEX_ACRONYM_LABEL_STYLE_MASK)) {
print_raw_node(temp_str, n->children);
} else {
g_string_append(temp_str, ascii_label_from_node(n->children));
g_string_append(temp_str, ascii_label_from_string(n->str));
}

switch(scratch->latex_acronym_config&LATEX_ACRONYM_PACKAGE_MASK) {
case LATEX_ACRONYM_PACKAGE_GLOSSARIES:
g_string_append_printf(out, "\\newacronym{%s}{",temp_str->str);
print_latex_node_tree(out, n->children, scratch);
g_string_append_printf(out, "}{");
break;
case LATEX_ACRONYM_PACKAGE_ACRONYM:
default:
g_string_append_printf(out, "\\newacro{%s}[",temp_str->str);
print_latex_node_tree(out, n->children, scratch);
g_string_append_printf(out, "]{");
break;
}
trim_trailing_whitespace_in_node_str(n);
print_latex_string(out, n->str, scratch);
g_string_append_printf(out, "}\n");
free(temp);
free(width);

g_string_free(temp_str, FALSE);
break;
case ABBRSTART:
/* Strip out nodes that are being replaced with the abbreviation */
Expand All @@ -122,13 +139,29 @@ void print_latex_node(GString *out, node *n, scratch_pad *scratch) {
n->next = temp_node->next;
temp_node->next = NULL;
free_node(temp_node);
case ABBRPLURAL:
case ABBR:
/* In either case, now we call on the abbreviation */
width = ascii_label_from_node(n->children->children);
temp = ascii_label_from_string(n->children->str);
g_string_append_printf(out, "\\ac{%s%s}", width, temp);
free(temp);
free(width);
temp_str = g_string_new("");

if(LATEX_ACRONYM_LABEL_STYLE_ABBR == (scratch->latex_acronym_config&LATEX_ACRONYM_LABEL_STYLE_MASK)) {
print_raw_node(temp_str, n->children->children);
} else {
g_string_append(temp_str, ascii_label_from_node(n->children->children));
g_string_append(temp_str, ascii_label_from_string(n->children->str));
}

switch(scratch->latex_acronym_config&LATEX_ACRONYM_PACKAGE_MASK) {
case LATEX_ACRONYM_PACKAGE_GLOSSARIES:
g_string_append_printf(out, "\\gls%s{%s}", (n->key == ABBRPLURAL) ? "pl" : "", temp_str->str);
break;
case LATEX_ACRONYM_PACKAGE_ACRONYM:
default:
g_string_append_printf(out, "\\ac%s{%s}", (n->key == ABBRPLURAL) ? "p" : "", temp_str->str);
break;
}

g_string_free(temp_str, FALSE);
break;
case ABBRSTOP:
break;
Expand Down Expand Up @@ -165,7 +198,7 @@ void print_latex_node(GString *out, node *n, scratch_pad *scratch) {
case VERBATIMFENCE:
pad(out, 2, scratch);
if ((n->children != NULL) && (n->children->key == VERBATIMTYPE)) {
trim_trailing_whitespace(n->children->str);
trim_trailing_whitespace_in_node_str(n->children);
if (strlen(n->children->str) > 0) {
g_string_append_printf(out, "\\begin{lstlisting}[language=%s]\n%s\\end{lstlisting}", n->children->str,n->str);
scratch->padded = 0;
Expand Down Expand Up @@ -264,14 +297,28 @@ void print_latex_node(GString *out, node *n, scratch_pad *scratch) {
} else if (strcmp(n->str, "mmdheader") == 0) {
} else if (strcmp(n->str, "lang") == 0) {
} else if (strcmp(n->str, "latexinput") == 0) {
trim_trailing_whitespace(n->children->str);
trim_trailing_whitespace_in_node_str(n->children);
g_string_append_printf(out, "\\input{%s}\n", n->children->str);
} else if (strcmp(n->str, "latexfooter") == 0) {
trim_trailing_whitespace(n->children->str);
trim_trailing_whitespace_in_node_str(n->children);
scratch->latex_footer = strdup(n->children->str);
} else if (strcmp(n->str, "bibtex") == 0) {
trim_trailing_whitespace(n->children->str);
trim_trailing_whitespace_in_node_str(n->children);
g_string_append_printf(out, "\\def\\bibliocommand{\\bibliography{%s}}\n",n->children->str);
} else if (strcmp(n->str, "latexacronympackage") == 0) {
temp = label_from_node_tree(n->children);
if(strcmp(temp, "acronym") == 0) {
scratch->latex_acronym_config = (scratch->latex_acronym_config&LATEX_ACRONYM_LABEL_STYLE_MASK)|LATEX_ACRONYM_PACKAGE_ACRONYM;
} else if(strcmp(temp, "glossaries") == 0) {
scratch->latex_acronym_config = (scratch->latex_acronym_config&LATEX_ACRONYM_LABEL_STYLE_MASK)|LATEX_ACRONYM_PACKAGE_GLOSSARIES;
}
} else if (strcmp(n->str, "latexacronymlabelstyle") == 0) {
temp = label_from_node_tree(n->children);
if(strcmp(temp, "full") == 0) {
scratch->latex_acronym_config = (scratch->latex_acronym_config&LATEX_ACRONYM_PACKAGE_MASK)|LATEX_ACRONYM_LABEL_STYLE_FULL;
} else if(strncmp(temp, "abbreviation", sizeof("abbr")-1) == 0) {
scratch->latex_acronym_config = (scratch->latex_acronym_config&LATEX_ACRONYM_PACKAGE_MASK)|LATEX_ACRONYM_LABEL_STYLE_ABBR;
}
} else {
g_string_append_printf(out, "\\def\\");
print_latex_string(out, n->str, scratch);
Expand All @@ -281,7 +328,7 @@ void print_latex_node(GString *out, node *n, scratch_pad *scratch) {
}
break;
case METAVALUE:
trim_trailing_whitespace(n->str);
trim_trailing_whitespace_in_node_str(n);
print_latex_string(out,n->str, scratch);
break;
case FOOTER:
Expand Down
14 changes: 14 additions & 0 deletions libMultiMarkdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,31 @@ enum keys {
VARIABLE,
ABBREVIATION,
ABBR,
ABBRPLURAL,
ABBRSTART,
ABBRSTOP,
TOC,
KEY_COUNTER /* This *MUST* be the last item in the list */
};

// The 'correct' data type, i.e., size_t, appears to be unnecessarily big for a
// node; even an unsigned char might turn out to be sufficient
#ifdef NODE_LEN_SIZE_T
typedef size_t NODE_LEN;
#elif NODE_LEN_UINT
typedef unsigned int NODE_LEN;
#else
typedef unsigned short int NODE_LEN;
#endif

/* This is the element used in the resulting parse tree */
// the len element is added in order to prevent iterating
// The string (e.g., strdup, string trimming) and helps ultimately comparing
// acronyms much faster.
struct node {
short key; /* what type of element are we? */
char *str; /* relevant string from source for element */
NODE_LEN len; // the length of the string
struct link_data *link_data; /* store link info when relevant */
struct node *children; /* child elements */
struct node *next; /* next element */
Expand Down
3 changes: 2 additions & 1 deletion lyx.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ void print_lyx_node(GString *out, node *n, scratch_pad *scratch, bool no_newline
n->next = temp_node->next;
temp_node->next = NULL;
free_node(temp_node);
case ABBRPLURAL:
case ABBR:
/* In either case, now we call on the abbreviation */
// width = ascii_label_from_node(n->children->children);
Expand Down Expand Up @@ -824,7 +825,7 @@ void print_lyx_node(GString *out, node *n, scratch_pad *scratch, bool no_newline
g_string_append(out,"\\begin_layout Standard\n");
g_string_append(out,"\\begin_inset listings\n");
if ((n->children != NULL) && (n->children->key == VERBATIMTYPE)) {
trim_trailing_whitespace(n->children->str);
trim_trailing_whitespace_in_node_str(n->children);
if (strlen(n->children->str) > 0) {
// NOTE: the language must match the LyX (LaTex) languages (e.g: Perl, not perl)
g_string_append_printf(out, "lstparams \"basicstyle={\\footnotesize\\ttfamily},language=%s\"\n", n->children->str,n->str);
Expand Down
2 changes: 1 addition & 1 deletion memoir.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void print_memoir_node(GString *out, node *n, scratch_pad *scratch) {
case VERBATIMFENCE:
pad(out, 2, scratch);
if ((n->children != NULL) && (n->children->key == VERBATIMTYPE)) {
trim_trailing_whitespace(n->children->str);
trim_trailing_whitespace_in_node_str(n->children);
if (strlen(n->children->str) > 0) {
g_string_append_printf(out, "\\begin{adjustwidth}{2.5em}{2.5em}\n\\begin{lstlisting}[language=%s]\n", n->children->str);
print_raw_node(out, n);
Expand Down
3 changes: 2 additions & 1 deletion odf.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ void print_odf_node(GString *out, node *n, scratch_pad *scratch) {
print_odf_node_tree(out,n->children,scratch);
break;
case STR:
case ABBRPLURAL:
case ABBR:
case ABBRSTART:
case ABBRSTOP:
Expand Down Expand Up @@ -270,7 +271,7 @@ void print_odf_node(GString *out, node *n, scratch_pad *scratch) {
free(temp);
break;
case METAVALUE:
trim_trailing_whitespace(n->str);
trim_trailing_whitespace_in_node_str(n);
print_odf_string(out,n->str);
break;
case FOOTER:
Expand Down
2 changes: 1 addition & 1 deletion opml.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void print_opml_node(GString *out, node *n, scratch_pad *scratch) {
g_string_append_printf(out, "<outline text=\"");
print_opml_string(out, n->str);
g_string_append_printf(out, "\" _note=\"");
trim_trailing_newlines(n->children->str);
trim_trailing_newlines_in_node_str(n->children);
print_opml_string(out, n->children->str);
g_string_append_printf(out, "\"/>");
break;
Expand Down
Loading