mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
1 parent
05d25dac5a
commit
2be6d4d412
1 file changed
+27
-2
@@ -34,12 +34,37 @@ const editor = new Editor({
|
||||
});
|
||||
|
||||
watch(html, (newHtml) => {
|
||||
if (editor.getHTML() !== newHtml) {
|
||||
if (getCorrectedHtml() !== newHtml) {
|
||||
editor.commands.setContent(newHtml);
|
||||
}
|
||||
});
|
||||
|
||||
editor.on('update', ({ editor }) => emit('update:html', editor.getHTML()));
|
||||
function getCorrectedHtml() {
|
||||
return patchTipTapHTML(editor.getHTML());
|
||||
}
|
||||
|
||||
function patchTipTapHTML(content: string | null) {
|
||||
if (content === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(content, 'text/html');
|
||||
|
||||
const listItems = doc.querySelectorAll('li');
|
||||
listItems.forEach((li) => {
|
||||
const p = li.querySelector('p');
|
||||
if (p) {
|
||||
while (p.firstChild) {
|
||||
li.insertBefore(p.firstChild, p);
|
||||
}
|
||||
p.remove();
|
||||
}
|
||||
});
|
||||
return doc.body.innerHTML;
|
||||
}
|
||||
|
||||
editor.on('update', () => emit('update:html', getCorrectedHtml()));
|
||||
|
||||
tryOnBeforeUnmount(() => {
|
||||
editor.destroy();
|
||||
|
||||
Reference in new issue
Block a user