Skip to content

Commit 94c0af9

Browse files
authored
Merge pull request #227 from gjtorikian/update-to-0.29.0.gfm.9
Update cmark-upstream to `0.29.0.gfm.9`
2 parents 734fd86 + 5249f70 commit 94c0af9

File tree

12 files changed

+81
-55
lines changed

12 files changed

+81
-55
lines changed

ext/commonmarker/arena.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,6 @@ static void arena_free(void *ptr) {
9999

100100
cmark_mem CMARK_ARENA_MEM_ALLOCATOR = {arena_calloc, arena_realloc, arena_free};
101101

102-
cmark_mem *cmark_get_arena_mem_allocator() {
102+
cmark_mem *cmark_get_arena_mem_allocator(void) {
103103
return &CMARK_ARENA_MEM_ALLOCATOR;
104104
}

ext/commonmarker/autolink.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ static cmark_node *url_match(cmark_parser *parser, cmark_node *parent,
267267
cmark_node *text = cmark_node_new_with_mem(CMARK_NODE_TEXT, parser->mem);
268268
text->as.literal = url;
269269
cmark_node_append_child(node, text);
270+
271+
node->start_line = text->start_line = node->end_line = text->end_line = cmark_inline_parser_get_line(inline_parser);
272+
273+
node->start_column = text->start_column = max_rewind - rewind;
274+
node->end_column = text->end_column = cmark_inline_parser_get_column(inline_parser) - 1;
270275

271276
return node;
272277
}

ext/commonmarker/cmark-gfm-core-extensions.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,45 @@ extern "C" {
66
#endif
77

88
#include "cmark-gfm-extension_api.h"
9-
#include "cmark-gfm-extensions_export.h"
10-
#include "config.h" // for bool
9+
#include "cmark-gfm_export.h"
10+
#include <stdbool.h>
1111
#include <stdint.h>
1212

13-
CMARK_GFM_EXTENSIONS_EXPORT
13+
CMARK_GFM_EXPORT
1414
void cmark_gfm_core_extensions_ensure_registered(void);
1515

16-
CMARK_GFM_EXTENSIONS_EXPORT
16+
CMARK_GFM_EXPORT
1717
uint16_t cmark_gfm_extensions_get_table_columns(cmark_node *node);
1818

1919
/** Sets the number of columns for the table, returning 1 on success and 0 on error.
2020
*/
21-
CMARK_GFM_EXTENSIONS_EXPORT
21+
CMARK_GFM_EXPORT
2222
int cmark_gfm_extensions_set_table_columns(cmark_node *node, uint16_t n_columns);
2323

24-
CMARK_GFM_EXTENSIONS_EXPORT
24+
CMARK_GFM_EXPORT
2525
uint8_t *cmark_gfm_extensions_get_table_alignments(cmark_node *node);
2626

2727
/** Sets the alignments for the table, returning 1 on success and 0 on error.
2828
*/
29-
CMARK_GFM_EXTENSIONS_EXPORT
29+
CMARK_GFM_EXPORT
3030
int cmark_gfm_extensions_set_table_alignments(cmark_node *node, uint16_t ncols, uint8_t *alignments);
3131

32-
CMARK_GFM_EXTENSIONS_EXPORT
32+
CMARK_GFM_EXPORT
3333
int cmark_gfm_extensions_get_table_row_is_header(cmark_node *node);
3434

3535
/** Sets whether the node is a table header row, returning 1 on success and 0 on error.
3636
*/
37-
CMARK_GFM_EXTENSIONS_EXPORT
37+
CMARK_GFM_EXPORT
3838
int cmark_gfm_extensions_set_table_row_is_header(cmark_node *node, int is_header);
3939

40-
CMARK_GFM_EXTENSIONS_EXPORT
40+
CMARK_GFM_EXPORT
4141
bool cmark_gfm_extensions_get_tasklist_item_checked(cmark_node *node);
4242
/* For backwards compatibility */
4343
#define cmark_gfm_extensions_tasklist_is_checked cmark_gfm_extensions_get_tasklist_item_checked
4444

4545
/** Sets whether a tasklist item is "checked" (completed), returning 1 on success and 0 on error.
4646
*/
47-
CMARK_GFM_EXTENSIONS_EXPORT
47+
CMARK_GFM_EXPORT
4848
int cmark_gfm_extensions_set_tasklist_item_checked(cmark_node *node, bool is_checked);
4949

5050
#ifdef __cplusplus

ext/commonmarker/cmark-gfm.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ typedef struct cmark_mem {
111111
* realloc and free.
112112
*/
113113
CMARK_GFM_EXPORT
114-
cmark_mem *cmark_get_default_mem_allocator();
114+
cmark_mem *cmark_get_default_mem_allocator(void);
115115

116116
/** An arena allocator; uses system calloc to allocate large
117117
* slabs of memory. Memory in these slabs is not reused at all.
118118
*/
119119
CMARK_GFM_EXPORT
120-
cmark_mem *cmark_get_arena_mem_allocator();
120+
cmark_mem *cmark_get_arena_mem_allocator(void);
121121

122122
/** Resets the arena allocator, quickly returning all used memory
123123
* to the operating system.
@@ -225,6 +225,11 @@ CMARK_GFM_EXPORT cmark_node *cmark_node_first_child(cmark_node *node);
225225
*/
226226
CMARK_GFM_EXPORT cmark_node *cmark_node_last_child(cmark_node *node);
227227

228+
/** Returns the footnote reference of 'node', or NULL if 'node' doesn't have a
229+
* footnote reference.
230+
*/
231+
CMARK_GFM_EXPORT cmark_node *cmark_node_parent_footnote_def(cmark_node *node);
232+
228233
/**
229234
* ## Iterator
230235
*

ext/commonmarker/cmark.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
cmark_node_type CMARK_NODE_LAST_BLOCK = CMARK_NODE_FOOTNOTE_DEFINITION;
1111
cmark_node_type CMARK_NODE_LAST_INLINE = CMARK_NODE_FOOTNOTE_REFERENCE;
1212

13-
int cmark_version() { return CMARK_GFM_VERSION; }
13+
int cmark_version(void) { return CMARK_GFM_VERSION; }
1414

15-
const char *cmark_version_string() { return CMARK_GFM_VERSION_STRING; }
15+
const char *cmark_version_string(void) { return CMARK_GFM_VERSION_STRING; }
1616

1717
static void *xcalloc(size_t nmem, size_t size) {
1818
void *ptr = calloc(nmem, size);
@@ -38,7 +38,7 @@ static void xfree(void *ptr) {
3838

3939
cmark_mem CMARK_DEFAULT_MEM_ALLOCATOR = {xcalloc, xrealloc, xfree};
4040

41-
cmark_mem *cmark_get_default_mem_allocator() {
41+
cmark_mem *cmark_get_default_mem_allocator(void) {
4242
return &CMARK_DEFAULT_MEM_ALLOCATOR;
4343
}
4444

ext/commonmarker/html.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,16 @@ static bool S_put_footnote_backref(cmark_html_renderer *renderer, cmark_strbuf *
6363
if (renderer->written_footnote_ix >= renderer->footnote_ix)
6464
return false;
6565
renderer->written_footnote_ix = renderer->footnote_ix;
66+
char m[32];
67+
snprintf(m, sizeof(m), "%d", renderer->written_footnote_ix);
6668

6769
cmark_strbuf_puts(html, "<a href=\"#fnref-");
6870
houdini_escape_href(html, node->as.literal.data, node->as.literal.len);
69-
cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩</a>");
71+
cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"");
72+
cmark_strbuf_puts(html, m);
73+
cmark_strbuf_puts(html, "\" aria-label=\"Back to reference ");
74+
cmark_strbuf_puts(html, m);
75+
cmark_strbuf_puts(html, "\">↩</a>");
7076

7177
if (node->footnote.def_count > 1)
7278
{
@@ -78,7 +84,15 @@ static bool S_put_footnote_backref(cmark_html_renderer *renderer, cmark_strbuf *
7884
houdini_escape_href(html, node->as.literal.data, node->as.literal.len);
7985
cmark_strbuf_puts(html, "-");
8086
cmark_strbuf_puts(html, n);
81-
cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩<sup class=\"footnote-ref\">");
87+
cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"");
88+
cmark_strbuf_puts(html, m);
89+
cmark_strbuf_puts(html, "-");
90+
cmark_strbuf_puts(html, n);
91+
cmark_strbuf_puts(html, "\" aria-label=\"Back to reference ");
92+
cmark_strbuf_puts(html, m);
93+
cmark_strbuf_puts(html, "-");
94+
cmark_strbuf_puts(html, n);
95+
cmark_strbuf_puts(html, "\">↩<sup class=\"footnote-ref\">");
8296
cmark_strbuf_puts(html, n);
8397
cmark_strbuf_puts(html, "</sup></a>");
8498
}

ext/commonmarker/node.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@ static void S_node_unlink(cmark_node *node);
99

1010
#define NODE_MEM(node) cmark_node_mem(node)
1111

12-
cmark_node__internal_flags CMARK_NODE__OPEN;
13-
cmark_node__internal_flags CMARK_NODE__LAST_LINE_BLANK;
14-
cmark_node__internal_flags CMARK_NODE__LAST_LINE_CHECKED;
15-
16-
void cmark_register_node_flag(cmark_node__internal_flags *flags) {
17-
static uint8_t shift = 0;
12+
void cmark_register_node_flag(cmark_node_internal_flags *flags) {
13+
static cmark_node_internal_flags nextflag = CMARK_NODE__REGISTER_FIRST;
1814

1915
// flags should be a pointer to a global variable and this function
2016
// should only be called once to initialize its value.
@@ -24,24 +20,16 @@ void cmark_register_node_flag(cmark_node__internal_flags *flags) {
2420
}
2521

2622
// Check that we haven't run out of bits.
27-
if (shift >= 8 * sizeof(cmark_node__internal_flags)) {
23+
if (nextflag == 0) {
2824
fprintf(stderr, "too many flags in cmark_register_node_flag\n");
2925
abort();
3026
}
3127

32-
*flags = (cmark_node__internal_flags)1 << shift;
33-
shift++;
28+
*flags = nextflag;
29+
nextflag <<= 1;
3430
}
3531

36-
void cmark_init_standard_node_flags() {
37-
static int initialized = 0;
38-
if (!initialized) {
39-
initialized = 1;
40-
cmark_register_node_flag(&CMARK_NODE__OPEN);
41-
cmark_register_node_flag(&CMARK_NODE__LAST_LINE_BLANK);
42-
cmark_register_node_flag(&CMARK_NODE__LAST_LINE_CHECKED);
43-
}
44-
}
32+
void cmark_init_standard_node_flags() {}
4533

4634
bool cmark_node_can_contain_type(cmark_node *node, cmark_node_type child_type) {
4735
if (child_type == CMARK_NODE_DOCUMENT) {
@@ -335,6 +323,14 @@ cmark_node *cmark_node_last_child(cmark_node *node) {
335323
}
336324
}
337325

326+
cmark_node *cmark_node_parent_footnote_def(cmark_node *node) {
327+
if (node == NULL) {
328+
return NULL;
329+
} else {
330+
return node->parent_footnote_def;
331+
}
332+
}
333+
338334
void *cmark_node_get_user_data(cmark_node *node) {
339335
if (node == NULL) {
340336
return NULL;

ext/commonmarker/node.h

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,17 @@ typedef struct {
4848
cmark_chunk on_exit;
4949
} cmark_custom;
5050

51-
typedef uint16_t cmark_node__internal_flags;
51+
enum cmark_node__internal_flags {
52+
CMARK_NODE__OPEN = (1 << 0),
53+
CMARK_NODE__LAST_LINE_BLANK = (1 << 1),
54+
CMARK_NODE__LAST_LINE_CHECKED = (1 << 2),
55+
56+
// Extensions can register custom flags by calling `cmark_register_node_flag`.
57+
// This is the starting value for the custom flags.
58+
CMARK_NODE__REGISTER_FIRST = (1 << 3),
59+
};
60+
61+
typedef uint16_t cmark_node_internal_flags;
5262

5363
struct cmark_node {
5464
cmark_strbuf content;
@@ -68,7 +78,7 @@ struct cmark_node {
6878
int end_column;
6979
int internal_offset;
7080
uint16_t type;
71-
cmark_node__internal_flags flags;
81+
cmark_node_internal_flags flags;
7282

7383
cmark_syntax_extension *extension;
7484

@@ -98,19 +108,15 @@ struct cmark_node {
98108
* which will store the flag value.
99109
*/
100110
CMARK_GFM_EXPORT
101-
void cmark_register_node_flag(cmark_node__internal_flags *flags);
102-
103-
/**
104-
* Standard node flags. (Initialized using `cmark_init_standard_node_flags`.)
105-
*/
106-
extern cmark_node__internal_flags CMARK_NODE__OPEN;
107-
extern cmark_node__internal_flags CMARK_NODE__LAST_LINE_BLANK;
108-
extern cmark_node__internal_flags CMARK_NODE__LAST_LINE_CHECKED;
111+
void cmark_register_node_flag(cmark_node_internal_flags *flags);
109112

110113
/**
111-
* Uses `cmark_register_node_flag` to initialize the standard node flags.
112-
* This function should be called at program startup time. Calling it
113-
* multiple times has no additional effect.
114+
* DEPRECATED.
115+
*
116+
* This function was added in cmark-gfm version 0.29.0.gfm.7, and was
117+
* required to be called at program start time, which caused
118+
* backwards-compatibility issues in applications that use cmark-gfm as a
119+
* library. It is now a no-op.
114120
*/
115121
CMARK_GFM_EXPORT
116122
void cmark_init_standard_node_flags();

ext/commonmarker/table.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "cmark-gfm-core-extensions.h"
1313

1414
// Custom node flag, initialized in `create_table_extension`.
15-
static cmark_node__internal_flags CMARK_NODE__TABLE_VISITED;
15+
static cmark_node_internal_flags CMARK_NODE__TABLE_VISITED;
1616

1717
cmark_node_type CMARK_NODE_TABLE, CMARK_NODE_TABLE_ROW,
1818
CMARK_NODE_TABLE_CELL;

lib/commonmarker/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module CommonMarker
4-
VERSION = "0.23.7"
4+
VERSION = "0.23.8"
55
end

test/test_footnotes.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_to_html
1313
<section class="footnotes" data-footnotes>
1414
<ol>
1515
<li id="fn-hi">
16-
<p>Hey! <a href="#fnref-hi" class="footnote-backref" data-footnote-backref aria-label="Back to content"></a></p>
16+
<p>Hey! <a href="#fnref-hi" class="footnote-backref" data-footnote-backref data-footnote-backref-idx="1" aria-label="Back to reference 1"></a></p>
1717
</li>
1818
</ol>
1919
</section>
@@ -50,7 +50,7 @@ def test_render_html
5050
<section class="footnotes" data-footnotes>
5151
<ol>
5252
<li id="fn-1">
53-
<p>This is a footnote <a href="#fnref-1" class="footnote-backref" data-footnote-backref aria-label="Back to content"></a></p>
53+
<p>This is a footnote <a href="#fnref-1" class="footnote-backref" data-footnote-backref data-footnote-backref-idx="1" aria-label="Back to reference 1"></a></p>
5454
</li>
5555
</ol>
5656
</section>

0 commit comments

Comments
 (0)