aboutsummaryrefslogtreecommitdiffstats
path: root/oni-org
diff options
context:
space:
mode:
authorGravatar Tom Willemse2021-07-01 19:05:46 -0700
committerGravatar Tom Willemse2021-07-01 19:05:46 -0700
commitb80c4f4321c443c38fbdc3a7e3cc4dc52faa2afd (patch)
treeb4704fe05b006c26c6e5cac9f804df848b5055a3 /oni-org
parent763395814f2bff864850ae56dc1926b9e2c5c360 (diff)
downloademacs-config-b80c4f4321c443c38fbdc3a7e3cc4dc52faa2afd.tar.gz
emacs-config-b80c4f4321c443c38fbdc3a7e3cc4dc52faa2afd.zip
[oni-org] Add code to embed SVG images in output
This was taken from https://emacs.stackexchange.com/a/57433
Diffstat (limited to 'oni-org')
-rw-r--r--oni-org/oni-org.el38
1 files changed, 37 insertions, 1 deletions
diff --git a/oni-org/oni-org.el b/oni-org/oni-org.el
index fab80b2..9dbad99 100644
--- a/oni-org/oni-org.el
+++ b/oni-org/oni-org.el
@@ -4,7 +4,7 @@
;; Author: Tom Willemse <tom@ryuslash.org>
;; 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)
;; 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))
(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)
;;; oni-org.el ends here