branch: externals/org-transclusion commit 20ac54f54a3a40e1ffd433569c064fb7c3acfa21 Author: Noboru Ota <m...@nobiot.com> Commit: Noboru Ota <m...@nobiot.com>
(WIP) add filter to convert filenames in links from rel to abs #145 It is still WIP. In this commit, a new function in the content filter has been added. It will iterate every link Org element and covernt relative filename into absolute. It does nothing if the link is already an absolute. --- org-transclusion.el | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/org-transclusion.el b/org-transclusion.el index 0934630b84..8668b89a1c 100644 --- a/org-transclusion.el +++ b/org-transclusion.el @@ -17,7 +17,7 @@ ;; Author: Noboru Ota <m...@nobiot.com> ;; Created: 10 October 2020 -;; Last modified: 29 January 2022 +;; Last modified: 27 May 2022 ;; URL: https://github.com/nobiot/org-transclusion ;; Keywords: org-mode, transclusion, writing @@ -1162,11 +1162,25 @@ etc.)." (setq obj (org-element-map obj org-element-all-elements #'org-transclusion-content-filter-org-only-contents nil nil '(section) nil))) + ;; Convert relative filename in links to absolute (abbreviated) + (org-element-map obj 'link #'org-transclusion-content-absolute-links) + (list :src-content (org-element-interpret-data obj) :src-buf (current-buffer) :src-beg (point-min) :src-end (point-max)))))) +(defun org-transclusion-content-absolute-links (link) + "." + (when (string-equal "file" (org-element-property :type link)) + (let ((raw-link (org-element-property :raw-link link))) + (unless (file-name-absolute-p raw-link) + (org-element-put-property + link :path + (expand-file-name + raw-link + (file-name-directory (buffer-file-name (current-buffer))))))))) + (defun org-transclusion-content-filter-org-exclude-elements (data) "Exclude specific elements from DATA. The elements to be excluded are defined by customizing variable