lynchjames / obsidian-mind-map

An Obsidian plugin for displaying markdown notes as mind maps using Markmap.
MIT License
1.1k stars 77 forks source link

copy screenshot is placing a low quality png file of mind map instead of svg image #53

Open sinayanaik opened 3 years ago

troilus commented 3 years ago

same problem image

acsoto commented 2 years ago

same problem

ssmmtt commented 2 years ago

+1

notmmaoo commented 2 years ago

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.');
}