Check if image url is readable.

This commit is contained in:
Yujie Wen 2015-07-29 22:57:21 +08:00
parent d5a0d569e4
commit 4adf7cde86
1 changed files with 18 additions and 12 deletions

View File

@ -739,7 +739,7 @@ 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) (defun org-reveal-embedded-svg (path)
"Embed the SVG content into Reveal HTML." "Embed the SVG content into Reveal HTML."
(with-temp-buffer (with-temp-buffer
(insert-file-contents-literally path) (insert-file-contents-literally path)
@ -747,12 +747,11 @@ CONTENTS is nil. INFO is a plist holding contextual information."
(end (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))))) (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 path 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* ((ext (downcase (file-name-extension path))))
(ext (downcase (file-name-extension path))))
(if (string= ext "svg") (if (string= ext "svg")
(org-reveal-embedded-svg link) (org-reveal-embedded-svg path)
(org-html-close-tag (org-html-close-tag
"img" "img"
(org-html--make-attribute-string (org-html--make-attribute-string
@ -760,7 +759,7 @@ CONTENTS is nil. INFO is a plist holding contextual information."
(concat (concat
"data:image/" "data:image/"
;; Image type ;; Image type
(downcase (file-name-extension path)) ext
";base64," ";base64,"
;; Base64 content ;; Base64 content
(with-temp-buffer (with-temp-buffer
@ -773,12 +772,19 @@ CONTENTS is nil. INFO is a plist holding contextual information."
"Transcode a LINK object from Org to Reveal. The result is "Transcode a LINK object from Org to Reveal. The result is
identical to ox-html expect for image links. When `org-reveal-single-file' is t, identical to ox-html expect for image links. When `org-reveal-single-file' is t,
the result is the Data URIs of the referenced image." the result is the Data URIs of the referenced image."
(if (and (plist-get info :reveal-single-file) (let* ((want-embed-image (and (plist-get info :reveal-single-file)
(plist-get info :html-inline-images) (plist-get info :html-inline-images)
(org-export-inline-image-p link (plist-get info :html-inline-image-rules))) (org-export-inline-image-p
;; Export image data URIs. link (plist-get info :html-inline-image-rules))))
(org-reveal--format-image-data-uri link info) (raw-path (org-element-property :path link))
(org-html-link link desc info))) (clean-path (replace-regexp-in-string "^file:///" "" raw-path))
(can-embed-image (and want-embed-image
(file-readable-p clean-path))))
(if can-embed-image
(org-reveal--format-image-data-uri link clean-path info)
(if want-embed-image
(error "Cannot embed image %s" raw-path)
(org-html-link link desc info)))))
(defun org-reveal-plain-list (plain-list contents info) (defun org-reveal-plain-list (plain-list contents info)
"Transcode a PLAIN-LIST element from Org to Reveal. "Transcode a PLAIN-LIST element from Org to Reveal.