1
0
Fork 0

[oni-org] Add code to embed SVG images in output

This was taken from https://emacs.stackexchange.com/a/57433
This commit is contained in:
Tom Willemse 2021-07-01 19:05:46 -07:00
parent 763395814f
commit b80c4f4321

View file

@ -4,7 +4,7 @@
;; Author: Tom Willemse <tom@ryuslash.org> ;; Author: Tom Willemse <tom@ryuslash.org>
;; Keywords: local ;; Keywords: local
;; Version: 2021.0630.150728 ;; Version: 2021.0701.185951
;; Package-Requires: (oni-yasnippet oni-alert oni-hydra org org-contrib org-bullets org-edna diminish all-the-icons olivetti) ;; Package-Requires: (oni-yasnippet oni-alert oni-hydra org org-contrib org-bullets org-edna diminish all-the-icons olivetti)
;; This program is free software; you can redistribute it and/or modify ;; This program is free software; you can redistribute it and/or modify
@ -580,5 +580,41 @@ After running it once remove it from `org-capture-after-finalize-hook'."
(setq org-refile-targets '((nil . (:maxlevel . 10)) (setq org-refile-targets '((nil . (:maxlevel . 10))
(org-default-notes-file . (:maxlevel . 10)))) (org-default-notes-file . (:maxlevel . 10))))
;;; Export
(require 'ox-html)
(require 'nxml-mode)
;; From https://emacs.stackexchange.com/a/57433
(defcustom oni-org-html-embed-svg nil
"Embed SVG images.
You can set this variable in Org files with
#+HTML_EMBED_SVG: t
or
#+OPTIONS: html-embed-svg:t"
:type 'boolean
:group 'org-export-html)
(cl-pushnew
'(:html-embed-svg "HTML_EMBED_SVG" "html-embed-svg" oni-org-html-embed-svg)
(org-export-backend-options (org-export-get-backend 'html)))
(defun oni-org-html-svg-image-embed (fun source attributes info)
"Make embedding of SVG images possible in org HTML export.
SVG images are embedded if :html-embed-svg is non-nil in the plist INFO.
Otherwise FUN called with SOURCE, ATTRIBUTES, and INFO as arguments.
SOURCE is the file name of the SVG file.
This is an around advice for org-html--svg-image as FUN."
(if (member (plist-get info :html-embed-svg) '("yes" "t" t))
(with-temp-buffer
(insert-file-contents source)
(with-syntax-table nxml-mode-syntax-table
(while (and (search-forward "<svg" nil t)
(nth 8 (syntax-ppss))))
(delete-region (point-min) (match-beginning 0))
(buffer-string)))
(funcall fun source attributes info)))
(advice-add 'org-html--svg-image :around #'oni-org-html-svg-image-embed)
(provide 'oni-org) (provide 'oni-org)
;;; oni-org.el ends here ;;; oni-org.el ends here