]> granicus.if.org Git - multimarkdown/commitdiff
ADDED: 'finalize' beamer support
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Thu, 16 Feb 2017 17:25:23 +0000 (12:25 -0500)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Thu, 16 Feb 2017 17:25:23 +0000 (12:25 -0500)
src/beamer.c
src/beamer.h
src/writer.c
src/writer.h

index 866d803473fe5cd22709b50381542a5a19a6486c..85c59b01e908daacdb31bd737a84eadc3fcf2601 100644 (file)
 #define print_localized(x) mmd_print_localized_char_latex(out, x, scratch)
 
 
+void mmd_outline_add_beamer(DString * out, token * current, scratch_pad * scratch) {
+       token * t;
+       short level;            // Header level we are adding
+       short t_level;  
+       stack * s = scratch->outline_stack;
+
+       if (current) {
+               switch (current->type) {
+                       case BLOCK_SETEXT_1:
+                               level = 1;
+                               break;
+                       case BLOCK_SETEXT_2:
+                               level = 2;
+                       default:
+                               level = 1 + current->type - BLOCK_H1;
+               }
+
+               level += scratch->base_header_level - 1;
+       } else {
+               level = 0;
+       }
+
+       if (s->size) {
+               t = stack_peek(s);
+
+               while (t) {
+                       switch (t->type) {
+                               case BLOCK_SETEXT_1:
+                                       t_level = 1;
+                                       break;
+                               case BLOCK_SETEXT_2:
+                                       t_level = 2;
+                               default:
+                                       t_level = 1 + t->type - BLOCK_H1;
+                       }
+
+                       t_level += scratch->base_header_level - 1;
+
+                       if (t_level >= level) {
+                               // Close out level
+                               switch (t_level) {
+                                       case 3:
+                                               pad(out, 2, scratch);
+                                               print("\\end{frame}\n\n");
+                                               scratch->padded = 2;
+                                               break;
+                                       case 4:
+                                               pad(out, 2, scratch);
+                                               print("}\n\n");
+                                               scratch->padded = 2;
+                                               break;
+                               }
+
+                               stack_pop(s);
+                               t = stack_peek(s);
+                       } else {
+                               // Nothing to close
+                               t = NULL;
+                       }
+               }
+       }
+
+
+       // Add current level to stack and open
+       switch (level) {
+               case 3:
+                       pad(out, 2, scratch);
+                       print("\\begin{frame}[fragile]\n");
+                       scratch->padded = 1;
+                       stack_push(s, current);
+                       break;
+               case 4:
+                       pad(out, 2, scratch);
+                       print("\\mode<article>{");
+                       scratch->padded = 0;
+                       stack_push(s, current);
+                       break;
+       }
+}
+
+
 void mmd_export_token_beamer(DString * out, const char * source, token * t, scratch_pad * scratch) {
        if (t == NULL)
                return;
@@ -117,6 +198,9 @@ void mmd_export_token_beamer(DString * out, const char * source, token * t, scra
                case BLOCK_SETEXT_1:
                case BLOCK_SETEXT_2:
                        pad(out, 2, scratch);
+
+                       mmd_outline_add_beamer(out, t, scratch);
+
                        switch (t->type) {
                                case BLOCK_SETEXT_1:
                                        temp_short = 1;
@@ -136,7 +220,7 @@ void mmd_export_token_beamer(DString * out, const char * source, token * t, scra
                                        print("\\section{");
                                        break;
                                case 3:
-                                       print("\\begin{frame}\n\\frametitle{");
+                                       print("\\frametitle{");
                                        break;
                                default:
                                        print("\\emph{");
@@ -190,3 +274,54 @@ void mmd_export_token_tree_beamer(DString * out, const char * source, token * t,
        scratch->recurse_depth--;
 }
 
+
+void mmd_export_citation_list_beamer(DString * out, const char * source, scratch_pad * scratch) {
+       if (scratch->used_citations->size > 0) {
+               footnote * note;
+               token * content;
+
+               pad(out, 2, scratch);
+               print("\\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)
+               {
+                       // Export footnote
+                       pad(out, 2, scratch);
+
+                       note = stack_peek_index(scratch->used_citations, i);
+                       content = note->content;
+
+                       printf("\\bibitem{%s}\n", note->label_text);
+                       scratch->padded = 6;
+
+                       scratch->footnote_para_counter = 0;
+
+                       content = note->content;
+                       scratch->citation_being_printed = i + 1;
+
+                       mmd_export_token_tree_latex(out, source, content, scratch);
+               }
+
+               pad(out, 1, scratch);
+               print("\\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");
+       meta * m = extract_meta_from_stack(scratch, "latexfooter");
+
+       if (m) {
+               printf("\\input{%s}\n\n", m->value);
+       }
+
+       print("\\end{document}");
+       print("\\mode*\n");
+       scratch->padded = 0;
+}
index f23f0893452596de6125f7c6e64d462583e2c801..eca3beb3bb2601596b789e1ea129ada4b7311acb 100644 (file)
 void mmd_export_token_beamer(DString * out, const char * source, token * t, scratch_pad * scratch);
 void mmd_export_token_tree_beamer(DString * out, const char * source, token * t, scratch_pad * scratch);
 
+void mmd_outline_add_beamer(DString * out, token * current, scratch_pad * scratch);
+
+void mmd_export_citation_list_beamer(DString * out, const char * source, scratch_pad * scratch);
+void mmd_end_complete_beamer(DString * out, const char * source, scratch_pad * scratch);
+
 
 #endif
index bf021309c5f74b1e3fadd337424a67913c6f1033..b96dcd7ba31d8558be67fc719731c6db5b1d0c90 100644 (file)
@@ -98,6 +98,8 @@ scratch_pad * scratch_pad_new(mmd_engine * e, short format) {
 
                p->header_stack = e->header_stack;
 
+               p->outline_stack = stack_new(0);
+
                p->recurse_depth = 0;
 
                p->base_header_level = 1;
@@ -163,6 +165,8 @@ scratch_pad * scratch_pad_new(mmd_engine * e, short format) {
 void scratch_pad_free(scratch_pad * scratch) {
 //     HASH_CLEAR(hh, scratch->link_hash);
 
+       stack_free(scratch->outline_stack);
+
        link * l, * l_tmp;
        
        // Free link hash
@@ -1325,10 +1329,13 @@ void mmd_export_token_tree(DString * out, mmd_engine * e, short format) {
                                mmd_start_complete_latex(out, e->dstr->str, scratch);
 
                        mmd_export_token_tree_beamer(out, e->dstr->str, e->root, scratch);
-                       mmd_export_citation_list_latex(out, e->dstr->str, scratch);
+
+                       mmd_outline_add_beamer(out, NULL, scratch);
+
+                       mmd_export_citation_list_beamer(out, e->dstr->str, scratch);
 
                        if (scratch->extensions & EXT_COMPLETE)
-                               mmd_end_complete_latex(out, e->dstr->str, scratch);
+                               mmd_end_complete_beamer(out, e->dstr->str, scratch);
 
                        break;
                case FORMAT_HTML:
index 98c29a0b0f21ce6da5560d62444c9696ed1b61ca..68d913478bbe7af803820756e0f5ca1228e1a06b 100644 (file)
@@ -100,6 +100,8 @@ typedef struct {
 
        stack *                         header_stack;
 
+       stack *                         outline_stack;
+
        short                           recurse_depth;
        
        short                           in_table_header;