0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 07:13:08 -05:00

feat(Editor): add method to change block type

This commit is contained in:
Illia Kyselov 2024-09-01 18:06:33 +03:00
parent cbd8881e78
commit fe30d243d3

View file

@ -2455,6 +2455,21 @@ class Squire {
return frag;
}
changeBlockType(
tag: string = this._config.blockTag,
attrs: Record<string, string> | null = this._config.blockAttributes
) {
return this.modifyBlocks((frag) => {
const walker = getBlockWalker(frag, this._root);
const output = document.createDocumentFragment();
let node;
while ((node = walker.nextNode())) {
output.appendChild(createElement(tag, attrs, [empty(node)]));
}
return output;
});
};
makeUnorderedList(): Squire {
this.modifyBlocks((frag) => this._makeList(frag, 'UL'));
return this.focus();