]> granicus.if.org Git - multimarkdown/commitdiff
ADDED: Add support for citation 'locators'
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Sat, 11 Feb 2017 17:05:05 +0000 (12:05 -0500)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Sat, 11 Feb 2017 17:05:05 +0000 (12:05 -0500)
src/html.c
src/writer.h
tests/MMD6Tests/Citations.html

index 3d900b90739bd7cb05ad07c2b507e5b862905b84..c6ac00a6dc0ba3fe42e34e422a69d967153553e2 100644 (file)
@@ -965,6 +965,11 @@ void mmd_export_token_html(DString * out, const char * source, token * t, size_t
                        mmd_export_token_tree_html(out, source, t->child, offset, scratch);
                        break;
                case PAIR_BRACKET:
+                       if ((scratch->extensions & EXT_NOTES) &&
+                               (t->next && t->next->type == PAIR_BRACKET_CITATION)) {
+                               goto parse_citation;
+                       }
+
                case PAIR_BRACKET_IMAGE:
                        parse_brackets(source, scratch, t, &temp_link, &temp_short, &temp_bool);
 
@@ -1008,22 +1013,60 @@ void mmd_export_token_html(DString * out, const char * source, token * t, size_t
                        mmd_export_token_tree_html(out, source, t->child, offset, scratch);
                        break;
                case PAIR_BRACKET_CITATION:
+                       parse_citation:
+                       temp_bool = true;
+
+                       if (t->type == PAIR_BRACKET) {
+                               // This is a locator for subsequent ciation
+                               temp_char = text_inside_pair(source, t);
+                               temp_char2 = label_from_string(temp_char);
+
+                               if (strcmp(temp_char2, "notcited") == 0) {
+                                       free(temp_char2);
+                                       free(temp_char);
+                                       temp_char = strdup("");
+                                       temp_bool = false;
+                               }
+
+                               if (temp_char[0] == '\0')
+                                       temp_char2 = strdup("");
+                               else
+                                       temp_char2 = strdup(", ");
+
+
+                               // Process the actual citation
+                               t = t->next;
+                       } else {
+                               temp_char = strdup("");
+                               temp_char2 = strdup("");
+                       }
+
                        if (scratch->extensions & EXT_NOTES) {
                                citation_from_bracket(source, scratch, t, &temp_short);
 
-                               if (temp_short < scratch->used_citations->size) {
-                                       // Re-using previous citation
-                                       printf("<a href=\"#cn:%d\" title=\"%s\" class=\"citation\">[%d]</a>",
-                                                  temp_short, LC("see citation"), temp_short);
-                               } else {
-                                       // This is a new citation
-                                       printf("<a href=\"#cn:%d\" id=\"cnref:%d\" title=\"%s\" class=\"citation\">[%d]</a>",
-                                                  temp_short, temp_short, LC("see citation"), temp_short);
+                               if (temp_bool) {
+                                       if (temp_short < scratch->used_citations->size) {
+                                               // Re-using previous citation
+                                               printf("<a href=\"#cn:%d\" title=\"%s\" class=\"citation\">[%s%s%d]</a>",
+                                                               temp_short, LC("see citation"), temp_char, temp_char2, temp_short);
+                                       } else {
+                                               // This is a new citation
+                                               printf("<a href=\"#cn:%d\" id=\"cnref:%d\" title=\"%s\" class=\"citation\">[%s%s%d]</a>",
+                                                               temp_short, temp_short, LC("see citation"), temp_char, temp_char2, temp_short);
+                                       }
+                               }
+
+                               if (t->prev && (t->prev->type == PAIR_BRACKET)) {
+                                       // Skip citation on next pass
+                                       scratch->skip_token = 1;
                                }
                        } else {
                                // Footnotes disabled
                                mmd_export_token_tree_html(out, source, t->child, offset, scratch);
                        }
+
+                       free(temp_char);
+                       free(temp_char2);
                        break;
                case PAIR_BRACKET_FOOTNOTE:
                        if (scratch->extensions & EXT_NOTES) {
index fa3f5b49f10c83ba6550e7ca0ff752757c31699c..c640b1d313964335d92cb7851cf5ae431aad5351 100644 (file)
@@ -209,5 +209,7 @@ char * get_fence_language_specifier(token * fence, const char * source);
 
 token * manual_label_from_header(token * h, const char * source);
 
+char * label_from_string(const char * str);
+
 #endif
 
index 7976de56c3250a222c77519d5a94fd7907d9e3e8..bffd65130259da4aba2fd8272b9212ee3f63909a 100644 (file)
@@ -1,10 +1,10 @@
 <p><a href="#cn:1" id="cnref:1" title="see citation" class="citation">[1]</a></p>
 
-<p>[p. 123]<a href="#cn:1" id="cnref:1" title="see citation" class="citation">[1]</a></p>
+<p><a href="#cn:1" id="cnref:1" title="see citation" class="citation">[p. 123, 1]</a></p>
 
-<p>[]<a href="#cn:1" id="cnref:1" title="see citation" class="citation">[1]</a></p>
+<p><a href="#cn:1" id="cnref:1" title="see citation" class="citation">[1]</a></p>
 
-<p>[Not Cited]<a href="#cn:1" id="cnref:1" title="see citation" class="citation">[1]</a></p>
+<p></p>
 
 <div class="citations">
 <hr />