facebook / lexical

Lexical is an extensible text editor framework that provides excellent reliability, accessibility and performance.
https://lexical.dev
MIT License
19.86k stars 1.68k forks source link

Bug: OL nested list must use three spaces rather than two #2214

Open hanford opened 2 years ago

hanford commented 2 years ago

Currently Lexical (0.2.9) treats numbered lists the same as unordered lists and indents nesting with four spaces. However lists where the marker takes up multiple spaces (ordered lists), must be treated special differently.

According to the commonmark spec:

If the list marker takes up two spaces, and there are three spaces between the list marker and the next non-whitespace character, then blocks must be indented five spaces in order to fall under the list item.

This can be quickly repro'd over here: https://codesandbox.io/s/lexical-rich-text-example-forked-e8comj?file=/src/Editor.js, by creating an ordered list and then clicking "Generate markdown" which logs the generated markdown.

refs https://github.com/facebook/lexical/issues/2208

I'm happy to try and fix my inputs with a regex if this isn't the desired functionality!

hanford commented 2 years ago

Originally I was patching the @lexical/markdown but instead ended up creating my own UNORDERED_LIST and ORDERED_LIST transforms which seemed slightly easier to keep up to date.

The downside is I ended up needing to duplicate a lot of code to get this to work, copying listReplace and listExport with very slight modifications (notice the indentSize argument that's been added to both functions and is passed in from the transform declarations.

https://gist.github.com/hanford/e15a0f3be981beb91602a6b1c82fa39a

Is there a better way to do this? Replacing these transforms might be common so adding better support might be helpful