Comments (2)
This is a bug in Org, as it hardcodes what type of link can preview an image. I modified the relevant function just to prove the concept (I SIMPLIFIED IT AND IT SHOULD NOT BE USED AS-IS):
(defun org-display-inline-images (&optional include-linked refresh beg end)
"Display inline images.
An inline image is a link which follows either of these
conventions:
1. Its path is a file with an extension matching return value
from `image-file-name-regexp' and it has no contents.
2. Its description consists in a single link of the previous
type. In this case, that link must be a well-formed plain
or angle link, i.e., it must have an explicit \"file\" or
\"attachment\" type.
Equip each image with the key-map `image-map'.
When optional argument INCLUDE-LINKED is non-nil, also links with
a text description part will be inlined. This can be nice for
a quick look at those images, but it does not reflect what
exported files will look like.
When optional argument REFRESH is non-nil, refresh existing
images between BEG and END. This will create new image displays
only if necessary.
BEG and END define the considered part. They default to the
buffer boundaries with possible narrowing."
(interactive "P")
(when (display-graphic-p)
(when refresh
(org-remove-inline-images beg end)
(when (fboundp 'clear-image-cache) (clear-image-cache)))
(let ((end (or end (point-max))))
(org-with-point-at (or beg (point-min))
(let* ((case-fold-search t)
(file-extension-re (image-file-name-regexp))
(link-abbrevs (mapcar #'car
(append org-link-abbrev-alist-local
org-link-abbrev-alist)))
;; Check absolute, relative file names and explicit
;; "file:" links. Also check link abbreviations since
;; some might expand to "file" links.
(file-types-re
(format "\\[\\[\\(?:file%s:\\|denote:\\|attachment:\\|[./~]\\)\\|\\]\\[\\(<?\\(?:file\\|denote\\|attachment\\):\\)"
(if (not link-abbrevs) ""
(concat "\\|" (regexp-opt link-abbrevs))))))
(while (re-search-forward file-types-re end t)
(let* ((link (org-element-lineage
(save-match-data (org-element-context))
'(link) t))
(linktype (org-element-property :type link))
(inner-start (match-beginning 1))
(path
(cond
((equal "denote" linktype)
(org-element-property :path link))
;; No link at point; no inline image.
((not link) nil)
;; File link without a description. Also handle
;; INCLUDE-LINKED here since it should have
;; precedence over the next case. I.e., if link
;; contains filenames in both the path and the
;; description, prioritize the path only when
;; INCLUDE-LINKED is non-nil.
((or (not (org-element-property :contents-begin link))
include-linked)
(and (or (equal "file" linktype)
(equal "attachment" linktype))
(org-element-property :path link)))
;; Link with a description. Check if description
;; is a filename. Even if Org doesn't have syntax
;; for those -- clickable image -- constructs, fake
;; them, as in `org-export-insert-image-links'.
((not inner-start) nil)
(t
(org-with-point-at inner-start
(and (looking-at
(if (char-equal ?< (char-after inner-start))
org-link-angle-re
org-link-plain-re))
;; File name must fill the whole
;; description.
(= (org-element-property :contents-end link)
(match-end 0))
(progn
(setq linktype (match-string 1))
(match-string 2))))))))
(when path
(let ((file (cond
((equal "denote" linktype)
(denote-link--ol-resolve-link-to-target path))
((equal "attachment" linktype)
(require 'org-attach)
(ignore-errors (org-attach-expand path)))
(t
(expand-file-name path)))))
(when file
(let ((width (org-display-inline-image--width link))
(old (get-char-property-and-overlay
(org-element-property :begin link)
'org-image-overlay)))
(if (and (car-safe old) refresh)
(image-flush (overlay-get (cdr old) 'display))
(let ((image (org--create-inline-image file width)))
(when image
(let ((ov (make-overlay
(org-element-property :begin link)
(progn
(goto-char
(org-element-property :end link))
(skip-chars-backward " \t")
(point)))))
;; FIXME: See bug#59902. We cannot rely
;; on Emacs to update image if the file
;; has changed.
(image-flush image)
(overlay-put ov 'display image)
(overlay-put ov 'face 'default)
(overlay-put ov 'org-image-overlay t)
(overlay-put
ov 'modification-hooks
(list 'org-display-inline-remove-overlay))
(when (boundp 'image-map)
(overlay-put ov 'keymap image-map))
(push ov org-inline-image-overlays))))))))))))))))
What we need is for the Org link infrastructure to provide a property that handles image previewing. We will then add support for it. The function org-display-inline-images
will have to be updated accordingly to handle the path resolution scheme of custom links, instead of hardcoding the file
or attachment
types.
I do not have time to report this as a bug in Org, nor to prepare the relevant patch. I am happy to help if someone takes the initiative.
from denote.
Oh, this is interesting! I will check how Org handles images and report back to you.
from denote.
Related Issues (20)
- A `denote-filetype-heuristics` variant to help other code HOT 5
- sort by title outside of denote-directory HOT 5
- I use `denote-rename-file` as my main file renaming UI HOT 6
- `denote--edit-front-matter-p` docstring vs behavior HOT 1
- Possible to create a denote file outside denote-directory? HOT 5
- markdown links HOT 3
- Commit 232bd90 does not only apply to signatures HOT 13
- is it possible to create single tag with multiple words seperated by delimter? HOT 3
- Backlink buffer aware of org heading HOT 2
- Can't add link to file from within org-capture: "The current file type is not recognized by Denote" HOT 8
- Problem due to overloading `no-confirm` for "save" HOT 7
- How can I figure out which version of denote is currently used? HOT 4
- Templates are not working in denote-org-capture-with-prompts HOT 5
- Cannot add a denote link in `org-add-log-note` HOT 2
- update the link description if the target title is changed HOT 7
- Announcement: Some upcoming features available in my fork HOT 15
- Add support for adding keywords and/or removing keywords when using `denote-dired-rename-marked-files`
- Allow listing backlinks for denote files that are not notes HOT 3
- denote-org-extras-convert-links-to-file-type ignores value of org-link-file-path-type HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from denote.