Skip to content

Commit 2e8d12f

Browse files
authored
Merge pull request #77 from Ericsson/png-copiable
Make generated PNG copiable
2 parents a9a5d9b + 095e79e commit 2e8d12f

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

src/plantuml_gui/static/script.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -317,29 +317,31 @@ function buttonEventListeners() {
317317
displayErrorMessage(`Error with fetch API: ${error.message}`, error);
318318
}
319319
})
320-
321320
document.getElementById('png').addEventListener('click', async () => {
322321
try {
323322
const plantuml = trimlines(editor.session.getValue());
324323
const response = await fetch("/renderPNG", {
325324
method: "POST",
326-
headers: {
327-
'Content-Type': 'application/json'
328-
},
329-
body: JSON.stringify({
330-
'plantuml': plantuml
331-
})
325+
headers: { 'Content-Type': 'application/json' },
326+
body: JSON.stringify({ 'plantuml': plantuml })
332327
});
333328

334329
const blob = await response.blob();
335-
const imageUrl = URL.createObjectURL(blob);
336-
const newTab = window.open('', '_blank');
337-
338-
const img = newTab.document.createElement('img');
339-
img.src = imageUrl;
340-
newTab.document.body.appendChild(img);
341-
newTab.document.body.style.textAlign = 'center';
342-
newTab.document.close();
330+
331+
// Convert blob → base64 Data URL to make image copiable
332+
const reader = new FileReader();
333+
reader.onloadend = () => {
334+
const imageUrl = reader.result; // data:image/png;base64,...
335+
336+
const newTab = window.open('', '_blank');
337+
const img = newTab.document.createElement('img');
338+
img.src = imageUrl;
339+
newTab.document.body.appendChild(img);
340+
newTab.document.body.style.textAlign = 'center';
341+
newTab.document.close();
342+
};
343+
344+
reader.readAsDataURL(blob);
343345

344346
} catch (error) {
345347
displayErrorMessage(`Error with fetch API: ${error.message}`, error);

uv.lock

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)