Markdown todo lists handling inconsistent when typing and setting data
There are some quite significant differences in what markup is converted to todo lists with Markdown plugin when typing and when using editor API (setData).
Typing
When typing, any of the below is transformed into a todo list automatically (after pressing space after ]):
- [ ] todo
- [x] todo
* [ ] todo
* [x] todo
- [] todo
* [] todo
[] todo
[ ] todo
[x] todo
This can be easily checked in our docs markdown example.
Using setData
When using setData, only two first pairs are transformed correctly:
- [ ] todo
- [x] todo
* [ ] todo
* [x] todo
additionally, + prefix is supported:
+ [ ] todo
+ [x] todo
Rest of the markup is not transformed into todo list. This can be checked by going to our docs markdown example and running below code in a browser dev console:
editor.setData(`## Valid:
1
- [ ] todo
2
- [x] todo
3
* [ ] todo
4
* [x] todo
5
+ [ ] todo
6
+ [x] todo
## Invalid
1
- [] todo
2
* [] todo
3
[] todo
4
[ ] todo
5
[x] todo
`)
Markdown specs
The behavior of setData directly reflects markdown (GFM) specification, which states [1]:
A list marker is a bullet list marker or an ordered list marker.
A bullet list marker is a -, +, or * character.
And [2]:
A task list item is a list item where the first block in it is a paragraph which begins with a task list item marker and at least one whitespace character before any other content.
A task list item marker consists of an optional number of spaces, a left bracket ([), either a whitespace character or the letter x in either lowercase or uppercase, and then a right bracket (]).
All other combinations, which are supported for typing are not valid according to markdown specs
📝 Provide detailed reproduction steps (if any)
As described above.
✔️ Expected result
I would expect more consistent behavior, so that the same syntax can be used while typing and setting data, both resulting in the same content.
One of real use cases here is source editing, where adding any of the unhandled markup in source will not result in a todo list in content.
❓ Possible solution
I'm not sure what would be 100% expected behavior and what is a current intended one.
From technical perspective, one of the solutions could be normalizing markdown content (todo lists markup) before sending it to markdown-html converter so any custom markup for todo lists which is supported during typing can be first normalized to supported markdown markup (no pun intended) and then correctly converted to todo list html.
If you'd like to see this fixed sooner, add a 👍 reaction to this post.