Repository navigation
Add custom attribute #4725
Replies: 1 comment
|
Use a registered block const { ClassAttributor, Scope } = Quill.import('parchment');
const ParagraphClass = new ClassAttributor('customKey', 'class', {
scope: Scope.BLOCK,
whitelist: ['a', 'b'],
});
Quill.register(ParagraphClass); // before creating the editor
const quill = new Quill('#editor', {
formats: ['customKey', 'bold', 'align', 'header', 'list'],
});
quill.setContents([
{ insert: 'hello' },
{ insert: '\n', attributes: { customKey: condition ? 'a' : 'b' } },
]);Here For an existing paragraph, use A runnable Quill2.0.3 example includes editing, JSON export, clearing, restoration into a new editor and repeated class changes, with bold/alignment/heading/list content retained. The Delta documentation explains why line formats belong on the newline. |
Uh oh!
There was an error while loading. Please reload this page.
Hi there,
I need to add a dynamic class to each
tag every time I call setContents.
something like
I am able to hack my way in the Block class
but the attribute is not stored in quill inner structure, quill.getContents does not store my attributes.customKey, I tried adding it to /formats folder without success.
Is there any official way to do this?
any suggestions?
All reactions