From 9b7b471c3239872cd4754506c30192a47325c71f Mon Sep 17 00:00:00 2001 From: "Fletcher T. Penney" Date: Sat, 11 Feb 2017 12:05:05 -0500 Subject: [PATCH] ADDED: Add support for citation 'locators' --- src/html.c | 59 +++++++++++++++++++++++++++++----- src/writer.h | 2 ++ tests/MMD6Tests/Citations.html | 6 ++-- 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/src/html.c b/src/html.c index 3d900b9..c6ac00a 100644 --- a/src/html.c +++ b/src/html.c @@ -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("[%d]", - temp_short, LC("see citation"), temp_short); - } else { - // This is a new citation - printf("[%d]", - temp_short, temp_short, LC("see citation"), temp_short); + if (temp_bool) { + if (temp_short < scratch->used_citations->size) { + // Re-using previous citation + printf("[%s%s%d]", + temp_short, LC("see citation"), temp_char, temp_char2, temp_short); + } else { + // This is a new citation + printf("[%s%s%d]", + 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) { diff --git a/src/writer.h b/src/writer.h index fa3f5b4..c640b1d 100644 --- a/src/writer.h +++ b/src/writer.h @@ -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 diff --git a/tests/MMD6Tests/Citations.html b/tests/MMD6Tests/Citations.html index 7976de5..bffd651 100644 --- a/tests/MMD6Tests/Citations.html +++ b/tests/MMD6Tests/Citations.html @@ -1,10 +1,10 @@

[1]

-

[p. 123][1]

+

[p. 123, 1]

-

[][1]

+

[1]

-

[Not Cited][1]

+


-- 2.40.0