Max Nikulin <maniku...@gmail.com> writes:

> [[file:~/examples/org/odt-id/file-b.org]] link is exported as 
> ./file:///home/user/examples/org/odt-id/file-b.org

Thanks!
See the attached new version of the patch.

>From 8ee8528366bbf31ed8510f005e032176711d15b9 Mon Sep 17 00:00:00 2001
Message-Id: <8ee8528366bbf31ed8510f005e032176711d15b9.1667280462.git.yanta...@posteo.net>
From: Ihor Radchenko <yanta...@posteo.net>
Date: Mon, 31 Oct 2022 14:11:19 +0800
Subject: [PATCH v2] org-odt-link: Fix relative file links

* lisp/ox-odt.el (org-odt-link): Append an extra "../" to relative
links.  This is needed to conform with OpenOffice convention to treat
base path inside the odt archive.  The path containing the odt file is
thus "../".

Reported-by: Ihor Radchenko <yanta...@posteo.net>
Link: https://orgmode.org/list/87ilkc30wd.fsf@localhost
---
 lisp/ox-odt.el | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el
index 15a9cf2de..e4fb7eb84 100644
--- a/lisp/ox-odt.el
+++ b/lisp/ox-odt.el
@@ -2688,7 +2688,16 @@ (defun org-odt-link (link desc info)
 		((member type '("http" "https" "ftp" "mailto"))
 		 (concat type ":" raw-path))
 		((string= type "file")
-		 (org-export-file-uri raw-path))
+                 (pcase (org-export-file-uri raw-path)
+                   (`(and (pred #'file-name-absolute-p) ,path)
+                    path)
+                   (path
+                    (if (string-prefix-p "file://" path)
+                        path
+                      ;; OpenOffice treats base directory inside the odt
+                      ;; archive.  The directory containing the odt file
+                      ;; is "../".
+                      (concat "../" path)))))
 		(t raw-path)))
 	 ;; Convert & to &amp; for correct XML representation
 	 (path (replace-regexp-in-string "&" "&amp;" path)))
-- 
2.35.1

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

Reply via email to