]> granicus.if.org Git - multimarkdown/commitdiff
CHANGED: Refactor glossary code
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Sun, 5 Mar 2017 16:21:39 +0000 (11:21 -0500)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Sun, 5 Mar 2017 16:21:39 +0000 (11:21 -0500)
Sources/libMultiMarkdown/html.c
Sources/libMultiMarkdown/latex.c
Sources/libMultiMarkdown/odf.c
tests/MMD6Tests/Glossaries.fodt

index a826b4d351bd9e3721ba02154dd389228ec7d6f9..93c025c15773dfa830ef40837f5f1a92d2bd752d 100644 (file)
@@ -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("<a href=\"#gn:%d\" title=\"%s\" class=\"glossary\">",
                                                   temp_short, LC("see glossary"));
-
                                        mmd_print_string_html(out, temp_note->clean_text, false);
-
                                        print_const("</a>");
                                } else {
-                                       // This is a new glossary
+                                       // This is the first time this note was used
+
+
                                        printf("<a href=\"#gn:%d\" id=\"gnref:%d\" title=\"%s\" class=\"glossary\">",
                                                   temp_short, temp_short, LC("see glossary"));
-
                                        mmd_print_string_html(out, temp_note->clean_text, false);
-
                                        print_const("</a>");
                                }
                        } else {
-                               // Footnotes disabled
+                               // Note-based syntax disabled
                                mmd_export_token_tree_html(out, source, t->child, scratch);
                        }
                        break;
index d6667f4ec7b1ab2d19d9082185545cab746e01a0..e3ac7f19567ea2648e492238811863d1cdc46312 100644 (file)
@@ -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;
index b45ee8350764457897d677554475638569861aa0..4e05571bdac387501a7f3b1d96829818b5781ac2 100644 (file)
@@ -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("<text:note text:id=\"gn%d\" text:note-class=\"glossary\"><text:note-body>", temp_short);
-
                                        mmd_export_token_tree_odf(out, source, temp_note->content, 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 b64c08e7e78aee465571cf43456871e70faf6b4d..a3b2f45391217c122fb4b9236190c44e929e2bcd 100644 (file)
 
 <text:p text:style-name="Footnote">With second para.</text:p></text:note-body></text:note></text:p>
 
-<text:p text:style-name="Standard">\footnote{reuse}</text:p>
+<text:p text:style-name="Standard">foo</text:p>
 
 <text:p text:style-name="Standard">[?bar]</text:p>