Skip to content

Commit

Permalink
Merge pull request #148 from phillmv/update-to-0290gfm2
Browse files Browse the repository at this point in the history
Update GFM release to `0.29.0.gfm.2`
  • Loading branch information
gjtorikian committed Sep 17, 2021
2 parents c44b825 + 3fb4f9c commit f30f525
Show file tree
Hide file tree
Showing 13 changed files with 627 additions and 744 deletions.
15 changes: 13 additions & 2 deletions ext/commonmarker/blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@ static void process_footnotes(cmark_parser *parser) {
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);
}
}
Expand All @@ -485,6 +484,15 @@ static void process_footnotes(cmark_parser *parser) {
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);
Expand Down Expand Up @@ -515,13 +523,16 @@ static void process_footnotes(cmark_parser *parser) {
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);
}

Expand Down
4 changes: 2 additions & 2 deletions ext/commonmarker/cmark-gfm_version.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef CMARK_GFM_VERSION_H
#define CMARK_GFM_VERSION_H

#define CMARK_GFM_VERSION ((0 << 24) | (29 << 16) | (0 << 8) | 0)
#define CMARK_GFM_VERSION_STRING "0.29.0.gfm.0"
#define CMARK_GFM_VERSION ((0 << 24) | (29 << 16) | (0 << 8) | 2)
#define CMARK_GFM_VERSION_STRING "0.29.0.gfm.2"

#endif
18 changes: 14 additions & 4 deletions ext/commonmarker/commonmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,13 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
case CMARK_NODE_FOOTNOTE_REFERENCE:
if (entering) {
LIT("[^");
OUT(cmark_chunk_to_cstr(renderer->mem, &node->as.literal), false, LITERAL);

char *footnote_label = renderer->mem->calloc(node->parent_footnote_def->as.literal.len + 1, sizeof(char));
memmove(footnote_label, node->parent_footnote_def->as.literal.data, node->parent_footnote_def->as.literal.len);

OUT(footnote_label, false, LITERAL);
renderer->mem->free(footnote_label);

LIT("]");
}
break;
Expand All @@ -486,9 +492,13 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
if (entering) {
renderer->footnote_ix += 1;
LIT("[^");
char n[32];
snprintf(n, sizeof(n), "%d", renderer->footnote_ix);
OUT(n, false, LITERAL);

char *footnote_label = renderer->mem->calloc(node->as.literal.len + 1, sizeof(char));
memmove(footnote_label, node->as.literal.data, node->as.literal.len);

OUT(footnote_label, false, LITERAL);
renderer->mem->free(footnote_label);

LIT("]:\n");

cmark_strbuf_puts(renderer->prefix, " ");
Expand Down

0 comments on commit f30f525

Please sign in to comment.