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

Fix quadratic list indexing in commonmark/man/plaintext output formats #322

Merged
merged 3 commits into from
Apr 3, 2023

Conversation

kevinbackhouse
Copy link

Fixes: #321

This adds some code to cmark_render() to calculate the correct list item index and store it on the node, so that output formats like commonmark don't have to calculate it themselves.

Nodes of type CMARK_NODE_ITEM store the same kind of data as CMARK_NODE_LIST, as can be seen here:

cmark-gfm/src/blocks.c

Lines 1371 to 1376 in c4de252

// add the list item
*container = add_child(parser, *container, CMARK_NODE_ITEM,
parser->first_nonspace + 1);
/* TODO: static */
memcpy(&((*container)->as.list), data, sizeof(*data));
parser->mem->free(data);

So I decided to use the start field to store the index.

@gravypod
Copy link

gravypod commented Apr 3, 2023

@kevinbackhouse, for what it's worth this passes our internal test suite. I am not a huge fan of how list numbers are calculated in the main render loop, and not at parse time, but I think that can be improved in future PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

commonmark list numbering is incorrect
3 participants