Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having problems extending Quill

I'm hitting some problems extending Quill.

I want to modify the List and ListItem classes in Quill, so I tried to copy formats/list.js into my code base as a starting point. I then import my local copy and register it with Quill like so...

import { List, ListItem } from './quill/list';

Quill.register({
    'formats/list': List,
    'formats/list/item': ListItem
}, true);

However, when I attempt to create a list in the editor the code crashes in the List class with the following error:

ParchmentError {message: "[Parchment] Unable to create list-item blot", name: "ParchmentError"}

This happens on this line... https://github.com/quilljs/quill/blob/develop/formats/list.js#L99

I assume it relates to the imports I was forced to change, but I can't figure out what's wrong. I've not made any other changes to list.js. The original file has the following:-

import Block from '../blots/block';
import Container from '../blots/container';

Which I changed to this:-

import Quill from 'quill';
let Block = Quill.import('blots/block');
let Container = Quill.import('blots/container');

Is the way I am importing wrong? What is causing the error?

like image 377
Rik Heywood Avatar asked Dec 11 '16 13:12

Rik Heywood


1 Answers

Figured it out (well a colleague did).

I needed to import Parchment like so :-

let Parchment = Quill.import('parchment');

instead of import Parchment from 'parchment';

This is because you'll end up with a different static Parchment class to the one used internally to Quill, so asking Quill for it's instance ensures you are both working with the same one (ie, the one where the blots were registered).

like image 78
Rik Heywood Avatar answered Sep 27 '22 17:09

Rik Heywood