]> granicus.if.org Git - multimarkdown/commitdiff
CHANGED: Refactor footnotes
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Sun, 5 Mar 2017 16:52:33 +0000 (11:52 -0500)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Sun, 5 Mar 2017 16:52:33 +0000 (11:52 -0500)
Sources/libMultiMarkdown/html.c
Sources/libMultiMarkdown/latex.c
Sources/libMultiMarkdown/odf.c
tests/MMD6Tests/Reference Footnotes.fodt
tests/MMD6Tests/Reference Footnotes.html
tests/MMD6Tests/Reference Footnotes.htmlc
tests/MMD6Tests/Reference Footnotes.tex
tests/MMD6Tests/Reference Footnotes.text

index 93c025c15773dfa830ef40837f5f1a92d2bd752d..e50d7f0052f10f5038b9a6312c180445b5c689cd 100644 (file)
@@ -1196,19 +1196,34 @@ void mmd_export_token_html(DString * out, const char * source, token * t, scratc
                        break;
                case PAIR_BRACKET_FOOTNOTE:
                        if (scratch->extensions & EXT_NOTES) {
+                               // Note-based syntax enabled
+
+                               // Classify this use
+                               temp_short2 = scratch->used_footnotes->size;
+                               temp_short3 = scratch->inline_footnotes_to_free->size;
                                footnote_from_bracket(source, scratch, t, &temp_short);
 
-                               if (temp_short < scratch->used_footnotes->size) {
-                                       // Re-using previous footnote
+                               if (temp_short == -1) {
+                                       // This instance is not properly formed
+                                       print_const("[^");
+                                       mmd_export_token_tree_html(out, source, t->child->next, scratch);
+                                       print_const("]");
+                                       break;
+                               }
+
+                               if (temp_short2 == scratch->used_footnotes->size) {
+                                       // This is a re-use of a previously used note
+
                                        printf("<a href=\"#fn:%d\" title=\"%s\" class=\"footnote\">[%d]</a>",
-                                                  temp_short, LC("see footnote"), temp_short);
+                                               temp_short, LC("see footnote"), temp_short);
                                } else {
-                                       // This is a new footnote
+                                       // This is the first time this note was used
+
                                        printf("<a href=\"#fn:%d\" id=\"fnref:%d\" title=\"%s\" class=\"footnote\">[%d]</a>",
-                                                  temp_short, temp_short, LC("see footnote"), temp_short);
+                                               temp_short, temp_short, LC("see footnote"), temp_short);
                                }
                        } else {
-                               // Footnotes disabled
+                               // Note-based syntax disabled
                                mmd_export_token_tree_html(out, source, t->child, scratch);
                        }
                        break;
