I have made a rich text area made with Quill js. I have the next options for the tool bar:
new Quill('#quilljs-container', {
modules: {
toolbar: [
['bold', 'italic', 'underline', 'strike'], // toggled buttons
['blockquote', 'code-block', 'link'],
[{ 'header': 1 }, { 'header': 2 }], // custom button values
[{ 'list': 'ordered'}, { 'list': 'bullet' }],
[{ 'script': 'sub'}, { 'script': 'super' }], // superscript/subscript
[{ 'indent': '-1'}, { 'indent': '+1' }], // outdent/indent
[{ 'direction': 'rtl' }], // text direction
[{ 'color': [] }, { 'background': [] }], // dropdown with defaults from theme
[{ 'font': [] }],
[{ 'align': [] }],
['clean'] // remove formatting button
]
},
theme: 'snow'
});
<!-- Style -->
<link href="https://cdn.quilljs.com/1.0.0/quill.snow.css" rel="stylesheet">
<!-- quill js container -->
<div id="quilljs-container"> </div>
<!-- Add quill js on the project -->
<script src="https://cdn.quilljs.com/1.0.0/quill.js"></script>
Currently, when I try to add more types editing the 'font' option on toolbar (e.g. 'font': ['arial']), the select options just display "Sans Serif" instead of display the "Arial" option. What I spect is see the default options ("Sans Serif", "Serif", "Monospace") plus custom options that I want to add.
Also, I have tried the customizing attributors shown on the documentation, but with my current configuration, it just display just the default options. Maybe I'm missing something.
I hope I was clear with my doubt and someone could help me.
UPDATE:
Just to be a little more clear, I am trying to add more fonts following the Quill Container configuration
Container: At the simplest level, toolbar controls can be specified by a simple array of format names.
You CAN use the JavaScript constructor to create a custom font selection.
From the Quill Quickstart page here's the basic HTML -
The code required in the JavaScript initialiser is along the lines of the following:
You also need to add the following to your stylesheet where the names in the CSS selectors are those names in the above JavaScript:
FWIW, I've copied the code from Steve B and made it more generic. This way you don't need to do all the copy pasting of css rules, etc... just specify the fonts you would like adding in your fonts array.
This is what you need.
The process is like this you need 4 components:
select
tag with aql-font
class. This will contain the new font options.Quill
constructor in Javascript.font-family
for eachlabel
in the dropdown. Example:font-family: "Inconsolata"
.ql-font-inconsolata { font-family: "Inconsolata";}
Update:
I read the documentation in order to help you and they mention that
Alternatively, you can manually create a toolbar in HTML by passing the DOM element or selector into Quill; and that is the solution presented in this answer. On the other hand, the documentation does not mention but after trying many ways to load data using an array (without any success), I noticed that is not possible. So, here is my contribution and the reason why I posted this update. I made the equivalences (JS and HTML) for the manual implementation.
A custom toolbar can be created using HTML and a JS constructor. The constructor will receive the
#toolbar-container
as atoolbar
in themodules
section.Then, you can generate the same structure using only
HTML
tags. The concept is very similar. For example:['bold', 'italic', 'underline', 'strike']
in HTML will be:[{ 'header': 1 }, { 'header': 2 }]
in HTML will beSo, here you have a complete example in this code snippet:
Accepted answer is mostly great but it's important to notice, that
formats/font
is actually wrong and doesn't work with tested Quill 1.3.7.What worked for me was:
let fonts = Quill.import("formats/font");