Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GFM release to 0.29.0.gfm.2 #148

Merged
merged 3 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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