Get font family from Quill

Viewed 1693

I'm using Quill to build rich text editor. It is working fine and I can change fonts for selected words as in this example.

The next step is to export raw HTML of the edited text. I was expecting standard font-family styles to be exported but I got Quill ones.

For example, using the above link, if I select the word "hello" and change font to Mirza:

  • Outputed raw HTML: <span class="ql-font-mirza">Hello </span>
  • Expected raw HTML: <span style="font-family: mirza;">Hello</span>
2 Answers

It's explained in the Quill guide.

Example:

var FontStyle = Quill.import('attributors/style/font');
Quill.register(FontStyle, true);

var quill = new Quill('#editor-container', {
  modules: {
    toolbar: [
      [{ header: [1, 2, false] }],
      [{'font': []}],
      ['bold', 'italic', 'underline']      
    ]
  },
  placeholder: 'Compose an epic...',
  theme: 'snow'  // or 'bubble'
});

It's explained in the Quill guide.

Example:

//The font of the quill editor
var fonts = ['SimSun', 'SimHei','Microsoft-YaHei','KaiTi','FangSong','Arial','Times-New-Roman','sans-serif'];  
var Font = Quill.import('formats/font');  
Font.whitelist = fonts; //Add fonts to the whitelist 
Quill.register(Font, true);
var toolbarOptions = [
    [{
            'header': [1, 2, 3, 4, 5, 6, false]
        }],
        ['bold', 'italic', 'underline', 'strike'],
        [{
            'list': 'ordered'
        }, {
            'list': 'bullet'
        }],
        [{'font': fonts }],
        ['link', 'image', 'video']
];
var quill = new Quill('#quillEditor', {
    modules: {
            toolbar: toolbarOptions
        },
        theme: 'snow',
        placeholder:'Enter The Song Here'
});

Related