When I paste code into Quill, or use tabs or spaces to indent code, that indentation seems to be lost in deltas, which is a shame.
However it is possible to use the Quill indent formatter to indent. This results in an 'indent: 1' attribute.
In your deltaToIntermediate.js file, this attribute is in a BlockInsert element. But when you combine block-code elements, only the child attributes are preserved - the parent block of all except the first BlockInsert element are discarded, so the indentation attribute is lost.
I was able to fix it as follows (there are probably more elegant ways - but it works):
/**
* @param blocks {BlockInsert[]}
*/
function mergeAdjacentCodeBlocks(blocks) {
for (let i = 0; i < blocks.length - 1; i++){
if (blocks[i].attributes['code-block'] && blocks[i + 1].attributes['code-block']) {
// SR: If the parent block being merged has attributes other than 'code-block',
// merge them into the children
if ( Object.keys( blocks[i+1].attributes ).length > 1 ) {
let parentAttrs = Object.assign({}, blocks[i + 1].attributes);
delete parentAttrs['code-block'];
blocks[i + 1].children.forEach( function( child ) {
Object.assign( child.attributes, parentAttrs );
});
}
blocks[i].children.push(...blocks[i + 1].children);
blocks.splice(i + 1, 1);
// Decrement index since the array has been changed
i--;
}
}
}
When I paste code into Quill, or use tabs or spaces to indent code, that indentation seems to be lost in deltas, which is a shame.
However it is possible to use the Quill indent formatter to indent. This results in an 'indent: 1' attribute.
In your
deltaToIntermediate.jsfile, this attribute is in aBlockInsertelement. But when you combine block-code elements, only the child attributes are preserved - the parent block of all except the firstBlockInsertelement are discarded, so the indentation attribute is lost.I was able to fix it as follows (there are probably more elegant ways - but it works):