After updating quill to 2.0 previous solution to line break stop working. I tried to apply and adopt many solutions available here for previous version with no success.
I got to the point, when line break with BR tag is applied in editing mode. Unfortunately when I’m initiating new quill instance with preloaded data containing BRs, they are all converted to paragraphs and I wasn’t able to code working solution for that.
Could you help me please?
I’m attaching working part of my code:
import Quill from 'quill';
import { EmbedBlot } from 'parchment';
class SoftBreak extends EmbedBlot {
static create(value) {
let node = super.create(value);
return node;
}
length() {
return 1;
}
value() {
return 'n';
}
static value(node) {
return 'n';
}
}
SoftBreak.blotName = 'softbreak';
SoftBreak.tagName = 'BR';
Quill.register(SoftBreak);
export const quillConfig = {
theme: 'snow',
modules: {
keyboard: {
bindings: {
linebreak: {
key: 'Enter',
shiftKey: true,
handler: function(range, context) {
const quill = this.quill;
const currentLength = quill.getLength();
quill.insertEmbed(range.index, 'softbreak', '');
quill.setSelection(Math.min(range.index + 1, currentLength), Quill.sources.SILENT);
}
}
}
}
}
}
I initiate quill as following:
quillContainer.innerHTML = htmlData;
quill = new Quill(quillContainer, quillConfig);
quill.focus();
htmlData
is containing html previously saved from quill.
Łukasz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.