mirror of
https://git.sr.ht/~magic_rb/dotfiles
synced 2024-11-22 16:04:25 +01:00
Embed SVGs when exporting Org-Roam
Signed-off-by: Magic_RB <magic_rb@redalder.org>
This commit is contained in:
parent
13924a217f
commit
71dc54cb68
|
@ -126,25 +126,61 @@ Lastly a bookmarklet in Firefox.
|
|||
#+begin_src emacs-lisp :tangle no :results none
|
||||
(require 'org-roam-export)
|
||||
|
||||
(require 'nxml-mode)
|
||||
|
||||
(defun magic_rb/org-html-publish-to-html-continue (plist filename pub-dir)
|
||||
(org-html-publish-to-html plist filename pub-dir))
|
||||
|
||||
(setq org-publish-project-alist
|
||||
`(("org"
|
||||
:base-directory "~/roam/"
|
||||
:publishing-function org-html-publish-to-html ;; magic_rb/org-html-publish-to-html-continue
|
||||
:publishing-directory "~/roam/published"
|
||||
:exclude "^.*$"
|
||||
:include ,(seq-map #'car
|
||||
(org-roam-db-query
|
||||
[:select [nodes:file]
|
||||
:from tags
|
||||
:left-join nodes
|
||||
:on (= tags:node-id nodes:id)
|
||||
:where (like tag (quote "%\"public-publish\""))]))
|
||||
)))
|
||||
(defcustom 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)
|
||||
|
||||
(org-publish "org" t)
|
||||
(cl-pushnew
|
||||
'(:html-embed-svg "HTML_EMBED_SVG" "html-embed-svg" org+-html-embed-svg)
|
||||
(org-export-backend-options (org-export-get-backend 'html)))
|
||||
|
||||
(defun 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 (and
|
||||
(member (plist-get info :html-embed-svg) '("yes" "t" t))
|
||||
(string-equal "svg" (file-name-extension source)))
|
||||
(with-temp-buffer
|
||||
(message "embedding svg: %s" source)
|
||||
(insert-file-contents source)
|
||||
(with-syntax-table nxml-mode-syntax-table
|
||||
(while (and (search-forward "<svg") ;; barfs if a "<svg" is not found in code
|
||||
(nth 8 (syntax-ppss)))))
|
||||
(delete-region (point-min) (match-beginning 0))
|
||||
(buffer-string))
|
||||
(funcall fun (concat "../" source) attributes info)))
|
||||
|
||||
(advice-add 'org-html--format-image :around #'org+-html-svg-image-embed)
|
||||
|
||||
(setq org-publish-project-alist
|
||||
`(("org"
|
||||
:base-directory "~/roam/"
|
||||
:publishing-function org-html-publish-to-html ;; magic_rb/org-html-publish-to-html-continue
|
||||
:publishing-directory "~/roam/published"
|
||||
:exclude "^.*$"
|
||||
:include ,(seq-map #'car
|
||||
(org-roam-db-query
|
||||
[:select [nodes:file]
|
||||
:from tags
|
||||
:left-join nodes
|
||||
:on (= tags:node-id nodes:id)
|
||||
:where (like tag (quote "%\"public-publish\""))]))
|
||||
)))
|
||||
|
||||
(org-publish "org" t)
|
||||
#+end_src
|
||||
|
||||
https://emacs.stackexchange.com/questions/59149/why-is-latex-preview-and-latex-to-html-export-via-dvisvgm-not-working-in-org-mod
|
||||
|
|
Loading…
Reference in a new issue