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

Line breaks are not being converted #20

Open
yassinsameh opened this issue Mar 25, 2024 · 9 comments
Open

Line breaks are not being converted #20

yassinsameh opened this issue Mar 25, 2024 · 9 comments

Comments

@yassinsameh
Copy link

With the following example json: "Example text/n/nTable of Contents",
Expected:

Example text

Table of contents

Result:

Example text
Table of contents

markdown_quill: ^3.1.0
flutter_quill: ^9.3.1

Code:

    final mdDocument = md.Document();
    final mdToDelta = MarkdownToDelta(
      markdownDocument: mdDocument,
    );
    final deltaDocument = mdToDelta.convert(json);
    return quill.Document.fromDelta(cleanedDelta);
@TarekkMA
Copy link
Owner

Hi @yassinsameh, thank you for opening an issue. This is to be expected when dealing with Markdown, you can also test it on https://dart-lang.github.io/markdown/ and confirm it.

if you want to add a hard line break that's not ignored you can add <br> which will be converted to a new line

Please let me know if you need any extra help regarding this issue.

@yassinsameh
Copy link
Author

yassinsameh commented Mar 25, 2024

Hi @TarekkMA , sorry i don't get your point with the converter, it's converting to html while i'm converting to deltas. For other reference: Using the flutter_markdown package , with the same String, the output is formatted correctly with line breaks, could you please take a look.

I believe the solution is possibly in the EmptyBlockSyntax class parse method.

To give more context to the use case, i'm converting an llm output to deltas, so it wouldn't be very possible to add line breaks manually really, think it would be very hacky with weird edge cases.

@TarekkMA TarekkMA reopened this Mar 25, 2024
@TarekkMA
Copy link
Owner

TarekkMA commented Mar 25, 2024

If the issue is line breaks are not converted, this is an expected behavior. 1 line break is ignored, but 2 or more line breaks converts only to one line break.

Vanilla Dart Markdown test (https://dart-lang.github.io/markdown/)
Screenshot 2024-03-25 at 11 36 05 AM

flutter_markdown test (https://tarekkma.github.io/markdown_quill_playground/)
Screenshot 2024-03-25 at 11 36 20 AM

Github markdown test (https://gist.github.com/)
Screenshot 2024-03-25 at 11 36 48 AM
Screenshot 2024-03-25 at 11 36 52 AM


If you want to maintain line breaks just replace \n with <br> it should do it.

@yassinsameh
Copy link
Author

Thank you for taking the time to look at this. That behavior of >= 2 line breaks will generate only one empty line is fine.
The problem i outlined above is during the conversion 2 line breaks generate 0 empty lines.

So case 1: "test/nbar".
Correct & current output:

test
bar

Case 2: "test/n/nbar".
Incorrect Current output:

test
bar

Correct expected output:

test

bar

Case 3 you mentioned above: "test/n/n/n/nbar":
Correct expected output:

test

bar

@TarekkMA
Copy link
Owner

Thank you for the clear examples, will try to figure out what's the issue.

@yassinsameh
Copy link
Author

Hi @TarekkMA, managed to take a look? I believe the solution is possibly in the EmptyBlockSyntax class parse method.

@Gursewak-Uppal
Copy link

Gursewak-Uppal commented Apr 24, 2024

I did it something like this

markdownToQuillDelta(String markdownText) {
  final mdDocument = md.Document();
  final mdToDelta = MarkdownToDelta(markdownDocument: mdDocument);
  final delta = mdToDelta.convert(markdownText.replaceAll("\n\n\n\n", '''
\n
\u200B 
\n
'''));
  return delta;
}

@sundar-karpura
Copy link

@TarekkMA - did you get a chance to look into this. This change would be of great help.

@DGrothe-PhD
Copy link

Looks pretty normal. Consider (inserting like a dozen linebreaks right here)

this comment, for example.

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