From: Fletcher T. Penney Date: Sun, 19 Mar 2017 15:42:25 +0000 (-0400) Subject: ADDED: Add support for random footnote numbers X-Git-Tag: 6.0.0-rc2^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0a4d50d7053aa2d25ebb014937d9f903d341a42f;p=multimarkdown ADDED: Add support for random footnote numbers --- diff --git a/Sources/libMultiMarkdown/html.c b/Sources/libMultiMarkdown/html.c index de383e9..b7992f8 100644 --- a/Sources/libMultiMarkdown/html.c +++ b/Sources/libMultiMarkdown/html.c @@ -651,7 +651,7 @@ void mmd_export_token_html(DString * out, const char * source, token * t, scratc print_const("

"); mmd_export_token_tree_html(out, source, t->child, scratch); - + if (scratch->citation_being_printed) { scratch->footnote_para_counter--; @@ -664,7 +664,12 @@ void mmd_export_token_html(DString * out, const char * source, token * t, scratc scratch->footnote_para_counter--; if (scratch->footnote_para_counter == 0) { - printf("  ↩", scratch->footnote_being_printed, LC("return to body")); + temp_short = scratch->footnote_being_printed; + if (scratch->extensions & EXT_RANDOM_FOOT) { + srand(scratch->random_seed_base + temp_short); + temp_short = rand() % 32000 + 1; + } + printf("  ↩", temp_short, LC("return to body")); } } @@ -1289,13 +1294,27 @@ void mmd_export_token_html(DString * out, const char * source, token * t, scratc if (temp_short2 == scratch->used_footnotes->size) { // This is a re-use of a previously used note + if (scratch->extensions & EXT_RANDOM_FOOT) { + srand(scratch->random_seed_base + temp_short); + temp_short3 = rand() % 32000 + 1; + } else { + temp_short3 = temp_short; + } + printf("[%d]", - temp_short, LC("see footnote"), temp_short); + temp_short3, LC("see footnote"), temp_short); } else { // This is the first time this note was used + if (scratch->extensions & EXT_RANDOM_FOOT) { + srand(scratch->random_seed_base + temp_short); + temp_short3 = rand() % 32000 + 1; + } else { + temp_short3 = temp_short; + } + printf("[%d]", - temp_short, temp_short, LC("see footnote"), temp_short); + temp_short3, temp_short3, LC("see footnote"), temp_short); } } else { // Note-based syntax disabled diff --git a/Sources/libMultiMarkdown/writer.c b/Sources/libMultiMarkdown/writer.c index a3b3351..2d3eb97 100644 --- a/Sources/libMultiMarkdown/writer.c +++ b/Sources/libMultiMarkdown/writer.c @@ -138,6 +138,12 @@ scratch_pad * scratch_pad_new(mmd_engine * e, short format) { p->odf_para_type = BLOCK_PARA; + if (e->extensions & EXT_RANDOM_FOOT) { + p->random_seed_base = rand() % 32000; + } else { + p->random_seed_base = 0; + } + // Store links in a hash for rapid retrieval when exporting p->link_hash = NULL; link * l; diff --git a/Sources/libMultiMarkdown/writer.h b/Sources/libMultiMarkdown/writer.h index 08ed9f3..86e8046 100644 --- a/Sources/libMultiMarkdown/writer.h +++ b/Sources/libMultiMarkdown/writer.h @@ -88,6 +88,8 @@ typedef struct { struct fn_holder * footnote_hash; short footnote_being_printed; + int random_seed_base; + stack * used_citations; stack * inline_citations_to_free; struct fn_holder * citation_hash; diff --git a/Sources/multimarkdown/main.c b/Sources/multimarkdown/main.c index d595e5f..61fbf64 100644 --- a/Sources/multimarkdown/main.c +++ b/Sources/multimarkdown/main.c @@ -77,7 +77,7 @@ // argtable structs struct arg_lit *a_help, *a_version, *a_compatibility, *a_nolabels, *a_batch, - *a_accept, *a_reject, *a_full, *a_snippet; + *a_accept, *a_reject, *a_full, *a_snippet, *a_random; struct arg_str *a_format, *a_lang; struct arg_file *a_file, *a_o; struct arg_end *a_end; @@ -153,6 +153,7 @@ int main(int argc, char** argv) { a_compatibility = arg_lit0("c", "compatibility", "Markdown compatibility mode"), a_full = arg_lit0("f", "full", "force a complete document"), a_snippet = arg_lit0("s", "snippet", "force a snippet"), + a_random = arg_lit0("", "random", "use random numbers for footnote anchors"), a_rem2 = arg_rem("", ""), @@ -244,6 +245,11 @@ int main(int argc, char** argv) { extensions |= EXT_SNIPPET; } + if (a_random->count > 0) { + // Use random anchors + extensions |= EXT_RANDOM_FOOT; + } + if (a_format->count > 0) { if (strcmp(a_format->sval[0], "html") == 0) format = FORMAT_HTML;