lexical
lexical copied to clipboard
Bug: $convertFromMarkdownString method from @lexical/markdown ignores linebreaks
Issue edited:
$convertFromMarkdownString is avoiding multiple "\n", in this case for example:
If I provide as an initial content something like this:
editorState: () => $convertFromMarkdownString( 'ab\n\nc\n\n\n\n - item\n- item2\n1. item1\n2. item2\n3. item3\n\nTest\n\nTest\n- another list\n- with items\n- {{additional_information}} ', TRANSFORMERS, ),
I expect to have some output like this:
However I get this:
Lexical version: Latest
The current behavior
The expected behavior
Output is properly rendered and it must be as the first screenshot provided.
Which basically, after being converted to markdown, it is something like this:
- item\n- item2\n1. item1\n2. item2\n3. item3\nTest\nTest\n- another list\n- with items\n
I think your input is converted to like this:
- item\n- item2\n\n1. item1\n2. item2\n3. item3\n\nTest\n\nTest\n\n- another list\n- with items\n
This is how GitHub renders the markdown that you've provided, which is consistent with the screenshot in this report:
- item
- item2
- item1
- item2
- item3 Test Test
- another list
- with items
I made sure to reproduce it exactly by using this from the browser console, and then pasting it into this comment:
copy('- item\n- item2\n1. item1\n2. item2\n3. item3\nTest\nTest\n- another list\n- with items\n')
Yes, you're right, I was deeping into my code and I saw somehow I was using in the middle of the process a format function which was basically replacing "\n\n" by "\n", which was causing this.
Now, anyway I figured out about another issue, which is basically that $convertFromMarkdownString is avoiding multiple "\n", in this case for example:
If I provide as an initial content something like this:
editorState: () => $convertFromMarkdownString( 'ab\n\nc\n\n\n\n - item\n- item2\n1. item1\n2. item2\n3. item3\n\nTest\n\nTest\n- another list\n- with items\n- {{additional_information}} ', TRANSFORMERS, ),
I expect to have some output like this:
However I get this:
Does it mean that line breaks somehow are ignored?
@2wheeh @etrepum
Thanks!
There would be new feature coming about preserveNewLines (#6020)
It seems not released yet though it's live on playground.
I saw on documentation https://lexical.dev/docs/api/modules/lexical_markdown that there's a shouldPreserveNewLines property in the signature.
However in my current export of the method, it only has 3 arguments:
There would be new feature coming about
preserveNewLines(#6020) It seems not released yet though it's live on playground.![]()
Oh, thanks mate, I see, I guess I just need for that new feature to be released on a new version right?
Oh, thanks mate, I see, I guess I just need for that new feature to be released on a new version right?
Yes, I guess so. You could open a new issue for that feature when it behaves somewhat unexpectedly.
is there a way to be notified when a new version is released to check for this feature?
well, giving a star to this repo starts updating release news on your github feed. there is also discord community.
Do you know the timeline for releasing this?
#6144 is the issue tracking what should be done regarding the docs being built directly from main
Releases tend to happen once or twice a month, just going by history. I'd expect the next one by mid-June but probably sooner.
yes that correct, shouldPreserveNewLines flag would resolve this issue, documentation in
https://lexical.dev/docs/api/modules/lexical_markdown#converttomarkdownstring
it is now available in v0.16.0