lexical icon indicating copy to clipboard operation
lexical copied to clipboard

Bug: $convertFromMarkdownString method from @lexical/markdown ignores linebreaks

Open aperezgarcia93 opened this issue 1 year ago • 12 comments

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: image

However I get this: image

Lexical version: Latest

The current behavior

The expected behavior

Output is properly rendered and it must be as the first screenshot provided.

aperezgarcia93 avatar May 19 '24 01:05 aperezgarcia93

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

2wheeh avatar May 19 '24 17:05 2wheeh

This is how GitHub renders the markdown that you've provided, which is consistent with the screenshot in this report:


  • item
  • item2
  1. item1
  2. item2
  3. 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')

etrepum avatar May 20 '24 17:05 etrepum

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: image

However I get this: image

Does it mean that line breaks somehow are ignored?

@2wheeh @etrepum

Thanks!

aperezgarcia93 avatar May 22 '24 13:05 aperezgarcia93

There would be new feature coming about preserveNewLines (#6020) It seems not released yet though it's live on playground.

image

2wheeh avatar May 22 '24 13:05 2wheeh

I saw on documentation https://lexical.dev/docs/api/modules/lexical_markdown that there's a shouldPreserveNewLines property in the signature. image

However in my current export of the method, it only has 3 arguments: image

aperezgarcia93 avatar May 22 '24 13:05 aperezgarcia93

There would be new feature coming about preserveNewLines (#6020) It seems not released yet though it's live on playground.

image

Oh, thanks mate, I see, I guess I just need for that new feature to be released on a new version right?

aperezgarcia93 avatar May 22 '24 13:05 aperezgarcia93

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.

2wheeh avatar May 22 '24 13:05 2wheeh

is there a way to be notified when a new version is released to check for this feature?

aperezgarcia93 avatar May 22 '24 13:05 aperezgarcia93

well, giving a star to this repo starts updating release news on your github feed. there is also discord community.

2wheeh avatar May 22 '24 13:05 2wheeh

Do you know the timeline for releasing this?

illing2005 avatar May 22 '24 14:05 illing2005

#6144 is the issue tracking what should be done regarding the docs being built directly from main

etrepum avatar May 22 '24 14:05 etrepum

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.

etrepum avatar May 22 '24 14:05 etrepum

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

potatowagon avatar Jun 05 '24 08:06 potatowagon