Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transclusion of [attachment:<file>] links from org-attach? #198

Open
ashgillman opened this issue Aug 1, 2023 · 5 comments
Open

Transclusion of [attachment:<file>] links from org-attach? #198

ashgillman opened this issue Aug 1, 2023 · 5 comments

Comments

@ashgillman
Copy link

Hi, thanks for a great contribution to the Org Mode ecosystem.

I wonder if there is a known way to transclude images included with Attachment links?

I've tried :expand-links without luck.

Many thanks,
Ash

@nobiot
Copy link
Owner

nobiot commented Aug 1, 2023

I do not know a way; I don’t use attachment links.

But… isn’t it just a link? Then why not use it as a link?

@ashgillman
Copy link
Author

The transcluded link won't work. I guess its because [attachment:] is a context-unique link. It means the file relative to the current attachment directory, and the attachment directory is derived from the current context ID.

@jtoloe
Copy link

jtoloe commented Aug 11, 2023

Attachment links can be expanded by org-attach-expand. Perhaps this could be added to :expand-links?

On the other hand, the real question might be how to treat properties of the transcluded source. Should the properties of the source or the heading that the transcluded region is in be respected?

@jtoloe
Copy link

jtoloe commented Aug 11, 2023

This works for me:

(defun org-transclusion-content-filter-expand-links (link)
  "Convert LINK to an absolute filename.
LINK is assumed to be an Org element. This function does nothing
to LINK if the link is already absolute.

The current buffer is assumed to be the source buffer for the
transclusion."
  (when (or
         (string-equal "file" (org-element-property :type link))
         (string-equal "attachment" (org-element-property :type link)))
    (let ((type (org-element-property :type link))
          (path (org-element-property :path link)))
      (unless (file-name-absolute-p path)
        (setq link (org-element-put-property
                    link :path
                    (if (string-equal "attachment" type)
                        (org-attach-expand path)
                      (expand-file-name
                       path
                       (file-name-directory (buffer-file-name (current-buffer)))))))
        (if (string-equal "attachment" type)
            (setq link (org-element-put-property
                        link :type "file")))
        link))))

@lucasvreis
Copy link

lucasvreis commented Sep 6, 2023

This may be more or less equivalent to @jtoloe function, but I have this snippet in the gist below to support ID and attachment links with anchors that I've been using for a while. It uses org-transclusion-add-functions instead of :expand-links. Posting here if it's useful to someone.
https://gist.github.com/lucasvreis/24f378f6f9a95f8c17906cb351bab2e1

Edit: actually, my gist does something completely different (I misunderstood the question): it adds support for attachment links as the transclusion link, instead of expanding their occurrences within the transcluded content into absolute links.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants