From: Fletcher T. Penney Date: Sun, 5 Mar 2017 16:52:33 +0000 (-0500) Subject: CHANGED: Refactor footnotes X-Git-Tag: 0.4.2-b^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=87a003a4c3f7067bad85657a5996d6d36a433df2;p=multimarkdown CHANGED: Refactor footnotes --- diff --git a/Sources/libMultiMarkdown/html.c b/Sources/libMultiMarkdown/html.c index 93c025c..e50d7f0 100644 --- a/Sources/libMultiMarkdown/html.c +++ b/Sources/libMultiMarkdown/html.c @@ -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("[%d]", - 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("[%d]", - 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; diff --git a/Sources/libMultiMarkdown/latex.c b/Sources/libMultiMarkdown/latex.c index e3ac7f1..9742ca8 100644 --- a/Sources/libMultiMarkdown/latex.c +++ b/Sources/libMultiMarkdown/latex.c @@ -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; diff --git a/Sources/libMultiMarkdown/odf.c b/Sources/libMultiMarkdown/odf.c index 4e05571..8712479 100644 --- a/Sources/libMultiMarkdown/odf.c +++ b/Sources/libMultiMarkdown/odf.c @@ -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("", 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(""); } else { + // This is the first time this note was used + // This is a new footnote printf("", 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(""); } - 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; diff --git a/tests/MMD6Tests/Reference Footnotes.fodt b/tests/MMD6Tests/Reference Footnotes.fodt index dfb0509..72a353d 100644 --- a/tests/MMD6Tests/Reference Footnotes.fodt +++ b/tests/MMD6Tests/Reference Footnotes.fodt @@ -282,6 +282,16 @@ bar bat + + +foo.foo + +bar + + + +bat + diff --git a/tests/MMD6Tests/Reference Footnotes.html b/tests/MMD6Tests/Reference Footnotes.html index 474dcab..6994095 100644 --- a/tests/MMD6Tests/Reference Footnotes.html +++ b/tests/MMD6Tests/Reference Footnotes.html @@ -12,6 +12,8 @@

foo.[3]

+

foo.[3]

+

    diff --git a/tests/MMD6Tests/Reference Footnotes.htmlc b/tests/MMD6Tests/Reference Footnotes.htmlc index 716c326..96dafb9 100644 --- a/tests/MMD6Tests/Reference Footnotes.htmlc +++ b/tests/MMD6Tests/Reference Footnotes.htmlc @@ -7,6 +7,8 @@ latex config: article

    foo.^bar3

    +

    foo.^bar3

    +
    *bar*
     
     * bat
    diff --git a/tests/MMD6Tests/Reference Footnotes.tex b/tests/MMD6Tests/Reference Footnotes.tex
    index d98dd5d..cd4342a 100644
    --- a/tests/MMD6Tests/Reference Footnotes.tex	
    +++ b/tests/MMD6Tests/Reference Footnotes.tex	
    @@ -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}
    diff --git a/tests/MMD6Tests/Reference Footnotes.text b/tests/MMD6Tests/Reference Footnotes.text
    index c9146ae..ec894fd 100644
    --- a/tests/MMD6Tests/Reference Footnotes.text	
    +++ b/tests/MMD6Tests/Reference Footnotes.text	
    @@ -7,6 +7,8 @@ foo.[^bar2]
     
     foo.[^bar3]
     
    +foo.[^bar3]
    +
     [^bar]: *foo*
     [^bar2]: *foo
     bar*