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 cmark-upstream to 0.29.0.gfm.9 #227

Merged
merged 3 commits into from
Jan 31, 2023
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
2 changes: 1 addition & 1 deletion ext/commonmarker/arena.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ static void arena_free(void *ptr) {

cmark_mem CMARK_ARENA_MEM_ALLOCATOR = {arena_calloc, arena_realloc, arena_free};

cmark_mem *cmark_get_arena_mem_allocator() {
cmark_mem *cmark_get_arena_mem_allocator(void) {
return &CMARK_ARENA_MEM_ALLOCATOR;
}
5 changes: 5 additions & 0 deletions ext/commonmarker/autolink.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ static cmark_node *url_match(cmark_parser *parser, cmark_node *parent,
cmark_node *text = cmark_node_new_with_mem(CMARK_NODE_TEXT, parser->mem);
text->as.literal = url;
cmark_node_append_child(node, text);

node->start_line = text->start_line = node->end_line = text->end_line = cmark_inline_parser_get_line(inline_parser);

node->start_column = text->start_column = max_rewind - rewind;
node->end_column = text->end_column = cmark_inline_parser_get_column(inline_parser) - 1;

return node;
}
Expand Down
22 changes: 11 additions & 11 deletions ext/commonmarker/cmark-gfm-core-extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,45 @@ extern "C" {
#endif

#include "cmark-gfm-extension_api.h"
#include "cmark-gfm-extensions_export.h"
#include "config.h" // for bool
#include "cmark-gfm_export.h"
#include <stdbool.h>
#include <stdint.h>

CMARK_GFM_EXTENSIONS_EXPORT
CMARK_GFM_EXPORT
void cmark_gfm_core_extensions_ensure_registered(void);

CMARK_GFM_EXTENSIONS_EXPORT
CMARK_GFM_EXPORT
uint16_t cmark_gfm_extensions_get_table_columns(cmark_node *node);

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

CMARK_GFM_EXTENSIONS_EXPORT
CMARK_GFM_EXPORT
uint8_t *cmark_gfm_extensions_get_table_alignments(cmark_node *node);

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

CMARK_GFM_EXTENSIONS_EXPORT
CMARK_GFM_EXPORT
int cmark_gfm_extensions_get_table_row_is_header(cmark_node *node);

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

CMARK_GFM_EXTENSIONS_EXPORT
CMARK_GFM_EXPORT
bool cmark_gfm_extensions_get_tasklist_item_checked(cmark_node *node);
/* For backwards compatibility */
#define cmark_gfm_extensions_tasklist_is_checked cmark_gfm_extensions_get_tasklist_item_checked

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

#ifdef __cplusplus
Expand Down
9 changes: 7 additions & 2 deletions ext/commonmarker/cmark-gfm.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ typedef struct cmark_mem {
* realloc and free.
*/
CMARK_GFM_EXPORT
cmark_mem *cmark_get_default_mem_allocator();
cmark_mem *cmark_get_default_mem_allocator(void);

/** An arena allocator; uses system calloc to allocate large
* slabs of memory. Memory in these slabs is not reused at all.
*/
CMARK_GFM_EXPORT
cmark_mem *cmark_get_arena_mem_allocator();
cmark_mem *cmark_get_arena_mem_allocator(void);

/** Resets the arena allocator, quickly returning all used memory
* to the operating system.
Expand Down Expand Up @@ -225,6 +225,11 @@ CMARK_GFM_EXPORT cmark_node *cmark_node_first_child(cmark_node *node);
*/
CMARK_GFM_EXPORT cmark_node *cmark_node_last_child(cmark_node *node);

/** Returns the footnote reference of 'node', or NULL if 'node' doesn't have a
* footnote reference.
*/
CMARK_GFM_EXPORT cmark_node *cmark_node_parent_footnote_def(cmark_node *node);

/**
* ## Iterator
*
Expand Down
6 changes: 3 additions & 3 deletions ext/commonmarker/cmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
cmark_node_type CMARK_NODE_LAST_BLOCK = CMARK_NODE_FOOTNOTE_DEFINITION;
cmark_node_type CMARK_NODE_LAST_INLINE = CMARK_NODE_FOOTNOTE_REFERENCE;

int cmark_version() { return CMARK_GFM_VERSION; }
int cmark_version(void) { return CMARK_GFM_VERSION; }

const char *cmark_version_string() { return CMARK_GFM_VERSION_STRING; }
const char *cmark_version_string(void) { return CMARK_GFM_VERSION_STRING; }

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

cmark_mem CMARK_DEFAULT_MEM_ALLOCATOR = {xcalloc, xrealloc, xfree};

cmark_mem *cmark_get_default_mem_allocator() {
cmark_mem *cmark_get_default_mem_allocator(void) {
return &CMARK_DEFAULT_MEM_ALLOCATOR;
}

Expand Down
18 changes: 16 additions & 2 deletions ext/commonmarker/html.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,16 @@ static bool S_put_footnote_backref(cmark_html_renderer *renderer, cmark_strbuf *
if (renderer->written_footnote_ix >= renderer->footnote_ix)
return false;
renderer->written_footnote_ix = renderer->footnote_ix;
char m[32];
snprintf(m, sizeof(m), "%d", renderer->written_footnote_ix);

cmark_strbuf_puts(html, "<a href=\"#fnref-");
houdini_escape_href(html, node->as.literal.data, node->as.literal.len);
cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩</a>");
cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"");
cmark_strbuf_puts(html, m);
cmark_strbuf_puts(html, "\" aria-label=\"Back to reference ");
cmark_strbuf_puts(html, m);
cmark_strbuf_puts(html, "\">↩</a>");

if (node->footnote.def_count > 1)
{
Expand All @@ -78,7 +84,15 @@ static bool S_put_footnote_backref(cmark_html_renderer *renderer, cmark_strbuf *
houdini_escape_href(html, node->as.literal.data, node->as.literal.len);
cmark_strbuf_puts(html, "-");
cmark_strbuf_puts(html, n);
cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩<sup class=\"footnote-ref\">");
cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"");
cmark_strbuf_puts(html, m);
cmark_strbuf_puts(html, "-");
cmark_strbuf_puts(html, n);
cmark_strbuf_puts(html, "\" aria-label=\"Back to reference ");
cmark_strbuf_puts(html, m);
cmark_strbuf_puts(html, "-");
cmark_strbuf_puts(html, n);
cmark_strbuf_puts(html, "\">↩<sup class=\"footnote-ref\">");
cmark_strbuf_puts(html, n);
cmark_strbuf_puts(html, "</sup></a>");
}
Expand Down
32 changes: 14 additions & 18 deletions ext/commonmarker/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ static void S_node_unlink(cmark_node *node);

#define NODE_MEM(node) cmark_node_mem(node)

cmark_node__internal_flags CMARK_NODE__OPEN;
cmark_node__internal_flags CMARK_NODE__LAST_LINE_BLANK;
cmark_node__internal_flags CMARK_NODE__LAST_LINE_CHECKED;

void cmark_register_node_flag(cmark_node__internal_flags *flags) {
static uint8_t shift = 0;
void cmark_register_node_flag(cmark_node_internal_flags *flags) {
static cmark_node_internal_flags nextflag = CMARK_NODE__REGISTER_FIRST;

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

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

*flags = (cmark_node__internal_flags)1 << shift;
shift++;
*flags = nextflag;
nextflag <<= 1;
}

void cmark_init_standard_node_flags() {
static int initialized = 0;
if (!initialized) {
initialized = 1;
cmark_register_node_flag(&CMARK_NODE__OPEN);
cmark_register_node_flag(&CMARK_NODE__LAST_LINE_BLANK);
cmark_register_node_flag(&CMARK_NODE__LAST_LINE_CHECKED);
}
}
void cmark_init_standard_node_flags() {}

bool cmark_node_can_contain_type(cmark_node *node, cmark_node_type child_type) {
if (child_type == CMARK_NODE_DOCUMENT) {
Expand Down Expand Up @@ -335,6 +323,14 @@ cmark_node *cmark_node_last_child(cmark_node *node) {
}
}

cmark_node *cmark_node_parent_footnote_def(cmark_node *node) {
if (node == NULL) {
return NULL;
} else {
return node->parent_footnote_def;
}
}

void *cmark_node_get_user_data(cmark_node *node) {
if (node == NULL) {
return NULL;
Expand Down
32 changes: 19 additions & 13 deletions ext/commonmarker/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,17 @@ typedef struct {
cmark_chunk on_exit;
} cmark_custom;

typedef uint16_t cmark_node__internal_flags;
enum cmark_node__internal_flags {
CMARK_NODE__OPEN = (1 << 0),
CMARK_NODE__LAST_LINE_BLANK = (1 << 1),
CMARK_NODE__LAST_LINE_CHECKED = (1 << 2),

// Extensions can register custom flags by calling `cmark_register_node_flag`.
// This is the starting value for the custom flags.
CMARK_NODE__REGISTER_FIRST = (1 << 3),
};

typedef uint16_t cmark_node_internal_flags;

struct cmark_node {
cmark_strbuf content;
Expand All @@ -68,7 +78,7 @@ struct cmark_node {
int end_column;
int internal_offset;
uint16_t type;
cmark_node__internal_flags flags;
cmark_node_internal_flags flags;

cmark_syntax_extension *extension;

Expand Down Expand Up @@ -98,19 +108,15 @@ struct cmark_node {
* which will store the flag value.
*/
CMARK_GFM_EXPORT
void cmark_register_node_flag(cmark_node__internal_flags *flags);

/**
* Standard node flags. (Initialized using `cmark_init_standard_node_flags`.)
*/
extern cmark_node__internal_flags CMARK_NODE__OPEN;
extern cmark_node__internal_flags CMARK_NODE__LAST_LINE_BLANK;
extern cmark_node__internal_flags CMARK_NODE__LAST_LINE_CHECKED;
void cmark_register_node_flag(cmark_node_internal_flags *flags);

/**
* Uses `cmark_register_node_flag` to initialize the standard node flags.
* This function should be called at program startup time. Calling it
* multiple times has no additional effect.
* DEPRECATED.
*
* This function was added in cmark-gfm version 0.29.0.gfm.7, and was
* required to be called at program start time, which caused
* backwards-compatibility issues in applications that use cmark-gfm as a
* library. It is now a no-op.
*/
CMARK_GFM_EXPORT
void cmark_init_standard_node_flags();
Expand Down
2 changes: 1 addition & 1 deletion ext/commonmarker/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "cmark-gfm-core-extensions.h"

// Custom node flag, initialized in `create_table_extension`.
static cmark_node__internal_flags CMARK_NODE__TABLE_VISITED;
static cmark_node_internal_flags CMARK_NODE__TABLE_VISITED;

cmark_node_type CMARK_NODE_TABLE, CMARK_NODE_TABLE_ROW,
CMARK_NODE_TABLE_CELL;
Expand Down
2 changes: 1 addition & 1 deletion lib/commonmarker/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module CommonMarker
VERSION = "0.23.7"
VERSION = "0.23.8"
end
4 changes: 2 additions & 2 deletions test/test_footnotes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_to_html
<section class="footnotes" data-footnotes>
<ol>
<li id="fn-hi">
<p>Hey! <a href="#fnref-hi" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩</a></p>
<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>
</li>
</ol>
</section>
Expand Down Expand Up @@ -50,7 +50,7 @@ def test_render_html
<section class="footnotes" data-footnotes>
<ol>
<li id="fn-1">
<p>This is a footnote <a href="#fnref-1" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩</a></p>
<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>
</li>
</ol>
</section>
Expand Down