delta_markdown icon indicating copy to clipboard operation
delta_markdown copied to clipboard

Issues with new lines

Open TarekkMA opened this issue 3 years ago • 1 comments

Thank you very much for this great tool. I noticed an issue with new lines handling

In markdown new lines must be specified with 2 (or more) consecutive lines. so one \n in quill should be transformed into two \n. and 1 \n in markdown should be ignored and more than that should result in only a single \n.

deltaToMarkdown

[{"insert":"line 1line 2\\nline 3\\n"}]

expected:

line 1line 2

line3

actual:

line 1line 2
line 3

markdownToDelta

line 1
line 2

line 3

expected:

[{"insert":"line 1line 2\\nline3\\n"}]

actual:

[{"insert":"line 1\\nline 2\\nline 3\\n"}]

TarekkMA avatar Nov 18 '21 10:11 TarekkMA

@TarekkMA this might help


// Converts single line break from "\n" to "  \n"
// Ignores double or more line breaks
final regex = RegExp(r'(?<!\n)\n(?!\n)');
final formattedMarkdown = markdown.replaceAll(regex, '  \n');

Juliotati avatar May 29 '23 16:05 Juliotati