emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Max Nikulin <manikulin@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [BUG] ox-odt file: links are not pointing to the real files (was: [BUG] ox-odt fails for org-id links (e.g., from org-roam v2) [9.5.2 (9.5.2-gfbff08 @ /home/moritz/.emacs.d/elpa/27.2/develop/org-9.5.2/)])
Date: Wed, 02 Nov 2022 05:04:03 +0000	[thread overview]
Message-ID: <87pme6kkvw.fsf@localhost> (raw)
In-Reply-To: <tjrchm$htq$1@ciao.gmane.io>

[-- Attachment #1: Type: text/plain, Size: 1035 bytes --]

Max Nikulin <manikulin@gmail.com> writes:

>> -		 (org-export-file-uri raw-path))
>> +                 (pcase (org-export-file-uri raw-path)
>> +                   (`(and (pred #'file-name-absolute-p) ,path)
>> +                    path)
>
> I am in doubts if this branch may be executed at all. For absolute file 
> names `org-export-file-uri' adds "file:" prefix so I expect that 
> `file-name-absolute-p' is always false.

You are indeed right.
See the attached new version of the patch.

> This time I am not lucky enough to accidentally face a case with invalid 
> link URI. However I do not think that for the link
>
>       [[file:file-b.org]]
>
> "../file-b.org" is appropriate default description. I do not expect 
> "../" here.

I also noticed this, but I feel that it is reasonable. In odt,
"file-b.org" implies a resource inside the odt archive. "../file-b.org"
will highlight that it is an external file.

I'd prefer to leave the "../file" description for now and only do
something when/if we hear from the ox-odt users.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: v3-0001-org-odt-link-Fix-relative-file-links.patch --]
[-- Type: text/x-patch, Size: 1620 bytes --]

From c72d90244eb1a0fafb42a8c7841be82ad882efc5 Mon Sep 17 00:00:00 2001
Message-Id: <c72d90244eb1a0fafb42a8c7841be82ad882efc5.1667364775.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Mon, 31 Oct 2022 14:11:19 +0800
Subject: [PATCH v3] 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 <yantar92@posteo.net>
Link: https://orgmode.org/list/87ilkc30wd.fsf@localhost
---
 lisp/ox-odt.el | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el
index 15a9cf2de..11b834d5d 100644
--- a/lisp/ox-odt.el
+++ b/lisp/ox-odt.el
@@ -2688,7 +2688,14 @@ (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))
+                 (let ((path-uri (org-export-file-uri raw-path)))
+                   (if (string-prefix-p "file://" path-uri)
+                       path
+                     ;; Otherwise, it is a relative 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


[-- Attachment #3: Type: text/plain, Size: 225 bytes --]



-- 
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	other threads:[~2022-11-02  5:04 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-08 18:39 [BUG] ox-odt fails for org-id links (e.g., from org-roam v2) [9.5.2 (9.5.2-gfbff08 @ /home/moritz/.emacs.d/elpa/27.2/develop/org-9.5.2/)] Moritz Schäfer
2022-10-18  7:47 ` Ihor Radchenko
2022-10-19  8:00   ` Moritz Schäfer
2022-10-19 10:36     ` Ihor Radchenko
2022-10-20 10:09       ` Max Nikulin
2022-10-21  3:16         ` Ihor Radchenko
2022-10-21 14:46           ` Max Nikulin
2022-10-22  5:03             ` [BUG] ox-odt file: links are not pointing to the real files (was: [BUG] ox-odt fails for org-id links (e.g., from org-roam v2) [9.5.2 (9.5.2-gfbff08 @ /home/moritz/.emacs.d/elpa/27.2/develop/org-9.5.2/)]) Ihor Radchenko
2022-10-22  8:04               ` Max Nikulin
2022-10-23  4:29                 ` Ihor Radchenko
2022-10-24 11:40                   ` Max Nikulin
2022-10-25 10:20               ` Max Nikulin
2022-10-31  6:13                 ` Ihor Radchenko
2022-10-31 14:37                   ` Max Nikulin
2022-11-01  5:40                     ` Ihor Radchenko
2022-11-01 15:04                       ` Max Nikulin
2022-11-02  5:04                         ` Ihor Radchenko [this message]
2022-11-02 15:39                           ` Max Nikulin
2022-11-03  6:25                             ` [DISCUSSION] Default description for relative file links in odt export (was: [BUG] ox-odt file: links are not pointing to the real files (was: [BUG] ox-odt fails for org-id links (e.g., from org-roam v2) [9.5.2 (9.5.2-gfbff08 @ /home/moritz/.emacs.d/elpa/27.2/develop/org-9.5.2/)])) Ihor Radchenko
2022-11-01  5:47                     ` org-export: How to handle links to the exported file? " Ihor Radchenko
2022-11-01 15:18                       ` org-export: How to handle links to the exported file? Max Nikulin
2022-11-01  5:48                     ` [BUG] ox-odt file: links are not pointing to the real files (was: [BUG] ox-odt fails for org-id links (e.g., from org-roam v2) [9.5.2 (9.5.2-gfbff08 @ /home/moritz/.emacs.d/elpa/27.2/develop/org-9.5.2/)]) Ihor Radchenko
2022-11-01 15:28                       ` export and cross links between files Max Nikulin
2022-11-02  6:38                         ` [DISCUSSION] Unified handling of links between Org files on export (was: export and cross links between files) Ihor Radchenko
2022-10-21 12:02       ` [BUG] ox-odt fails for org-id links (e.g., from org-roam v2) [9.5.2 (9.5.2-gfbff08 @ /home/moritz/.emacs.d/elpa/27.2/develop/org-9.5.2/)] Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87pme6kkvw.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=manikulin@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).