Open yassinsameh opened 8 months ago
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.
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.
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/)
flutter_markdown test (https://tarekkma.github.io/markdown_quill_playground/)
Github markdown test (https://gist.github.com/)
If you want to maintain line breaks just replace \n
with <br>
it should do it.
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
Thank you for the clear examples, will try to figure out what's the issue.
Hi @TarekkMA, managed to take a look? I believe the solution is possibly in the EmptyBlockSyntax class parse method.
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;
}
@TarekkMA - did you get a chance to look into this. This change would be of great help.
Looks pretty normal. Consider (inserting like a dozen linebreaks right here)
this comment, for example.
With the following example json: "Example text/n/nTable of Contents", Expected:
Result:
markdown_quill: ^3.1.0 flutter_quill: ^9.3.1
Code: