Skip to content

Commit

Permalink
client,server: Set up SVG rendering for mindmap
Browse files Browse the repository at this point in the history
  • Loading branch information
eliandoran committed Sep 1, 2024
1 parent ad88042 commit 1437df7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/public/app/services/content_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async function getRenderedContent(entity, options = {}) {
else if (type === 'code') {
await renderCode(entity, $renderedContent);
}
else if (type === 'image' || type === 'canvas') {
else if (['image', 'canvas', 'mindMap'].includes(type)) {
renderImage(entity, $renderedContent, options);
}
else if (!options.tooltip && ['file', 'pdf', 'audio', 'video'].includes(type)) {
Expand Down
12 changes: 11 additions & 1 deletion src/public/app/widgets/type_widgets/mind_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,18 @@ export default class MindMapWidget extends TypeWidget {
return;
}

const svgContent = await this.mind.exportSvg().text();
return {
content: mind.getDataString()
content: mind.getDataString(),
attachments: [
{
role: "image",
title: "mindmap-export.svg",
mime: "image/svg+xml",
content: svgContent,
position: 0
}
]
};
}

Expand Down
4 changes: 3 additions & 1 deletion src/routes/api/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ function returnImageInt(image: BNote | BRevision | null, res: Response) {
if (!image) {
res.set('Content-Type', 'image/png');
return res.send(fs.readFileSync(`${RESOURCE_DIR}/db/image-deleted.png`));
} else if (!["image", "canvas", "mermaid"].includes(image.type)) {
} else if (![ "image", "canvas", "mermaid", "mindMap" ].includes(image.type)) {
return res.sendStatus(400);
}

if (image.type === 'canvas') {
renderSvgAttachment(image, res, 'canvas-export.svg');
} else if (image.type === 'mermaid') {
renderSvgAttachment(image, res, 'mermaid-export.svg');
} else if (image.type === "mindMap") {
renderSvgAttachment(image, res, 'mindmap-export.svg');
} else {
res.set('Content-Type', image.mime);
res.set("Cache-Control", "no-cache, no-store, must-revalidate");
Expand Down

0 comments on commit 1437df7

Please sign in to comment.