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 formats and explain some of the nuances of working with tables, fonts, images, and video. I will also show how …
In this article, you will find an example of how to implement your own Quill tooltip. And you will get how this even works. As an example, a tooltip will …
In this article I will show how to make custom quill module for an editors. This module will generate the table of contents of the article. I will also show …
Used termins
TailwindCSS framework ⟶ It is a utility-first CSS framework that streamlines web development by providing a set of pre-designed utility classes. These classes enable rapid styling without writing custom CSS, promoting consistency and scalability. Tailwind’s approach shifts focus from traditional CSS components to functional classes, empowering developers.
Javascript ⟶ Is a high-level, interpreted programming language that is commonly used for web development. It is an essential part of web applications, enabling interactive features and dynamic content on websites.
CSS (Cascading style sheets) ⟶ Is a stylesheet language used for describing the presentation of a document written in HTML or XML (including various XML languages like SVG or XHTML). CSS controls the layout, colors, fonts, and overall visual appearance of web pages, allowing web developers to create visually engaging and cohesive designs.
JSON (JavaScript Object Notation) ⟶ Stands for JavaScript Object Notation, is a lightweight data interchange format that is easy for humans to read and write, and easy for machines to parse and generate. It is primarily used to transmit data between a server and a web application as an alternative to XML.
Related questions
Why did you quit game development ?
I quit making games because it was long and tedious. And very lonely. And yet, I didn’t want to work 15 hours a day to make some kind of feature for the game. I still want to have some kind of personal live :)
What is a quill text editor
This is a text editor based on the WYSIWYG principle (What you see is what you get). It is lightweight and easy to modify the JS framework. Perfectly fitting for any website needs.
How does quill works
To be able to work the quill, divide a text into blots and save them in a special format called delta. This format is very similar to JSON. Modification and editing are managed by Quill modules and formatters, with no dependencies from the markup language; in most cases, this is HTML.