📄 htmlData support

This commit is contained in:
Sahatsawat Kanpai 2024-12-30 11:59:18 +07:00
parent 19930d8022
commit e98f74f169

View File

@ -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<Blob|Buffer>
// this.listenTo( view, 'execute', async () => {
// asBlob(this.editor.getData()).then((data: any) => {
// saveAs(data, 'file.docx') // save as docx file
// }) // asBlob() return Promise<Blob|Buffer>
// 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();
} );