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 for numbered list item when exporting to PDF, DOCX #1357

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mfanselmo
Copy link
Contributor

This PR #1326 introduced the ability to start numbered lists from indices other than 1. I noticed on the demo to export to pdf/docx this was not taked into account.

I was not able to run playwright locally and update snapshots if that is needed, can you give me guidance here or do it?

Copy link

vercel bot commented Jan 7, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
blocknote ✅ Ready (Inspect) Visit Preview Jan 8, 2025 7:39pm

Copy link

vercel bot commented Jan 7, 2025

@mfanselmo is attempting to deploy a commit to the TypeCell Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Collaborator

@YousefED YousefED left a comment

Choose a reason for hiding this comment

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

Nice, thanks. We'll fix the playwright tests, I think it's unrelated. Could you:

  • also add support to the docx exporter?
  • add it to the unit tests of the exporters? (add a case to the default test case and update the related snapshots)

@mfanselmo
Copy link
Contributor Author

Hey! I spent quite a bit of time on this but ran into some tricky edge cases I couldn’t get to work perfectly. Let me break them down:

For PDFs, numbering is straightforward since we can manually set the numbering. However, Word has a few quirks:
To start a numbered list at a value other than 1, you have to define a specific configuration for that list type. It’s not as simple as just setting a start value. I handled this by maintaining a set of starting indices and manually referencing them via blocknote-numbered-list-{index}.
Word automatically increments list numbers, so if you need to restart numbering manually, you have to use the instance parameter for adjacent lists.
I came across a weird edge case where adjacent lists, nested under different parent blocks, don’t behave as expected—even though the instance parameter should fix it. For now, my code assigns a unique numeric ID to each list instance, but I believe this might be overkill and could be simplified. I left it in just in case someone wants to dig into it.

Here’s an example of content that doesn’t render correctly in Word. Based on how instance works, I would expect this to work fine:
image

I’ve updated the snapshots for both PDF and DOCX to test these cases. The PDF output works perfectly, but DOCX still has this one issue. @YousefED I will leave this one to this point for now, but if I find time in the future I will give it another go


for (const b of blocks) {
if (b.type === "numberedListItem") {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code is a bit messy and could definitely be improved, but its the best I could come up with to ensure a unique instance id is given to each numbered list. In theory this id should guarantee no weird continuations of non adjacent lists happen, but for some reason they still are. I would not merge this as is

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.

2 participants