Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lbarrous opened this issue May 19, 2024 · 13 comments
Closed

Comments

@lbarrous
Copy link

lbarrous commented May 19, 2024

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.

@2wheeh
Copy link
Contributor

2wheeh commented May 19, 2024

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

@etrepum
Copy link
Contributor

etrepum commented May 20, 2024

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')

@lbarrous
Copy link
Author

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!

@lbarrous lbarrous changed the title Bug: $convertFromMarkdownString method from @lexical/markdown does not convert text properly after ListItemNodes Bug: $convertFromMarkdownString method from @lexical/markdown ignores linebreaks May 22, 2024
@2wheeh
Copy link
Contributor

2wheeh commented May 22, 2024

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

image

@lbarrous
Copy link
Author

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

@lbarrous
Copy link
Author

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?

@2wheeh
Copy link
Contributor

2wheeh commented May 22, 2024

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.

@lbarrous
Copy link
Author

lbarrous commented May 22, 2024

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

@2wheeh
Copy link
Contributor

2wheeh commented May 22, 2024

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

@illing2005
Copy link

Do you know the timeline for releasing this?

@etrepum
Copy link
Contributor

etrepum commented May 22, 2024

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

@etrepum
Copy link
Contributor

etrepum commented May 22, 2024

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.

@potatowagon
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants