Пример #1
0
/* print_memoir_node -- convert given node to LaTeX and append */
void print_memoir_node(GString *out, node *n, scratch_pad *scratch) {

	/* If we are forcing a complete document, and METADATA isn't the first thing,
		we need to close <head> */
	if ((scratch->extensions & EXT_COMPLETE)
		&& !(scratch->extensions & EXT_HEAD_CLOSED) && 
		!((n->key == FOOTER) || (n->key == METADATA))) {
			pad(out, 2, scratch);
			scratch->extensions = scratch->extensions | EXT_HEAD_CLOSED;
		}
	switch (n->key) {
		case VERBATIM:
		case VERBATIMFENCE:
			pad(out, 2, scratch);
			if ((n->children != NULL) && (n->children->key == VERBATIMTYPE)) {
				trim_trailing_whitespace(n->children->str);
				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);
					g_string_append_printf(out, "\n\\end{lstlisting}\n\\end{adjustwidth}");					
					scratch->padded = 0;
					break;
				}
			}
			g_string_append_printf(out, "\\begin{adjustwidth}{2.5em}{2.5em}\n\\begin{verbatim}\n\n");
			print_raw_node(out, n);
			g_string_append_printf(out, "\n\\end{verbatim}\n\\end{adjustwidth}");
			scratch->padded = 0;
			break;
		case HEADINGSECTION:
			print_memoir_node_tree(out, n->children, scratch);
			break;
		case DEFLIST:
			pad(out, 2, scratch);
			g_string_append_printf(out, "\\begin{description}");
			scratch->padded = 0;
			print_memoir_node_tree(out, n->children, scratch);
			pad(out, 1, scratch);
			g_string_append_printf(out, "\\end{description}");
			scratch->padded = 0;
			break;
		case DEFINITION:
			pad(out, 2, scratch);
			scratch->padded = 2;
			print_memoir_node_tree(out, n->children, scratch);
			scratch->padded = 0;
			break;
		default:
			/* most things are not changed for memoir output */
			print_latex_node(out, n, scratch);
	}
}
Пример #2
0
/* export_node_tree -- given a tree, export as specified format */
char * export_node_tree(node *list, int format, unsigned long extensions) {
	char *output;
	char *temp;
	GString *out = g_string_new("");
	scratch_pad *scratch = mk_scratch_pad(extensions);
	scratch->result_tree = list;  /* Pointer to result tree to use later */

#ifdef DEBUG_ON
	fprintf(stderr, "export_node_tree\n");
#endif

#ifdef DEBUG_ON
	fprintf(stderr, "extract_references\n");
#endif

	if ((format != OPML_FORMAT) &&
		(format != CRITIC_ACCEPT_FORMAT) &&
		(format != CRITIC_REJECT_FORMAT) &&
		(format != CRITIC_HTML_HIGHLIGHT_FORMAT)) {
			/* Find defined abbreviations */
			extract_abbreviations(list, scratch);
			/* Apply those abbreviations to source text */
			find_abbreviations(list, scratch);

			/* Parse for link, images, etc reference definitions */
			extract_references(list, scratch);
		}
	
	/* Change our desired format based on metadata */
	if (format == LATEX_FORMAT)
		format = find_latex_mode(format, list);
	
	switch (format) {
		case TEXT_FORMAT:
			print_text_node_tree(out, list, scratch);
			break;
		case HTML_FORMAT:
			if (scratch->extensions & EXT_COMPLETE) {
				temp = metavalue_for_key("lang", scratch->result_tree);
				if (temp != NULL) {
				    g_string_append_printf(out,
					"<!DOCTYPE html>\n<html lang=\"%s\">\n<head>\n\t<meta charset=\"utf-8\"/>\n",temp);
					free(temp);
				} else {
				    g_string_append_printf(out,
					"<!DOCTYPE html>\n<html>\n<head>\n\t<meta charset=\"utf-8\"/>\n");
				}
			}
#ifdef DEBUG_ON
	fprintf(stderr, "print_html output\n");
#endif
			print_html_node_tree(out, list, scratch);
#ifdef DEBUG_ON
	fprintf(stderr, "print html endnotes\n");
#endif
			print_html_endnotes(out, scratch);
#ifdef DEBUG_ON
	fprintf(stderr, "finished printing html endnotes\n");
#endif
			if (scratch->extensions & EXT_COMPLETE) {
				pad(out,2, scratch);
				g_string_append_printf(out, "</body>\n</html>");
			}
#ifdef DEBUG_ON
	fprintf(stderr, "closed HTML document\n");
#endif
			break;
		case LATEX_FORMAT:
			if ((list != NULL) && (list->key != METADATA)) {
				print_latex_node_tree(out, scratch->abbreviations, scratch);
			}
			print_latex_node_tree(out, list, scratch);
			break;
		case MEMOIR_FORMAT:
			if ((list != NULL) && (list->key != METADATA)) {
				print_memoir_node_tree(out, scratch->abbreviations, scratch);
			}
			print_memoir_node_tree(out, list, scratch);
			break;
		case BEAMER_FORMAT:
			if ((list != NULL) && (list->key != METADATA)) {
				print_beamer_node_tree(out, scratch->abbreviations, scratch);
			}
			print_beamer_node_tree(out, list, scratch);
			break;
		case LYX_FORMAT:
			perform_lyx_output(out,list,scratch);
			break;
		case OPML_FORMAT:
#ifdef DEBUG_ON
	fprintf(stderr, "export OPML\n");
#endif
			begin_opml_output(out, list, scratch);
			print_opml_node_tree(out, list, scratch);
			end_opml_output(out, list, scratch);
			break;
		case ODF_FORMAT:
#ifdef DEBUG_ON
	fprintf(stderr, "export ODF\n");
#endif
			begin_odf_output(out, list, scratch);
			print_odf_node_tree(out, list, scratch);
			end_odf_output(out, list, scratch);
			break;
		case RTF_FORMAT:
#ifdef DEBUG_ON
	fprintf(stderr, "export RTF\n");
#endif
			if (!(scratch->extensions & EXT_SNIPPET))
				begin_rtf_output(out, list, scratch);
			print_rtf_node_tree(out, list, scratch);
			if (!(scratch->extensions & EXT_SNIPPET))
				end_rtf_output(out, list, scratch);
			break;
		case CRITIC_ACCEPT_FORMAT:
			print_critic_accept_node_tree(out, list, scratch);
			break;
		case CRITIC_REJECT_FORMAT:
			print_critic_reject_node_tree(out, list, scratch);
			break;
		case CRITIC_HTML_HIGHLIGHT_FORMAT:
			print_critic_html_highlight_node_tree(out, list, scratch);
			break;
		case TOC_FORMAT:
			scratch->toc_level = 0;
			print_toc_node_tree(out,list,scratch);
			break;
		default:
			fprintf(stderr, "Unknown export format = %d\n",format);
			exit(EXIT_FAILURE);
	}
	
	output = out->str;
	g_string_free(out, false);
	free_scratch_pad(scratch);

#ifdef DEBUG_ON
	fprintf(stderr, "finish export_node_tree\n");
#endif
	return output;
}
Пример #3
0
/* export_node_tree -- given a tree, export as specified format */
char * export_node_tree(node *list, int format, int extensions) {
	char *output;
	GString *out = g_string_new("");
	scratch_pad *scratch = mk_scratch_pad(extensions);

#ifdef DEBUG_ON
	fprintf(stderr, "export_node_tree\n");
#endif

#ifdef DEBUG_ON
	fprintf(stderr, "extract_references\n");
#endif
	/* Parse for link, images, etc reference definitions */
	if ((format != OPML_FORMAT) &&
		(format != CRITIC_ACCEPT_FORMAT) &&
		(format != CRITIC_REJECT_FORMAT) &&
		(format != CRITIC_HTML_HIGHLIGHT_FORMAT))
			extract_references(list, scratch);
	
	/* Change our desired format based on metadata */
	if (format == LATEX_FORMAT)
		format = find_latex_mode(format, list);
	
	switch (format) {
		case TEXT_FORMAT:
			print_text_node_tree(out, list, scratch);
			break;
		case HTML_FORMAT:
			if (scratch->extensions & EXT_COMPLETE) {
			    g_string_append_printf(out,
				"<!DOCTYPE html>\n<html>\n<head>\n\t<meta charset=\"utf-8\"/>\n");
			}
#ifdef DEBUG_ON
	fprintf(stderr, "print_html output\n");
#endif
			print_html_node_tree(out, list, scratch);
#ifdef DEBUG_ON
	fprintf(stderr, "print html endnotes\n");
#endif
			print_html_endnotes(out, scratch);
#ifdef DEBUG_ON
	fprintf(stderr, "finished printing html endnotes\n");
#endif
			if (scratch->extensions & EXT_COMPLETE) {
				pad(out,2, scratch);
				g_string_append_printf(out, "</body>\n</html>");
			}
#ifdef DEBUG_ON
	fprintf(stderr, "closed HTML document\n");
#endif
			break;
		case LATEX_FORMAT:
			print_latex_node_tree(out, list, scratch);
			break;
		case MEMOIR_FORMAT:
			print_memoir_node_tree(out, list, scratch);
			break;
		case BEAMER_FORMAT:
			print_beamer_node_tree(out, list, scratch);
			break;
		case OPML_FORMAT:
#ifdef DEBUG_ON
	fprintf(stderr, "export OPML\n");
#endif
			begin_opml_output(out, list, scratch);
			print_opml_node_tree(out, list, scratch);
			end_opml_output(out, list, scratch);
			break;
		case ODF_FORMAT:
#ifdef DEBUG_ON
	fprintf(stderr, "export ODF\n");
#endif
			begin_odf_output(out, list, scratch);
			print_odf_node_tree(out, list, scratch);
			end_odf_output(out, list, scratch);
			break;
		case CRITIC_ACCEPT_FORMAT:
			print_critic_accept_node_tree(out, list, scratch);
			break;
		case CRITIC_REJECT_FORMAT:
			print_critic_reject_node_tree(out, list, scratch);
			break;
		case CRITIC_HTML_HIGHLIGHT_FORMAT:
			print_critic_html_highlight_node_tree(out, list, scratch);
			break;
		default:
			fprintf(stderr, "Unknown export format = %d\n",format);
			exit(EXIT_FAILURE);
	}
	
	output = out->str;
	g_string_free(out, false);
	free_scratch_pad(scratch);

#ifdef DEBUG_ON
	fprintf(stderr, "finish export_node_tree\n");
#endif
	return output;
}