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

Extend the ListItem interface with ordered and index #3359

Open
pejas opened this issue Jul 4, 2024 · 5 comments
Open

Extend the ListItem interface with ordered and index #3359

pejas opened this issue Jul 4, 2024 · 5 comments
Labels

Comments

@pejas
Copy link

pejas commented Jul 4, 2024

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.

@UziTech
Copy link
Member

UziTech commented Jul 4, 2024

That sounds good to me. Do you want to create a PR to implement it?

@UziTech
Copy link
Member

UziTech commented Jul 4, 2024

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

@pejas
Copy link
Author

pejas commented Jul 5, 2024

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.

@tmatheas
Copy link

tmatheas commented Oct 2, 2024

@pejas Have you fixed this issue ?

@UziTech
Copy link
Member

UziTech commented Oct 2, 2024

@tmatheas this is not fixed in marked

See #3359 (comment) for a way to add properties with an extension. Or feel free to submit a PR to add the properties

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

No branches or pull requests

3 participants