All about quill blots, and how to make a custom quill blot
24.10.2024
119
0
0
0
0
List of blots and how to get them
Blot is a building block of document used by parchment. Their various types, examples of useage and implementation can be viewed on my online quill editor.
As you will see below, there are quite a few of these building blocks. And each of them exists to perform a specific role in the document. I will talk about the role of each blot separately, but before this, let's see what kinds of blots we have in QuillJs::
block
block/embed
break
container
cursor
embed
inline
scroll
text
To import any blot from this list into a new JS variable, enter the blot name after blots, like this:
To see a full list of all available blots, type in the browser console:
About each blot
Inline blot. Examples of using this block are bold, italic, or anything underlined. This is the simplest block; it simply wraps the selected block in a prespecified tag with prespecified classes. And it can be wrapped around another inline block.
Block blot. For example, a block of quotes, a block of code, or headings. It is important to understand how this block works. It does not simply wrap a selected block in a certain tag - yes, a block, not text - it just replaces it. That is, block blots cannot be inside each other, as is the case with inline blocks.
Container blot. They are created in order to overcome the inability of previous blocks to be embedded in one another. In other articles, you will see that we will have to specify in advance the elements that can be inside each other ;) An example of the implementation of such blocks are lists and tables.
Block/embed and embed. They work the same way as regular blocks, but with the only difference that the content they embed cannot be edited. It can be reloaded or deleted, but not changed. These are videos, formulas, and images.
Scroll blot. It is the main container for all the others. What is it? By default, it is a DIV element with the ql-editor class. Which can contain the following types of blots:
block
embed
container
Another important feature of this blot is that the constructor accepts a special object as the first parameter - a register. It is too early to talk about Quill registers, but let's say that each register is a unique set of buttons and formatters for editing text. That is, on one page you can have several text editors with their own unique functionality.
Break blot. This is a special zero element. In the Parchment library, each container that can have children must have at least one. And this blot was created to play the role of the initial element.
Text blot. It is a regular wrapper around the text
Cursor blot. It is a vertical line when editing. And it knows where and on which block it is located.
All blot methods and members to override
In this chapter, I have collected all possible methods for overriding and added some comments to them. I did this because the official site does not have such information, although it can still be found through the browser console.
How to make a new one blot and override a default one
For the example of overriding an existing blot, I'll use block blot. Let's start with import.
Next, you need to define new blot functionality. In my case, I want to use <div> instead of <p> tag and add a class named "txt". This is how I will do it:
This is about modifying blots. But how to make a new one? Any quill block has 3 variables that are used to distinguish one block from another. The first is tagName, the second is blotName and the third is className.
To create a new blot, you need to set a different value for blotName. I will demonstrate this using links as an example. We will create 2 types of links:
Internal links
External links
You're probably wondering what this "formater" is. But basically, I just made a button to add and delete this type of blot in the editor.
In this article, I will analyze the types of quilljs formatters and explain some of the nuances of working with tables, fonts, images, and video. I will also show how …
In this article, I will analyze the types of quilljs formatters and explain some of the nuances of working with tables, fonts, images, and video. I will also show how …