quill icon indicating copy to clipboard operation
quill copied to clipboard

Quill 2.0: Support for multiple line-breaks within a single paragraph

Open dstj opened this issue 1 year ago • 7 comments

This is a modified revival of #2872 as it was closed when Quill 2.0 was released. Also related: #2469

Quote from #2872

Lines and paragraphs are not same things in typography. Usually, there's a spacing between paragraphs, which less than the height of a full line, unless there are different elements involved like figures, headings,... And, sometimes, there's a need to use multiple simple line-breaks for the same paragraph.

There can be produced output allowing multiple line-breaks within a single paragraph, like:

<p>Some text paragraph</p>
<p>
  Another text paragraph:<br/>
  with<br/>
  multiple<br/>
  lines
<p>
<p>Another paragraph</p>

Actual behavior:

Can't produce output above.

Suggested behaviour

In text editors like Microsoft Word (or CKEditor5 and TinyMCE), Shift-Enter will create a simple line break, while Enter will create a new paragraph.

#4248 tried with a custom keyboard binding, but it doesn't work because the underlying Parchment data model that does not support it.

Version Quill 2.0.2 via ngx-quill: "^25.3.2"

dstj avatar Sep 13 '24 18:09 dstj

The key reason is that Quill uses \n to generate a new paragraph, so it doesn't have an elegant way to identify <br>. If possible, just like markdown syntax, use \n\n to generate a new paragraph, and leave \n for <br>. Then it should be very easy to support line breaks within a paragraph.

However, this seems difficult to complete in a short time, so that the author tends not to complete it. The same problem also occurs in the support of Table. Of course, this is another topic ...

zozoh avatar Oct 22 '24 16:10 zozoh

@zozoh Exactly, and that, unfortunately, disqualifies Quill as a serious, viable contender for Rich Text Editor replacement like CKEditor5 and TinyMCE or Froala for everything except simple use cases. :/

\n and \n\n seems like a valid solution (with a possible toggle option like enableLineBreaks: true|false maybe to avoid breaking old implementations)...

dstj avatar Oct 22 '24 16:10 dstj

@dstj Yes, every time I thought this, I feel very sad, Quill's abstraction layer is very good, I love the Blots and related design, it is almost like I should have, but as you known few very small things prevent it from shining brightly.

zozoh avatar Oct 25 '24 08:10 zozoh

.ql-editor { white-space: normal !important;

p:empty { &::before { content: " "; white-space-collapse: preserve; } } }

mtnadb avatar Nov 15 '24 18:11 mtnadb

The key reason is that Quill uses \n to generate a new paragraph, so it doesn't have an elegant way to identify <br>. If possible, just like markdown syntax, use \n\n to generate a new paragraph, and leave \n for <br>. Then it should be very easy to support line breaks within a paragraph.

However, this seems difficult to complete in a short time, so that the author tends not to complete it. The same problem also occurs in the support of Table. Of course, this is another topic ...

There is a unicode character (u2028) for representing a line break. It's called line separator there. Can't we use this?

lsaffre avatar Oct 15 '25 15:10 lsaffre

I gived up. Maybe prosemirror is a better choice for me. @lsaffre

zozoh avatar Oct 18 '25 17:10 zozoh

@zozoh Thanks for sharing! Indeed prosemirror looks interesting. Maybe quill-next is a less radical solution, we started testing this approach thanks to 8lurry who did the work of making it work in Lino: https://gitlab.com/lino-framework/react

lsaffre avatar Oct 18 '25 18:10 lsaffre