From fe30d243d30832cd915d7c2ca190f88ac5313bc1 Mon Sep 17 00:00:00 2001 From: Illia Kyselov <69676320+kyselberg@users.noreply.github.com> Date: Sun, 1 Sep 2024 18:06:33 +0300 Subject: [PATCH] feat(Editor): add method to change block type --- source/Editor.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source/Editor.ts b/source/Editor.ts index 78a4ba8a..927c2148 100644 --- a/source/Editor.ts +++ b/source/Editor.ts @@ -2455,6 +2455,21 @@ class Squire { return frag; } + changeBlockType( + tag: string = this._config.blockTag, + attrs: Record | 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();