if (entry_level >= level) {
// This entry is a direct descendant of the parent
- temp_char = label_from_header(source, entry);
+ scratch->label_counter = *counter;
+ temp_char = label_from_header(source, entry, scratch);
printf("<li><a href=\"main.xhtml#%s\">", temp_char);
mmd_export_token_tree_html(out, source, entry->child, scratch);
print_const("</a>");
void epub_export_nav(DString * out, mmd_engine * e, scratch_pad * scratch) {
size_t counter = 0;
-
epub_export_nav_entry(out, e->dstr->str, scratch, &counter, 0);
+
+ scratch->label_counter = 0;
}
DString * epub_create(DString * body, mmd_engine * e, const char * directory) {
DString * result = d_string_new("");
scratch_pad * scratch = scratch_pad_new(e, FORMAT_EPUB);
+ scratch->random_seed_base_labels = e->random_seed_base_labels;
mz_bool status;
char * data;
if (entry_level >= level) {
// This entry is a direct descendant of the parent
- temp_char = label_from_header(source, entry);
+ scratch->label_counter = *counter;
+ temp_char = label_from_header(source, entry, scratch);
printf("<li><a href=\"#%s\">", temp_char);
mmd_export_token_tree_html(out, source, entry->child, scratch);
print_const("</a>");
size_t counter = 0;
mmd_export_toc_entry_html(out, source, scratch, &counter, 0);
+
+ scratch->label_counter = 0;
}
if (scratch->extensions & EXT_NO_LABELS) {
printf("<h%1d>", temp_short + scratch->base_header_level - 1);
} else {
- temp_char = label_from_header(source, t);
+ temp_char = label_from_header(source, t, scratch);
printf("<h%1d id=\"%s\">", temp_short + scratch->base_header_level - 1, temp_char);
free(temp_char);
}
if (scratch->extensions & EXT_NO_LABELS) {
printf("<h%1d>", temp_short + scratch->base_header_level - 1);
} else {
- temp_token = manual_label_from_header(t, source);
-
- if (temp_token) {
- temp_char = label_from_token(source, temp_token);
- } else {
- temp_char = label_from_token(source, t);
- }
-
+ temp_char = label_from_header(source, t, scratch);
printf("<h%1d id=\"%s\">", temp_short + scratch->base_header_level - 1, temp_char);
free(temp_char);
}
if (scratch->extensions & EXT_NO_LABELS) {
printf("<h%1d>", temp_short + scratch->base_header_level - 1);
} else {
- temp_token = manual_label_from_header(t, source);
-
- if (temp_token) {
- temp_char = label_from_token(source, temp_token);
- } else {
- temp_char = label_from_token(source, t);
- }
-
+ temp_char = label_from_header(source, t, scratch);
printf("<h%1d id=\"%s\">", temp_short + scratch->base_header_level - 1, temp_char);
free(temp_char);
}
EXT_TRANSCLUDE = 1 << 13, //!< Perform transclusion(s)
EXT_PARSE_OPML = 1 << 14, //!< Convert from OPML before processing source text
EXT_PARSE_ITMZ = 1 << 15, //!< Convert from ITMZ (iThoughts) before processing source text
+ EXT_RANDOM_LABELS = 1 << 16, //!< Use random numbers for header labels (unless manually defined)
EXT_FAKE = 1 << 31, //!< 31 is highest number allowed
};
if (entry_level >= level) {
// This entry is a direct descendant of the parent
- temp_char = label_from_header(source, entry);
+ scratch->label_counter = *counter;
+ temp_char = label_from_header(source, entry, scratch);
print_const("\\item ");
mmd_export_token_tree_latex(out, source, entry->child, scratch);
printf("(\\autoref{%s})\n\n", temp_char);
size_t counter = 0;
mmd_export_toc_entry_latex(out, source, scratch, &counter, 0);
+
+ scratch->label_counter = 0;
}
if (scratch->extensions & EXT_NO_LABELS) {
print_const("}");
} else {
- temp_token = manual_label_from_header(t, source);
-
- if (temp_token) {
- temp_char = label_from_token(source, temp_token);
- } else {
- temp_char = label_from_token(source, t);
- }
-
+ temp_char = label_from_header(source, t, scratch);
printf("}\n\\label{%s}", temp_char);
free(temp_char);
}
short quotes_lang;
struct asset * asset_hash;
+
+ int random_seed_base_labels;
};
if (entry_level >= level) {
// This entry is a direct descendant of the parent
- temp_char = label_from_header(source, entry);
+ scratch->label_counter = *counter;
+ temp_char = label_from_header(source, entry, scratch);
printf("<text:p text:style-name=\"TOC_Item\"><text:a xlink:type=\"simple\" xlink:href=\"#%s\" text:style-name=\"Index_20_Link\" text:visited-style-name=\"Index_20_Link\">", temp_char);
mmd_export_token_tree_opendocument(out, source, entry->child, scratch);
print_const(" <text:tab/>1</text:a></text:p>\n");
mmd_export_toc_entry_opendocument(out, source, scratch, &counter, 0);
print_const("</text:index-body>\n</text:table-of-content>\n\n");
+
+ scratch->label_counter = 0;
}
if (scratch->extensions & EXT_NO_LABELS) {
mmd_export_token_tree_opendocument(out, source, t->child, scratch);
} else {
- temp_char = label_from_header(source, t);
+ temp_char = label_from_header(source, t, scratch);
printf("<text:bookmark text:name=\"%s\"/>", temp_char);
mmd_export_token_tree_opendocument(out, source, t->child, scratch);
//printf("<text:bookmark-end text:name=\"%s\"/>", temp_char);
p->random_seed_base = 0;
}
+ if (e->extensions & EXT_RANDOM_LABELS) {
+ p->random_seed_base_labels = rand() % 32000;
+ } else {
+ p->random_seed_base_labels = 0;
+ }
+
+ p->label_counter = 0;
+
// Store links in a hash for rapid retrieval when exporting
p->link_hash = NULL;
link * l;
}
-char * label_from_header(const char * source, token * t) {
+char * label_from_header(const char * source, token * t, scratch_pad * scratch) {
char * result;
+ short temp_short;
+
token * temp_token = manual_label_from_header(t, source);
if (temp_token) {
result = label_from_token(source, temp_token);
} else {
- result = label_from_token(source, t);
+ if (scratch->extensions & EXT_RANDOM_LABELS) {
+ srand(scratch->random_seed_base_labels + scratch->label_counter);
+ temp_short = rand() % 32000 + 1;
+ result = malloc(sizeof(char) * 6);
+ sprintf(result, "%d", temp_short);
+
+ scratch->label_counter++;
+ } else {
+ result = label_from_token(source, t);
+ }
}
return result;
// Preserve asset_hash for possible use in export
e->asset_hash = scratch->asset_hash;
+ // Preserve random label seed
+ e->random_seed_base_labels = scratch->random_seed_base_labels;
+
scratch_pad_free(scratch);
}
int random_seed_base;
+ int random_seed_base_labels;
+ int label_counter;
+
stack * used_citations;
stack * inline_citations_to_free;
struct fn_holder * citation_hash;
void footnote_free(footnote * f);
char * label_from_token(const char * source, token * t);
-char * label_from_header(const char * source, token * t);
+char * label_from_header(const char * source, token * t, scratch_pad * scratch);
void parse_brackets(const char * source, scratch_pad * scratch, token * bracket, link ** link, short * skip_token, bool * free_link);
// argtable structs
struct arg_lit *a_help, *a_version, *a_compatibility, *a_nolabels, *a_batch,
- *a_accept, *a_reject, *a_full, *a_snippet, *a_random, *a_meta,
+ *a_accept, *a_reject, *a_full, *a_snippet, *a_random, *a_unique, *a_meta,
*a_notransclude, *a_nosmart, *a_opml, *a_itmz;
struct arg_str *a_format, *a_lang, *a_extract;
struct arg_file *a_file, *a_o;
a_snippet = arg_lit0("s", "snippet", "force a snippet"),
a_compatibility = arg_lit0("c", "compatibility", "Markdown compatibility mode"),
a_random = arg_lit0(NULL, "random", "use random numbers for footnote anchors"),
+ a_unique = arg_lit0(NULL, "unique", "use random numbers for header labels unless manually specified"),
a_nosmart = arg_lit0(NULL, "nosmart", "Disable smart typography"),
a_nolabels = arg_lit0(NULL, "nolabels", "Disable id attributes for headers"),
a_notransclude = arg_lit0(NULL, "notransclude", "Disable file transclusion"),
extensions |= EXT_RANDOM_FOOT;
}
+ if (a_unique->count > 0) {
+ // Use random header labels
+ extensions |= EXT_RANDOM_LABELS;
+ }
+
if (a_format->count > 0) {
if (strcmp(a_format->sval[0], "html") == 0) {
format = FORMAT_HTML;