ext/commonmarker/blocks.c in commonmarker-0.23.1 vs ext/commonmarker/blocks.c in commonmarker-0.23.2
- old
+ new
@@ -466,11 +466,10 @@
cmark_event_type ev_type;
while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
cur = cmark_iter_get_node(iter);
if (ev_type == CMARK_EVENT_EXIT && cur->type == CMARK_NODE_FOOTNOTE_DEFINITION) {
- cmark_node_unlink(cur);
cmark_footnote_create(map, cur);
}
}
cmark_iter_free(iter);
@@ -483,10 +482,19 @@
cmark_footnote *footnote = (cmark_footnote *)cmark_map_lookup(map, &cur->as.literal);
if (footnote) {
if (!footnote->ix)
footnote->ix = ++ix;
+ // store a reference to this footnote reference's footnote definition
+ // this is used by renderers when generating label ids
+ cur->parent_footnote_def = footnote->node;
+
+ // keep track of a) count of how many times this footnote def has been
+ // referenced, and b) which reference index this footnote ref is at.
+ // this is used by renderers when generating links and backreferences.
+ cur->footnote.ref_ix = ++footnote->node->footnote.def_count;
+
char n[32];
snprintf(n, sizeof(n), "%d", footnote->ix);
cmark_chunk_free(parser->mem, &cur->as.literal);
cmark_strbuf buf = CMARK_BUF_INIT(parser->mem);
cmark_strbuf_puts(&buf, n);
@@ -513,16 +521,19 @@
if (map->sorted) {
qsort(map->sorted, map->size, sizeof(cmark_map_entry *), sort_footnote_by_ix);
for (unsigned int i = 0; i < map->size; ++i) {
cmark_footnote *footnote = (cmark_footnote *)map->sorted[i];
- if (!footnote->ix)
+ if (!footnote->ix) {
+ cmark_node_unlink(footnote->node);
continue;
+ }
cmark_node_append_child(parser->root, footnote->node);
footnote->node = NULL;
}
}
+ cmark_unlink_footnotes_map(map);
cmark_map_free(map);
}
// Attempts to parse a list item marker (bullet or enumerated).
// On success, returns length of the marker, and populates