Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,17 @@ static cmark_node *finalize(cmark_parser *parser, cmark_node *b) {
b->data = cmark_strbuf_detach(node_content);
break;

case CMARK_NODE_ITEM:
if (parent->as.list.list_type != CMARK_ORDERED_LIST)
break;

if (b->prev == NULL)
b->as.item.number = parent->as.list.start;
else
b->as.item.number = b->prev->as.item.number + 1;

break;

case CMARK_NODE_LIST: // determine tight/loose status
b->as.list.tight = true; // tight by default
item = b->first_child;
Expand Down
4 changes: 4 additions & 0 deletions src/cmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ CMARK_EXPORT int cmark_node_get_list_tight(cmark_node *node);
*/
CMARK_EXPORT int cmark_node_set_list_tight(cmark_node *node, int tight);

/** Returns the list item number of 'node' or 0 if it is not an ordered list.
*/
CMARK_EXPORT int cmark_node_get_item_number(cmark_node *node);

/** Returns the info string from a fenced code block.
*/
CMARK_EXPORT const char *cmark_node_get_fence_info(cmark_node *node);
Expand Down
10 changes: 10 additions & 0 deletions src/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,16 @@ int cmark_node_set_list_tight(cmark_node *node, int tight) {
}
}

int cmark_node_get_item_number(cmark_node *node) {
if (node == NULL)
return 0;

if (node->type == CMARK_NODE_ITEM)
return node->as.item.number;
else
return 0;
}

const char *cmark_node_get_fence_info(cmark_node *node) {
if (node == NULL) {
return NULL;
Expand Down
5 changes: 5 additions & 0 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ typedef struct {
bool setext;
} cmark_heading;

typedef struct {
int number;
} cmark_item;

typedef struct {
unsigned char *url;
unsigned char *title;
Expand Down Expand Up @@ -78,6 +82,7 @@ struct cmark_node {
cmark_list list;
cmark_code code;
cmark_heading heading;
cmark_item item;
cmark_link link;
cmark_custom custom;
int html_block_type;
Expand Down