Add lists of SVG files to select for and/or exclude from embedding

This commit is contained in:
Gerard Vermeulen 2023-06-03 20:48:15 +02:00
parent ef080422a0
commit 1a92b1b0cc
1 changed files with 47 additions and 15 deletions

View File

@ -45,15 +45,18 @@
(org-export-define-derived-backend 'my-html 'html
:menu-entry
'(?h 1
((?M "As my-HTML buffer" org-my-html-export-as-html)
(?m "As my-HTML file" org-my-html-export-to-html)
(?O "As my-HTML file and open"
((?M "As MY-HTML buffer" org-my-html-export-as-html)
(?m "As MY-HTML file" org-my-html-export-to-html)
(?O "As MY-HTML file and open"
(lambda (a s v b)
(if a (org-my-html-export-to-html t s v b)
(org-open-file (org-my-html-export-to-html nil s v b)))))))
:options-alist
'((:with-html-svg-embedding "HTML_EMBED_SVG" ;; groks nil as "nil" in Org file!
"html-embed-svg" org-html-embed-svg))
'((:html-exclude-embed-svgs "HTML_EXCLUDE_EMBED_SVGS" nil
org-html-exclude-embed-svgs split)
(:html-select-embed-svgs "HTML_SELECT_EMBED_SVGS" nil
org-html-select-embed-svgs split)
(:with-html-svg-embedding nil "html-embed-svg" org-html-embed-svg))
:translate-alist
'((link . org-my-html-link)))
@ -63,8 +66,10 @@
;;;; Links :: Embed SVG
(defcustom org-html-embed-svg nil
"Non-nil means embed SVG images into exported my-HTML pages,
otherwise link to SVG images from exported my-HTML pages. Use
"Non-nil means embed SVG images into exported HTML pages,
otherwise link to SVG images from exported HTML pages.
This option can also be set with
#+OPTIONS: html-embed-svg:t
or
#+OPTIONS: html-embed-svg:nil
@ -73,16 +78,44 @@ to enable or disable SVG embedding in Org files."
:version "30.0"
:type 'boolean)
(defcustom org-html-exclude-embed-svgs nil
"List of SVG paths to exclude from SVG embedding.
This option overrules an `org-html-embed-svg' non-nil value.
It can also be set with the HTML_EXCLUDE_EMBED_SVGS keyword."
:group 'org-export-html
:version "30.0"
:type '(repeat (string :path "Path"))
:safe (lambda (x) (and (listp x) (cl-every #'stringp x))))
(defcustom org-html-select-embed-svgs nil
"List of SVG paths to select for SVG embedding.
This option overrules an `org-html-embed-svg' nil value.
It can also be set with the HTML_SELECT_EMBED_SVGS keyword."
:group 'org-export-html
:version "30.0"
:type '(repeat (string :path "Path"))
:safe (lambda (x) (and (listp x) (cl-every #'stringp x))))
;;; Transcode Functions
;;;; Link
(defun org--my-html-embed-svg-p (link)
"Check whether LINK links to an SVG file to embed."
(defun org--my-html-embed-svg-p (link path info)
"Check whether LINK and INFO specify to embed the SVG file named PATH.
LINK must have no contents and link to an SVG file. INFO may contain
lists of SVG files to select for and/or to exclude from embedding."
(and (not (org-element-contents link))
(let ((case-fold-search t))
(string-match-p ".svg\\'" (org-element-property :path link)))))
(string-match-p ".svg\\'" (org-element-property :path link)))
(or (and (plist-get info :with-html-svg-embedding)
(not (member path (plist-get info :html-exclude-embed-svgs))))
(and (not (plist-get info :with-html-svg-embedding))
(member path (plist-get info :html-select-embed-svgs))))))
(defun org--my-html-svg-contents (path)
"Return the SVG contents of the file named PATH."
@ -97,7 +130,7 @@ to enable or disable SVG embedding in Org files."
(buffer-string)))
(defun org-my-html-link (link desc info)
"Transcode a LINK object from Org to MY-HTML.
"Transcode a LINK object from Org to HTML.
DESC is the description part of the link, or the empty string.
INFO is a plist holding contextual information. See
`org-export-data'. This function can embed or link SVG images
@ -176,8 +209,7 @@ contrary to `org-html-link' which can only link such images."
;; Link type is handled by a special function.
((org-export-custom-protocol-maybe link desc 'html info))
;; Embed SVG.
((and (plist-get info :with-html-svg-embedding)
(org--my-html-embed-svg-p link))
((org--my-html-embed-svg-p link path info)
(org--my-html-svg-contents path))
;; Image file.
((and (plist-get info :html-inline-images)
@ -298,7 +330,7 @@ contrary to `org-html-link' which can only link such images."
;;;###autoload
(defun org-my-html-export-as-html
(&optional async subtreep visible-only body-only ext-plist)
"Export current buffer to a MY-HTML buffer.
"Export current buffer to an HTML buffer.
If narrowing is active in the current buffer, only export its
narrowed part.
@ -334,7 +366,7 @@ is non-nil."
;;;###autoload
(defun org-my-html-export-to-html
(&optional async subtreep visible-only body-only ext-plist)
"Export current buffer to a MY-HTML file.
"Export current buffer to an HTML file.
If narrowing is active in the current buffer, only export its
narrowed part.