1
votes

How can you make an editor within editor with Quill? Imagine a scenario: there is some text with formating, then there is an embed (image/video/...) with some formated text on the right. And then there is some text again. So HTML would look like:

<editor>
<regular_quill_stuff></regular_quill_stuff>
<customEmbed> // some CSS flex here
    <container contenteditable="false"><image></image></container>
    <container><regular_quill_stuff_in></regular_quill_stuff_in></container>
</customEmbed>
<regular_quill_stuff></regular_quill_stuff>
</editor>

NOTES:

  • in 'regular_quill_stuff_in' user should be able too use the same toolbar but inserting embeds should be disabled.
  • when you remove embed blot from outside, 'regular_quill_stuff_in' contents should be moved to 'regular_quill_stuff'.

I've tried making some custom blot based on Block, Code and Scroll but I can't really understand how to make it work, and many low level stuff isn't documented very well. Then I tried to create another instance of Quill on a dom node, but it was very buggy becouse main quill was reciving events from within . I was able to fix it with auto-enabling/disabling Quills based on user focusing divs, but it still was buggy, not to mention passing information between two Quills and edit history and deltas were very incoistent.

Surely there has to be a way to make it easier.

1
Hi @GreenTea222. I'm sorry, but I don't quite understand what you want to do. Do you want to put one Quill editor inside another one? Is that it? But... For what purpose? How would this be useful? What kind of scenario could this be applied to? Could you explain it better, please? Maybe this way I can help you. Also, If you need more information about Quill, take a look at this. It may be useful somehow. - Loa
@Loa not necessary quill inside quill. What I want is being able to easily create containers inside ql-editor, and redirect flow of a document. Take this page for example: en.wikipedia.org/wiki/JavaScript imagine it all being inside one ql-editor. 'JavaScript (/ˈdʒɑːvəˌskrɪpt/),[9] often abbreviated as ...' is just in ql-editor, but the contents with some background and list is in a container that is in ql-editor. Panel on the right would ba another container. I want to create custom Embeds with a formatable content inside. - GreenTea222
Do you want to define containers within Quill to separate and organize its content? Like to arrange the layout of text, images, lists and tables, and etc? In other words, like a css layout on an HTML page? - Loa
yes, and being able to add/delete them like any other quill embeds (from some custom a toolbar that is) - GreenTea222

1 Answers

2
votes

Styling and organizing HTML elements on a page is done using CSS stylesheets. Basically, elements get values for their class and id attributes, so that they can be selected to have a desired stylization applied.

This same process is done with any WYSIWYG rich text editor. The buttons on the editor toolbar are responsible for not only adding new content, but also changing what is already present. For some, this involves changing or applying classes to the desired snippet.

We can see this happening in Quill using the alignment format. If you write the following line in Quill:

This is a simple test.

As a result, you will have the following HTML markup in the editor:

<p>This is a simple test.</p>

Selecting a portion of this text and using/applying the alignment format to, for example, center, will cause a class to be applied to the paragraph, and the result will be as follows:

<p class="ql-align-center">This is a simple test.</p>

So what does this mean? This means you can define your own formats to apply classes that are in charge of arranging the layout of Quill content the way you want.

Compared to what you said, the idea is not to add the content to a container, but to add a CSS class capable of organizing the content.

You can choose to apply attributors, or define new elements for it. But this kind of process requires testing and more testing. I'm not sure how you want to organize things, or what features you want to add. Therefore, for this to be implemented correctly, you will need to test formats and styles for the different HTML elements present as the editor content.

I suggest you start with simple things, such as text, a paragraph. Try to create an attributor that can apply classes to paragraphs. When you can do that, try something else, such as images, videos, the embed elements. You will find varied results, and this will show that you have to test and test until the desired result is found.

As a help, copy the alignment code, but change it to a desired class. More information on this can be found at the following links:

To learn how to define new formats through blots, see the following links: