Skip to content

Commit f5c77c6

Browse files
NightFlyerAshe Connor
authored andcommitted
Make "set" methods public, add "set" method for tasklist (commonmark#162)
Also rename "get" method for tasklist to better match others.
1 parent 438f3b2 commit f5c77c6

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

extensions/cmark-gfm-core-extensions.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extern "C" {
77

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

1313
CMARK_GFM_EXTENSIONS_EXPORT
@@ -16,14 +16,36 @@ void cmark_gfm_core_extensions_ensure_registered(void);
1616
CMARK_GFM_EXTENSIONS_EXPORT
1717
uint16_t cmark_gfm_extensions_get_table_columns(cmark_node *node);
1818

19+
/** Sets the number of columns for the table, returning 1 on success and 0 on error.
20+
*/
21+
CMARK_GFM_EXTENSIONS_EXPORT
22+
int cmark_gfm_extensions_set_table_columns(cmark_node *node, uint16_t n_columns);
23+
1924
CMARK_GFM_EXTENSIONS_EXPORT
2025
uint8_t *cmark_gfm_extensions_get_table_alignments(cmark_node *node);
2126

27+
/** Sets the alignments for the table, returning 1 on success and 0 on error.
28+
*/
29+
CMARK_GFM_EXTENSIONS_EXPORT
30+
int cmark_gfm_extensions_set_table_alignments(cmark_node *node, uint16_t ncols, uint8_t *alignments);
31+
2232
CMARK_GFM_EXTENSIONS_EXPORT
2333
int cmark_gfm_extensions_get_table_row_is_header(cmark_node *node);
2434

35+
/** Sets whether the node is a table header row, returning 1 on success and 0 on error.
36+
*/
37+
CMARK_GFM_EXTENSIONS_EXPORT
38+
int cmark_gfm_extensions_set_table_row_is_header(cmark_node *node, int is_header);
39+
40+
CMARK_GFM_EXTENSIONS_EXPORT
41+
bool cmark_gfm_extensions_get_tasklist_item_checked(cmark_node *node);
42+
/* For backwards compatibility */
43+
#define cmark_gfm_extensions_tasklist_is_checked cmark_gfm_extensions_get_tasklist_item_checked
44+
45+
/** Sets whether a tasklist item is "checked" (completed), returning 1 on success and 0 on error.
46+
*/
2547
CMARK_GFM_EXTENSIONS_EXPORT
26-
bool cmark_gfm_extensions_tasklist_state_is_checked(cmark_node *node);
48+
int cmark_gfm_extensions_set_tasklist_item_checked(cmark_node *node, bool is_checked);
2749

2850
#ifdef __cplusplus
2951
}

extensions/tasklist.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,24 @@ static const char *get_type_string(cmark_syntax_extension *extension, cmark_node
1616
return TYPE_STRING;
1717
}
1818

19-
bool cmark_gfm_extensions_tasklist_state_is_checked(cmark_node *node) {
19+
20+
// Return 1 if state was set, 0 otherwise
21+
int cmark_gfm_extensions_set_tasklist_item_checked(cmark_node *node, bool is_checked) {
22+
// The node has to exist, and be an extension, and actually be the right type in order to get the value.
23+
if (!node || !node->extension || strcmp(cmark_node_get_type_string(node), TYPE_STRING))
24+
return 0;
25+
26+
if (is_checked) {
27+
node->as.opaque = (void *)CMARK_TASKLIST_CHECKED;
28+
return 1;
29+
}
30+
else {
31+
node->as.opaque = (void *)CMARK_TASKLIST_NOCHECKED;
32+
return 1;
33+
}
34+
}
35+
36+
bool cmark_gfm_extensions_get_tasklist_item_checked(cmark_node *node) {
2037
if (!node || !node->extension || strcmp(cmark_node_get_type_string(node), TYPE_STRING))
2138
return false;
2239

0 commit comments

Comments
 (0)