From e98f74f1696b1568767171fa5e3548e9bfb62a95 Mon Sep 17 00:00:00 2001 From: Sahatsawat Kanpai Date: Mon, 30 Dec 2024 11:59:18 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=84=20htmlData=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/export.ts | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/export.ts b/src/export.ts index 02dfe5a..ad0693c 100644 --- a/src/export.ts +++ b/src/export.ts @@ -37,11 +37,30 @@ export default class Export extends Plugin { // } ); // Insert a text into the editor after clicking the button. - this.listenTo( view, 'execute', async () => { - asBlob(this.editor.getData()).then((data: any) => { - saveAs(data, 'file.docx') // save as docx file - }) // asBlob() return Promise + // this.listenTo( view, 'execute', async () => { + // asBlob(this.editor.getData()).then((data: any) => { + // saveAs(data, 'file.docx') // save as docx file + // }) // asBlob() return Promise + // editor.editing.view.focus(); + // } ); + + // POST fetch docx and download + this.listenTo( view, 'execute', async () => { + fetch('http://localhost:3000/docx', { + method: 'POST', + body: JSON.stringify({ htmlData: this.editor.getData() }), + headers: { + 'Content-Type': 'application/json' + } + }) + .then(response => response.blob()) + .then(blob => { + saveAs(blob, 'stou.docx') // save as docx file + }) + .catch(error => { + console.error('Error:', error); + }); editor.editing.view.focus(); } );