From: Fletcher T. Penney Date: Sun, 5 Mar 2017 16:21:39 +0000 (-0500) Subject: CHANGED: Refactor glossary code X-Git-Tag: 0.4.2-b^2~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=deab5602548e691ad62d01a76cfc128c0d330d25;p=multimarkdown CHANGED: Refactor glossary code --- diff --git a/Sources/libMultiMarkdown/html.c b/Sources/libMultiMarkdown/html.c index a826b4d..93c025c 100644 --- a/Sources/libMultiMarkdown/html.c +++ b/Sources/libMultiMarkdown/html.c @@ -1214,36 +1214,42 @@ void mmd_export_token_html(DString * out, const char * source, token * t, scratc break; case PAIR_BRACKET_GLOSSARY: if (scratch->extensions & EXT_NOTES) { + // Note-based syntax enabled + + // Classify this use + temp_short2 = scratch->used_glossaries->size; + temp_short3 = scratch->inline_glossaries_to_free->size; glossary_from_bracket(source, scratch, t, &temp_short); if (temp_short == -1) { + // This instance is not properly formed print_const("[?"); - mmd_export_token_tree_html(out, source, t->child, scratch); + mmd_export_token_tree_html(out, source, t->child->next, scratch); print_const("]"); break; } + // Get instance of the note used temp_note = stack_peek_index(scratch->used_glossaries, temp_short - 1); - if (temp_short < scratch->used_glossaries->size) { - // Re-using previous glossary + if (temp_short2 == scratch->used_glossaries->size) { + // This is a re-use of a previously used note + printf("", temp_short, LC("see glossary")); - mmd_print_string_html(out, temp_note->clean_text, false); - print_const(""); } else { - // This is a new glossary + // This is the first time this note was used + + printf("", temp_short, temp_short, LC("see glossary")); - mmd_print_string_html(out, temp_note->clean_text, false); - print_const(""); } } 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 d6667f4..e3ac7f1 100644 --- a/Sources/libMultiMarkdown/latex.c +++ b/Sources/libMultiMarkdown/latex.c @@ -1154,35 +1154,40 @@ void mmd_export_token_latex(DString * out, const char * source, token * t, scrat break; case PAIR_BRACKET_GLOSSARY: if (scratch->extensions & EXT_NOTES) { - // See whether we create an inline glossary - temp_short2 = scratch->inline_glossaries_to_free->size; - glossary_from_bracket(source, scratch, t, &temp_short); + // Note-based syntax enabled + + // Classify this use + temp_short2 = scratch->used_glossaries->size; temp_short3 = scratch->inline_glossaries_to_free->size; + glossary_from_bracket(source, scratch, t, &temp_short); if (temp_short == -1) { + // This instance is not properly formed print_const("[?"); - mmd_export_token_tree_latex(out, source, t->child, scratch); + mmd_export_token_tree_latex(out, source, t->child->next, scratch); print_const("]"); break; } - if (temp_short2 != temp_short3) - temp_bool = true; // This is an inline - else - temp_bool = false; - + // Get instance of the note used temp_note = stack_peek_index(scratch->used_glossaries, temp_short - 1); - if (temp_short < scratch->used_glossaries->size) { - // Re-using previous glossary + if (temp_short2 == scratch->used_glossaries->size) { + // This is a re-use of a previously used note + print("\\gls{"); print(temp_note->label_text); print("}"); } else { - // This is a new glossary + // This is the first time this note was used - if (temp_bool) { - // This is an inline glossary entry + if (temp_short3 == scratch->inline_glossaries_to_free->size) { + // This is a reference definition + print_const("\\gls{"); + print(temp_note->label_text); + print_const("}"); + } else { + // This is an inline definition print_const("\\newglossaryentry{"); print(temp_note->label_text); @@ -1193,14 +1198,13 @@ void mmd_export_token_latex(DString * out, const char * source, token * t, scrat // We skip over temp_note->content, since that is the term in use mmd_export_token_tree_latex(out, source, temp_note->content, scratch); - print_const("}}"); + print_const("}}\\gls{"); + print(temp_note->label_text); + print_const("}"); } - print_const("\\gls{"); - print(temp_note->label_text); - 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 b45ee83..4e05571 100644 --- a/Sources/libMultiMarkdown/odf.c +++ b/Sources/libMultiMarkdown/odf.c @@ -1128,38 +1128,44 @@ void mmd_export_token_odf(DString * out, const char * source, token * t, scratch break; case PAIR_BRACKET_GLOSSARY: if (scratch->extensions & EXT_NOTES) { + // Note-based syntax enabled + + // Classify this use + temp_short2 = scratch->used_glossaries->size; + temp_short3 = scratch->inline_glossaries_to_free->size; glossary_from_bracket(source, scratch, t, &temp_short); if (temp_short == -1) { + // This instance is not properly formed print_const("[?"); - mmd_export_token_tree_odf(out, source, t->child, scratch); + mmd_export_token_tree_odf(out, source, t->child->next, scratch); print_const("]"); break; } - temp_short2 = scratch->odf_para_type; + // Get instance of the note used + temp_note = stack_peek_index(scratch->used_glossaries, temp_short - 1); + + temp_short3 = scratch->odf_para_type; scratch->odf_para_type = PAIR_BRACKET_GLOSSARY; - if (temp_short < scratch->used_glossaries->size) { - // Re-using previous footnote - print("\\footnote{reuse"); + if (temp_short2 == scratch->used_glossaries->size) { + // This is a re-use of a previously used note - print("}"); + mmd_print_string_odf(out, temp_note->clean_text); } else { - // This is a new glossary item - temp_note = stack_peek_index(scratch->used_glossaries, temp_short - 1); + // This is the first time this note was used mmd_print_string_odf(out, temp_note->clean_text); printf("", temp_short); - mmd_export_token_tree_odf(out, source, temp_note->content, 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/Glossaries.fodt b/tests/MMD6Tests/Glossaries.fodt index b64c08e..a3b2f45 100644 --- a/tests/MMD6Tests/Glossaries.fodt +++ b/tests/MMD6Tests/Glossaries.fodt @@ -277,7 +277,7 @@ With second para. -\footnote{reuse} +foo [?bar]