Embed svg.

This commit is contained in:
Yujie Wen 2015-07-25 22:55:53 +08:00
parent 528d1ddca9
commit 74b9a3c8cb
1 changed files with 26 additions and 16 deletions

View File

@ -686,25 +686,35 @@ CONTENTS is nil. INFO is a plist holding contextual information."
(case (intern key) (case (intern key)
(REVEAL (org-reveal-parse-keyword-value value)) (REVEAL (org-reveal-parse-keyword-value value))
(REVEAL_HTML value)))) (REVEAL_HTML value))))
(defun org-reveal-embedded-svg (link)
"Embed the SVG content into Reveal HTML."
(with-temp-buffer
(insert-file-contents-literally path)
(let ((start (re-search-forward "<[ \t\n]*svg[ \t\n]"))
(end (re-search-forward "<[ \t\n]*/svg[ \t\n]*>")))
(concat "<svg " (buffer-substring-no-properties start end)))))
(defun org-reveal--format-image-data-uri (link info) (defun org-reveal--format-image-data-uri (link info)
"Generate the data URI for the image referenced by LINK." "Generate the data URI for the image referenced by LINK."
(let ((path (org-element-property :path link))) (let* ((path (org-element-property :path link))
(org-html-close-tag (ext (downcase (file-name-extension path))))
"img" (if (string= ext "svg")
(org-html--make-attribute-string (org-reveal-embedded-svg link)
(list :src (org-html-close-tag
(concat "img"
"data:image/" (org-html--make-attribute-string
;; Image type (list :src
(downcase (file-name-extension path)) (concat
";base64," "data:image/"
;; Base64 content ;; Image type
(with-temp-buffer (downcase (file-name-extension path))
(insert-file-contents-literally path) ";base64,"
(base64-encode-region 1 (point-max)) ;; Base64 content
(buffer-string))))) (with-temp-buffer
info))) (insert-file-contents-literally path)
(base64-encode-region 1 (point-max))
(buffer-string)))))
info))))
(defun org-reveal-link (link desc info) (defun org-reveal-link (link desc info)
"Transcode a LINK object from Org to Reveal. The result is "Transcode a LINK object from Org to Reveal. The result is