I am trying to create a command which converts a nested bullet list into todo list.
I think this should be done by
ReplaceAroundStep (see BulletList to TodoList conversion). When I convert the
listItem B into
todoItem B with
ReplaceAroundStep I get schema error saying
todoItem is not a valid child of
bulletList and a similar error if I try to convert
todoList first. Is there a way I can get these two node types converted without modifying my schema constraints?
ReplaceAroundSteps can only replace around a single range, so if you need to convert multiple
bulletItem nodes to
todoItems, that isn’t currently possible. There’s three possible solutions:
Just replace the entire list with a modified list with a replace step. This is the easy way, but will to lead to flaky collaborative editing if someone else is editing the list at the time when it is converted.
Find some sequence of steps, each leaving the document valid, that takes you to to the target document structure. For example use replace-around steps to move items into paragraphs sitting next to the list until they are all outside. Then wrap the first one in the other list type, and move the others in one at a time. This is going to be very tricky and awkward, though.
If these items just contain inline content, maybe you can just use a replace-around step that converts the type of the outer list, and rely on the replace-fitting code to convert the items to the right type. I’m not 100% sure it’ll do the right thing, but it’s worth a shot, since it’s a lot easier than the second option.
Thanks for the solutions. For my case option2 can work, but it seems more work than the perceived benefits.
Which makes me think if it is worth having separate
todoItem node types vs just having a plain
bulletItem and implement the checkbox using node attribute and display it as a widget decorator. What do you think about this approach ? For me this will prevent having to fudge
bulletLists when in all regards they behave identical.
That seems like it would simplify things. (And has a precedent in Github-style markdown task lists, which are just bullet list items with a checkbox.)