]> granicus.if.org Git - multimarkdown/commitdiff
ADDED: Add support for random footnote numbers
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Sun, 19 Mar 2017 15:42:25 +0000 (11:42 -0400)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Sun, 19 Mar 2017 15:42:25 +0000 (11:42 -0400)
Sources/libMultiMarkdown/html.c
Sources/libMultiMarkdown/writer.c
Sources/libMultiMarkdown/writer.h
Sources/multimarkdown/main.c

index de383e97ce73f66adc6fb6c6e142efa8d8ae97ea..b7992f8d8f6d78b6c8a2c4122c2c0e11a27d1472 100644 (file)
@@ -651,7 +651,7 @@ void mmd_export_token_html(DString * out, const char * source, token * t, scratc
                                print_const("<p>");
 
                        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(" <a href=\"#fnref:%d\" title=\"%s\" class=\"reversefootnote\">&#160;&#8617;</a>", 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(" <a href=\"#fnref:%d\" title=\"%s\" class=\"reversefootnote\">&#160;&#8617;</a>", 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("<a href=\"#fn:%d\" title=\"%s\" class=\"footnote\">[%d]</a>",
-                                               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("<a href=\"#fn:%d\" id=\"fnref:%d\" title=\"%s\" class=\"footnote\">[%d]</a>",
-                                               temp_short, temp_short, LC("see footnote"), temp_short);
+                                               temp_short3, temp_short3, LC("see footnote"), temp_short);
                                }
                        } else {
                                // Note-based syntax disabled
index a3b33511d17aa8e530690c7226a8b349d19da227..2d3eb9736795a5ec495c70c0ef7f2aa4c476ef96 100644 (file)
@@ -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;
index 08ed9f384104704c285a0b32c14a1deacf8a0074..86e80468efa389eb0221b66870f01abbe1ad0673 100644 (file)
@@ -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;
index d595e5fe54008bc937eed7a4cf99fa0a760cac97..61fbf64b2551645d6b376d4dd656d23d5c64ee75 100644 (file)
@@ -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;