简体   繁体   English

如何为 Quill 内容定义布局?

[英]How can I define a layout for Quill content?

How can you make an editor within editor with Quill?如何使用 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:所以 HTML 看起来像:

<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.在 'regular_quill_stuff_in' 中,用户也应该能够使用相同的工具栏,但应该禁用插入嵌入。
  • when you remove embed blot from outside, 'regular_quill_stuff_in' contents should be moved to 'regular_quill_stuff'.当您从外部移除嵌入污点时,“regular_quill_stuff_in”内容应移至“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.我尝试过基于 Block、Code 和 Scroll 制作一些自定义印迹,但我真的不明白如何使它工作,而且许多低级的东西没有很好地记录。 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 .然后我尝试在 dom 节点上创建另一个 Quill 实例,但由于主 quill 正在从 . 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.我能够通过基于用户聚焦 div 的自动启用/禁用 Quills 来修复它,但它仍然有问题,更不用说在两个 Quills 之间传递信息并且编辑历史和增量非常不协调。

Surely there has to be a way to make it easier.当然,必须有一种方法可以使它更容易。

Styling and organizing HTML elements on a page is done using CSS stylesheets.页面上的 HTML 元素的样式和组织是使用 CSS 样式表完成的。 Basically, elements get values for their class and id attributes, so that they can be selected to have a desired stylization applied.基本上,元素获取其 class 和 id 属性的值,以便可以选择它们以应用所需的样式。

This same process is done with any WYSIWYG rich text editor.任何 WYSIWYG 富文本编辑器都可以完成相同的过程。 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.我们可以使用对齐格式在 Quill 中看到这种情况。 If you write the following line in Quill:如果您在 Quill 中编写以下行:

This is a simple test.

As a result, you will have the following HTML markup in the editor:因此,您将在编辑器中拥有以下 HTML 标记:

<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.这意味着您可以定义自己的格式来应用负责按照您想要的方式安排 Quill 内容布局的类。

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.和你说的相比,这个想法不是将内容添加到容器中,而是添加一个能够组织内容的CSS类。

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.因此,为了正确实现这一点,您需要测试作为编辑器内容的不同 HTML 元素的格式和样式。

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:要了解如何通过印迹定义新格式,请参阅以下链接:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM