diff --git a/ext/commonmarker/arena.c b/ext/commonmarker/arena.c index 6373c0d0..da1a70e9 100644 --- a/ext/commonmarker/arena.c +++ b/ext/commonmarker/arena.c @@ -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; } diff --git a/ext/commonmarker/autolink.c b/ext/commonmarker/autolink.c index f3b75a7e..491d96c3 100644 --- a/ext/commonmarker/autolink.c +++ b/ext/commonmarker/autolink.c @@ -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; } diff --git a/ext/commonmarker/cmark-gfm-core-extensions.h b/ext/commonmarker/cmark-gfm-core-extensions.h index 0645915f..bc29ffd4 100644 --- a/ext/commonmarker/cmark-gfm-core-extensions.h +++ b/ext/commonmarker/cmark-gfm-core-extensions.h @@ -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 #include -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 diff --git a/ext/commonmarker/cmark-gfm.h b/ext/commonmarker/cmark-gfm.h index 6fb28693..6b362a86 100644 --- a/ext/commonmarker/cmark-gfm.h +++ b/ext/commonmarker/cmark-gfm.h @@ -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. @@ -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 * diff --git a/ext/commonmarker/cmark-upstream b/ext/commonmarker/cmark-upstream index 57d5e093..c32ef78b 160000 --- a/ext/commonmarker/cmark-upstream +++ b/ext/commonmarker/cmark-upstream @@ -1 +1 @@ -Subproject commit 57d5e093ef801f54bf4174c900f7a863599bb47d +Subproject commit c32ef78bae851cb83b7ad52d0fbff880acdcd44a diff --git a/ext/commonmarker/cmark.c b/ext/commonmarker/cmark.c index b3fad4b0..68c40c47 100644 --- a/ext/commonmarker/cmark.c +++ b/ext/commonmarker/cmark.c @@ -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); @@ -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; } diff --git a/ext/commonmarker/html.c b/ext/commonmarker/html.c index 12d3c3e9..529e0ea3 100644 --- a/ext/commonmarker/html.c +++ b/ext/commonmarker/html.c @@ -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, "as.literal.data, node->as.literal.len); - cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩"); + 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, "\">↩"); if (node->footnote.def_count > 1) { @@ -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\">↩"); + 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, "\">↩"); cmark_strbuf_puts(html, n); cmark_strbuf_puts(html, ""); } diff --git a/ext/commonmarker/node.c b/ext/commonmarker/node.c index 80c434e3..56daf0aa 100644 --- a/ext/commonmarker/node.c +++ b/ext/commonmarker/node.c @@ -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. @@ -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) { @@ -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; diff --git a/ext/commonmarker/node.h b/ext/commonmarker/node.h index 281258f7..e025e25d 100644 --- a/ext/commonmarker/node.h +++ b/ext/commonmarker/node.h @@ -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; @@ -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; @@ -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(); diff --git a/ext/commonmarker/table.c b/ext/commonmarker/table.c index 7f281322..e53ea315 100644 --- a/ext/commonmarker/table.c +++ b/ext/commonmarker/table.c @@ -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; diff --git a/lib/commonmarker/version.rb b/lib/commonmarker/version.rb index 7d03a7ea..6405511f 100644 --- a/lib/commonmarker/version.rb +++ b/lib/commonmarker/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module CommonMarker - VERSION = "0.23.7" + VERSION = "0.23.8" end diff --git a/test/test_footnotes.rb b/test/test_footnotes.rb index 7cdfd93a..0e00a913 100644 --- a/test/test_footnotes.rb +++ b/test/test_footnotes.rb @@ -13,7 +13,7 @@ def test_to_html
  1. -

    Hey!

    +

    Hey!

@@ -50,7 +50,7 @@ def test_render_html
  1. -

    This is a footnote

    +

    This is a footnote