index e3ac7f19567ea2648e492238811863d1cdc46312..9742ca8678085f060347bdd3b8547aea2e467514 100644 (file)
@@ -1132,23 +1132,52 @@ void mmd_export_token_latex(DString * out, const char * source, token * t, scrat
                        break;
                case PAIR_BRACKET_FOOTNOTE:
                        if (scratch->extensions & EXT_NOTES) {
+                               // Note-based syntax enabled
+
+                               // Classify this use
+                               temp_short2 = scratch->used_footnotes->size;
+                               temp_short3 = scratch->inline_footnotes_to_free->size;
                                footnote_from_bracket(source, scratch, t, &temp_short);
 
-                               if (temp_short < scratch->used_footnotes->size) {
-                                       // Re-using previous footnote
-                                       print("\\footnote{reuse");
+                               if (temp_short == -1) {
+                                       // This instance is not properly formed
+                                       print_const("[?");
+                                       mmd_export_token_tree_latex(out, source, t->child->next, scratch);
+                                       print_const("]");
+                                       break;
+                               }
+
+                               // Get instance of the note used
+                               temp_note = stack_peek_index(scratch->used_footnotes, temp_short - 1);
 
-                                       print("}");
+                               if (temp_short2 == scratch->used_footnotes->size) {
+                                       // This is a re-use of a previously used note
+
+                                       // TODO: This would work, assuming no URL's are converted to 
+                                       // footnotes without affecting the numbering.
+                                       // Could add a NULL to the used_footnotes stack??
+
+                                       // Additionally, re-using an old footnote would require flipping back
+                                       // through the document to find it...
+
+                                       // printf("\\footnotemark[%d]", temp_short);
+
+                                       print_const("\\footnote{");
+                                       temp_note = stack_peek_index(scratch->used_footnotes, temp_short - 1);
+
+                                       mmd_export_token_tree_latex(out, source, temp_note->content, scratch);
+                                       print_const("}");
                                } else {
-                                       // This is a new footnote
-                                       print("\\footnote{");
+                                       // This is the first time this note was used
+
+                                       print_const("\\footnote{");
                                        temp_note = stack_peek_index(scratch->used_footnotes, temp_short - 1);
 
                                        mmd_export_token_tree_latex(out, source, temp_note->content, scratch);
-                                       print("}");
+                                       print_const("}");
                                }
                        } else {
-                               // Footnotes disabled
+                               // Note-based syntax disabled
                                mmd_export_token_tree_latex(out, source, t->child, scratch);
                        }
                        break;
index 4e05571bdac387501a7f3b1d96829818b5781ac2..87124793370949b70a48995d53d6e82206d2a571 100644 (file)
@@ -1042,17 +1042,38 @@ void mmd_export_token_odf(DString * out, const char * source, token * t, scratch
                        break;
                case PAIR_BRACKET_FOOTNOTE:
                        if (scratch->extensions & EXT_NOTES) {
+                               // Note-based syntax enabled
+
+                               // Classify this use
+                               temp_short2 = scratch->used_footnotes->size;
+                               temp_short3 = scratch->inline_footnotes_to_free->size;
                                footnote_from_bracket(source, scratch, t, &temp_short);
 
-                               temp_short2 = scratch->odf_para_type;
+                               if (temp_short == -1) {
+                                       // This instance is not properly formed
+                                       print_const("[?");
+                                       mmd_export_token_tree_odf(out, source, t->child->next, scratch);
+                                       print_const("]");
+                                       break;
+                               }
+
+                               // Get instance of the note used
+                               temp_note = stack_peek_index(scratch->used_footnotes, temp_short - 1);
+
+                               temp_short3 = scratch->odf_para_type;
                                scratch->odf_para_type = PAIR_BRACKET_FOOTNOTE;
 
-                               if (temp_short < scratch->used_footnotes->size) {
-                                       // Re-using previous footnote
-                                       print("\\footnote{reuse");
+                               if (temp_short2 == scratch->used_footnotes->size) {
+                                       // This is a re-use of a previously used note
 
-                                       print("}");
+                                       printf("<text:note text:id=\"fn%d\" text:note-class=\"footnote\"><text:note-body>", temp_short);
+                                       temp_note = stack_peek_index(scratch->used_footnotes, temp_short - 1);
+
+                                       mmd_export_token_tree_odf(out, source, temp_note->content, scratch);
+                                       print_const("</text:note-body></text:note>");
                                } else {
+                                       // This is the first time this note was used
+
                                        // This is a new footnote
                                        printf("<text:note text:id=\"fn%d\" text:note-class=\"footnote\"><text:note-body>", temp_short);
                                        temp_note = stack_peek_index(scratch->used_footnotes, temp_short - 1);
@@ -1061,9 +1082,9 @@ void mmd_export_token_odf(DString * out, const char * source, token * t, scratch
                                        print_const("</text:note-body></text:note>");
                                }
 
-                               scratch->odf_para_type = temp_short2;
+                               scratch->odf_para_type = temp_short3;
                        } else {
-                               // Footnotes disabled
+                               // Note-based syntax disabled
                                mmd_export_token_tree_odf(out, source, t->child, scratch);
                        }
                        break;
index dfb05096ef6d1d5212828329f35ff42c155c798c..72a353d8e9afb414cc30217adffa685455702986 100644 (file)
@@ -282,6 +282,16 @@ bar</text:span></text:p></text:note-body></text:note></text:p>
 <text:list-item>
 <text:p text:style-name="Footnote">bat</text:p></text:list-item>
 
+</text:list></text:note-body></text:note></text:p>
+
+<text:p text:style-name="Standard">foo.<text:note text:id="fn3" text:note-class="footnote"><text:note-body><text:p text:style-name="Footnote">foo</text:p>
+
+<text:p text:style-name="Footnote"><text:span text:style-name="MMD-Italic">bar</text:span></text:p>
+
+<text:list text:style-name="L1">
+<text:list-item>
+<text:p text:style-name="Footnote">bat</text:p></text:list-item>
+
 </text:list></text:note-body></text:note></text:p>
 </office:text>
 </office:body>
index 474dcab5f3e02572c88234085ae0a7471f224840..6994095bddc43c61ca0b7dcf47d8f81be8ee1638 100644 (file)
@@ -12,6 +12,8 @@
 
 <p>foo.<a href="#fn:3" id="fnref:3" title="see footnote" class="footnote">[3]</a></p>
 
+<p>foo.<a href="#fn:3" title="see footnote" class="footnote">[3]</a></p>
+
 <div class="footnotes">
 <hr />
 <ol>
index 716c3264a7314935d9c964afd8f42c0ef30f3aa6..96dafb9f08365228e49b1227d8897d6a68ca24fd 100644 (file)
@@ -7,6 +7,8 @@ latex config:   article</p>
 
 <p>foo.<a href="foo">^bar3</a></p>
 
+<p>foo.<a href="foo">^bar3</a></p>
+
 <pre><code>*bar*
 
 * bat
index d98dd5dcd930ca7b5d4ef96ef6384baac03d93d4..cd4342a014c08cc025b16ea8d24ccb71fadd38ae 100644 (file)
@@ -16,5 +16,14 @@ foo.\footnote{foo
 
 \end{itemize}}
 
+foo.\footnote{foo
+
+\emph{bar}
+
+\begin{itemize}
+\item{} bat
+
+\end{itemize}}
+
 \input{mmd6-article-footer}
 \end{document}
index c9146aed123db19fb3c5b1bc49315541ac52d1b6..ec894fd07836ffa46ef846ed1e83ca16cd9560db 100644 (file)
@@ -7,6 +7,8 @@ foo.[^bar2]
 
 foo.[^bar3]
 
+foo.[^bar3]
+
 [^bar]: *foo*
 [^bar2]: *foo
 bar*