Extend the ListItem interface with ordered and index
Describe the feature Extend the ListItem interface with two additional fields:
{
ordered: boolean;
index: number;
}
-
ordered: Indicates whether the parent List is ordered. -
index: Represents the starting index plus the item's index.
Why is this feature necessary?
Android's TextView does not support ordered lists natively. To work around this limitation, I need to simulate ordered lists using <span> and <br/> tags. This feature will facilitate that process. You can find more details in the Styling with HTML markup documentation.
Describe alternatives you've considered
Currently, I have to parse the body of the list and manually mark each item in the listitem:
{
listitem(text: string, task: boolean, checked: boolean): string {
return text.trim() + '__LIST_ITEM__';
},
list(body: string, ordered: boolean, start: number | ''): string {
const items = body.split('__LIST_ITEM__');
// Ugly workaround
}
}
I have reviewed the marked.js code and believe that this feature should be straightforward to implement.
That sounds good to me. Do you want to create a PR to implement it?
This could also be done with walkTokens. Something like:
const walkTokens = (token) => {
if (token.type === 'list') {
token.listItems.forEach((item, idx) => {
item.ordered = token.ordered;
item.index = idx;
})
}
}
marked use({walkTokens})
with marked v13+ the whole token is sent to the renderer so any changes in walkTokens will make it to the renderer
That sounds good to me. Do you want to create a PR to implement it?
Yes, I do. I will prepare a PR with the described change.
This could also be done with walkTokens. Something like:
Thank you, it will look much better for the time being.
@pejas Have you fixed this issue ?
@tmatheas this is not fixed in marked
See https://github.com/markedjs/marked/issues/3359#issuecomment-2209320597 for a way to add properties with an extension. Or feel free to submit a PR to add the properties
@pejas @tmatheas @UziTech Has this issue been resolved.If not, I would like to work on this issue.
@pejas @tmatheas @UziTech Has this issue been resolved.If not, I would like to work on this issue.
Feel free I've used a walk tree workaround and this ticket just sits in my backlog with a low priority.
closing this as it can easily be an extension so users can opt-in if they need it. see https://github.com/markedjs/marked/issues/3359#issuecomment-2209320597