Skip to content

fix nested ordered lists with more than 10 items #104

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

Merged

Conversation

brunopagno
Copy link
Contributor

Ticket

https://community.openproject.org/projects/communicator-stream/work_packages/64414/activity

What are you trying to accomplish?

Fix an issue where nested ordered lists with more than 10 items would break when persisted.

Screenshots

image

What approach did you choose and why?

Based on turndown.js implementation of conversion of list items, make the indentation 5 spaces instead of 4. This allows the commonmarker gem used on OpenProject to properly parse large nested ordered lists.

Merge checklist

  • Added/updated tests
  • Tested major browsers (Chrome, Firefox, Edge, ...)

Copy link
Member

@akabiru akabiru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Structure looks good to me 👍🏾 Just one q: on the "5 spaces" fix

content = content
.replace(/^\n+/, '') // remove leading newlines
.replace(/\n+$/, '\n') // replace trailing newlines with just a single one
.replace(/\n/gm, '\n ') // indent with five spaces (five is important)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow why "5" spaces is important. Should we expound on that a bit more in the comment or fn description?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, 5 spaces is a quick fix. And kinda brute forcing things

1.  list item
2.  list item 2
    - sub item # this works, because the `-` is indented with four spaces, two more than the `2.`
...
10.  list item 10
    - sub item # this does not work, because the `-` is indented four spaces, only a single space over the `10.`. So we need 5 here instead`

So, forcing 5 spaces kinda fixes lists until 100 😬

But I probably can make an algorithm that will handle more gracefully the indentation width.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And fixed~

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, much more clear. And really nice one on the unit tests! 🥇

@brunopagno brunopagno force-pushed the fix/64414-allow-long-ordered-lists-with-nested-items branch from 09554b6 to 4c6e5ba Compare July 8, 2025 08:22
@brunopagno brunopagno force-pushed the fix/64414-allow-long-ordered-lists-with-nested-items branch from 4c6e5ba to 828b25b Compare July 8, 2025 08:36
@brunopagno brunopagno merged commit 733e5cf into master Jul 8, 2025
4 checks passed
@brunopagno brunopagno deleted the fix/64414-allow-long-ordered-lists-with-nested-items branch July 8, 2025 08:45
/**
* This rule is used to convert ordered list items to markdown.
*
* This is based on he turndownService rule for listItems, but modified to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* This is based on he turndownService rule for listItems, but modified to
* This is based on the turndownService rule for listItems, but modified to

content = content
.replace(/^\n+/, '') // remove leading newlines
.replace(/\n+$/, '\n') // replace trailing newlines with just a single one
.replace(/\n/gm, '\n ') // indent with five spaces (five is important)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, much more clear. And really nice one on the unit tests! 🥇

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

Successfully merging this pull request may close these issues.

2 participants