Expose Ability to Get the Number Of a List Item#600
Expose Ability to Get the Number Of a List Item#600bfoersterling wants to merge 1 commit intocommonmark:masterfrom
Conversation
- add cmark_node_get_item_number() function - store item number in cmark_item member Signed-off-by: Bjoern Foersterling <bjoern.foersterling@gmail.com>
|
@nwellnhof any objections to this? |
|
It seems trivial to count list items manually, so I don't think we need an additional API function. It might also be confusing that the returned values aren't guaranteed to match the values from the source file which don't have to be consecutive or increasing. For a input like 5. five
2. two
4. fourpeople might expect the function to return values 5, 2, 4 instead of 5, 6, 7. Besides, what should happen if the tree is updated? |
|
Thank you for the review.
But is that expectation correct for an ordered list and is it satisfied with the current implementation of In This example would produce this html when converted by And this renders in This would also mean, that the current implementation of The tags for the
I assume you mean the functions |
|
You are right about cmark behavior. I think the worry was that people might expect to get the number in the markdown source. So this could be a confusing feature. The question is whether it is worth adding complexity (which is always a negative) in order to facilitate something that can be done quite easily in a renderer or other processor by counting. I'm not convinced that it is. |
No, I meant what should happen if list items are added to or removed from the tree. Updating the list numbers can't be done in constant time. |
rationale
The function
cmark_node_get_item_number()improves the user friendlinessof the API as the library user does not have to implement a logic to derive
the number of a list item.
It is more efficient to store the item number once when parsing the markdown
content.
The function
cmark_node_get_item_numberonly has to look at the previousnode. The library user might need to traverse until the start of the list
if he does not want to store the item numbers in a separate data type.
implementation
I added the new type
cmark_itemand made it a union member for theasmember in
cmark_node.The item number is calculated and stored in the function
finalize().