d2-mode icon indicating copy to clipboard operation
d2-mode copied to clipboard

Seems Imagemagick didn't handle SVG well as expected.

Open suliveevil opened this issue 3 years ago • 9 comments

截屏2022-11-28 10 23 40

suliveevil avatar Nov 28 '22 02:11 suliveevil

Thanks @suliveevil. will get back to you on this. As some level this is blocked by #8 from my end. It would be great if eventually d2 supports pngs. SVG's just don't play as well with emacs. I think I can get it to work, but I need to fix #8 first

andorsk avatar Nov 28 '22 07:11 andorsk

confirmed repeatability image Browser renders correctly: image

andorsk avatar Nov 28 '22 11:11 andorsk

This a more general issue with imagemagik and svgs convert input.svg output.png reproduces the issue.

andorsk avatar Nov 28 '22 11:11 andorsk

The way I see it, there are two fixes:

  1. See if there's a fix for imagemagick and svgs.
  2. See if convert to png first with some other command, then just read that. I'm leaning toward that.

andorsk avatar Nov 28 '22 11:11 andorsk

Or we may should find another tool to convert svg to png?

suliveevil avatar Nov 28 '22 12:11 suliveevil

yea...possible. i'll need to look into it and get back on this.

andorsk avatar Nov 28 '22 12:11 andorsk

referencing here https://github.com/andorsk/d2-mode/issues/8

andorsk avatar Nov 29 '22 09:11 andorsk

since this is an emacs related issue, I don't see an easy way around this without saying "upgrade your emacs", however I have added support for a complementing method at #19 , which allows you to open up the browser directly from emacs through the new supported commands:

(defvar d2-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map (kbd "C-c C-c") 'd2-compile)
    (define-key map (kbd "C-c C-f") 'd2-compile-file)
    (define-key map (kbd "C-c C-b") 'd2-compile-buffer)
    (define-key map (kbd "C-c C-r") 'd2-compile-region)
    (define-key map (kbd "C-c C-h") 'd2-compile-file-and-browse)
    (define-key map (kbd "C-c C-j") 'd2-compile-buffer-and-browse)
    (define-key map (kbd "C-c C-k") 'd2-compile-region-and-browse)
    (define-key map (kbd "C-c C-o") 'd2-open-browser)
    (define-key map (kbd "C-x C-o") 'd2-view-current-svg)
    (define-key map (kbd "C-c C-d") 'd2-open-doc)
    map))

This allows the browser to render the svg, which should work pretty well.

andorsk avatar Nov 29 '22 20:11 andorsk

d2 is able to convert to png, e.g. d2 input.d2 out.png. i'm not 100% sure it would work in this context though, as it involves using headless browsers.

we also ran into some subpar svg rendering when building the Obsidian integration. we got around this by base64 encoding the SVGs. didn't end up going with that in the end, but it did work

alixander avatar Dec 08 '22 06:12 alixander