obsidian-mind-map
obsidian-mind-map copied to clipboard
copy screenshot is placing a low quality png file of mind map instead of svg image
same problem
same problem
+1
https://stackoverflow.com/questions/23218174/how-do-i-save-export-an-svg-file-after-creating-an-svg-with-d3-js-ie-safari-an
我参考上面链接对插件做了一点小小修改, 现在copy screenshot
时复制到剪切板的是 svg xml string
.
这样虽然不能直接粘贴到其他图片处理软件,但是可以粘贴到text editor
手动保存为xx.svg
再进行导入.
下面是我修改的代码:
function copyImageToClipboard(svg) {
// var canvas = createCanvas(svg);
// var img = generateImage(svg, canvas, function () {
// canvas.toBlob(function (blob) {
// var item = new ClipboardItem({ "image/png": blob });
// navigator.clipboard.write([item]);
// new obsidian.Notice('Screenshot copied to the clipboard.');
// });
// });
//get svg source.
var serializer = new XMLSerializer();
var source = serializer.serializeToString(svg);
//add name spaces.
if(!source.match(/^<svg[^>]+xmlns="http\:\/\/www\.w3\.org\/2000\/svg"/)){
source = source.replace(/^<svg/, '<svg xmlns="http://www.w3.org/2000/svg"');
}
if(!source.match(/^<svg[^>]+"http\:\/\/www\.w3\.org\/1999\/xlink"/)){
source = source.replace(/^<svg/, '<svg xmlns:xlink="http://www.w3.org/1999/xlink"');
}
//add xml declaration
source = '<?xml version="1.0" standalone="no"?>\r\n' + source;
navigator.clipboard.writeText(source);
new obsidian.Notice('Screenshot copied to the clipboard.');
}