Basically, for a Delta like this:
{
"ops": [
{
"attributes": {
"header": 2
},
"insert": "\n"
},
{
"insert": "a\n"
}
]
}
I get TypeError: Cannot set properties of undefined (setting 'attributes'), at this line in the insertNewline function:
parsed.paragraphs[parsed.paragraphs.length-1].attributes = op.attributes;
My workaround is to do this, which is fine for my use case:
const raw = { ...(delta as RawQuillDelta) };
if (raw.ops?.length > 0) {
raw.ops = [...raw.ops];
const first = raw.ops[0];
if (first.insert === '\n' && first.attributes) {
raw.ops.unshift({ insert: '\n' });
}
}
const parsed = parseQuillDelta(raw);