lang/org: add inline base64/http(s) image support
Adds inline image preview support for http/https links, as well as base64 encode image support with the img protocol. e.g. Examples: [[http://domain.com/some/image.png]] [[https://raw.githubusercontent.com/hlissner/doom-emacs/screenshots/company.png]] [[img:iVBORw0KGgoAAAANSUhEUgAAACUAAAAuCAAAAACKMo8cAA...]]
This commit is contained in:
parent
fda4734164
commit
99b7b7f740
3 changed files with 28 additions and 3 deletions
|
@ -63,6 +63,28 @@
|
|||
(advice-add #'org-download--fullname
|
||||
:filter-return #'+org-attach*download-fullname))
|
||||
|
||||
(def-package! org-yt
|
||||
:after org
|
||||
:config
|
||||
(defun +org-inline-data-image (_protocol link _description)
|
||||
"Interpret LINK as base64-encoded image data."
|
||||
(base64-decode-string link))
|
||||
|
||||
(defun +org-image-link (protocol link _description)
|
||||
"Interpret LINK as base64-encoded image data."
|
||||
(when (image-type-from-file-name link)
|
||||
(let ((buf (url-retrieve-synchronously (concat protocol ":" link))))
|
||||
;; TODO Better error handling
|
||||
(cl-assert buf nil "Download of image \"%s\" failed." link)
|
||||
(with-current-buffer buf
|
||||
(goto-char (point-min))
|
||||
(re-search-forward "\r?\n\r?\n")
|
||||
(buffer-substring-no-properties (point) (point-max))))))
|
||||
|
||||
(org-link-set-parameters "http" :image-data-fun #'+org-image-link)
|
||||
(org-link-set-parameters "https" :image-data-fun #'+org-image-link)
|
||||
(org-link-set-parameters "img" :image-data-fun #'+org-inline-data-image))
|
||||
|
||||
|
||||
;;
|
||||
;; Bootstrap
|
||||
|
|
|
@ -119,8 +119,10 @@ If on a:
|
|||
(org-toggle-latex-fragment))
|
||||
|
||||
(`link
|
||||
(let ((path (org-element-property :path (org-element-lineage context '(link) t))))
|
||||
(if (and path (image-type-from-file-name path))
|
||||
(let* ((lineage (org-element-lineage context '(link) t))
|
||||
(path (org-element-property :path lineage)))
|
||||
(if (or (equal (org-element-property :type lineage) "img")
|
||||
(and path (image-type-from-file-name path)))
|
||||
(+org/refresh-inline-images)
|
||||
(org-open-at-point))))
|
||||
|
||||
|
|
|
@ -15,7 +15,8 @@
|
|||
(package! org-pdfview))
|
||||
|
||||
(when (featurep! +attach)
|
||||
(package! org-download))
|
||||
(package! org-download)
|
||||
(package! org-yt :recipe (:fetcher github :repo "TobiasZawada/org-yt")))
|
||||
|
||||
(when (featurep! +babel)
|
||||
(package! ob-mongo)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue