[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [BUG] URI handling is overly complicated and nonstandard [9.6.7 (N/A
From: |
Ihor Radchenko |
Subject: |
Re: [BUG] URI handling is overly complicated and nonstandard [9.6.7 (N/A @ /gnu/store/mg7223g8mw90lccp6mm5g6f3mpjk70si-emacs-org-9.6.7/share/emacs/site-lisp/org-9.6.7/)] |
Date: |
Mon, 05 Feb 2024 15:41:10 +0000 |
Max Nikulin <manikulin@gmail.com> writes:
> On 05/09/2023 16:42, Ihor Radchenko wrote:
>> Max Nikulin writes:
>>>
>>> From my point of view it will be more sane behavior. However it may
>>> require update of 3rd party ox backends.
>>
>> Yes. The main problem is that I fail to understand the motivation behind
>> the current behaviour. git logs reveal that the code is there from the
>> initial version of the library.
>
> Just a guess, likely unrelated to actual decision. For links like
> "lisp:" or "shell:" keeping link type does not have much sense (however
> stripping it is questionable as well).
>
> From my point of view, e.g. <elisp:(identity "a")> should be exported
> as plain text <code>(identity "a")</code> rather than an (invalid due to
> not escaped quotes inside href) link <a href="(identity "a")">(identity
> "a")</a>.
>
> I still believe that fallback export should preserve link type. Code
> links should define their export functions.
Let's get started on tackling this problem from not stripping the link
type.
I am attaching tentative patch to that effect, as a first step.
>From d0b6d3ff62749aaee40ca37964095bbaa3120128 Mon Sep 17 00:00:00 2001
Message-ID:
<d0b6d3ff62749aaee40ca37964095bbaa3120128.1707147647.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Mon, 5 Feb 2024 16:39:05 +0100
Subject: [PATCH] org-export: Do not strip link type by default during export
* lisp/ox-html.el (org-html-link):
* lisp/ox-latex.el (org-latex-link):
* lisp/ox-man.el (org-man-link):
* lisp/ox-md.el (org-md-link):
* lisp/ox-odt.el (org-odt-link--inline-image):
* lisp/ox-texinfo.el (org-texinfo-link): Preserve link type during
export for all the links, not just for a hard-coded subset.
* etc/ORG-NEWS (Built-in HTML, LaTeX, Man, Markdown, ODT, and Texinfo
exporters preserve the link protocol during export): Document the
breaking change.
Link: https://list.orgmode.org/orgmode/878r9nofpw.fsf@localhost/
---
etc/ORG-NEWS | 18 ++++++++++++++++++
lisp/ox-html.el | 4 +---
lisp/ox-latex.el | 4 +---
lisp/ox-man.el | 4 +---
lisp/ox-md.el | 4 +---
lisp/ox-odt.el | 6 ++----
lisp/ox-texinfo.el | 4 +---
7 files changed, 25 insertions(+), 19 deletions(-)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 965872d23..c5e84b7c7 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -13,6 +13,24 @@ Please send Org bug reports to mailto:emacs-orgmode@gnu.org.
* Version 9.7 (not released yet)
** Important announcements and breaking changes
+*** Built-in HTML, LaTeX, Man, Markdown, ODT, and Texinfo exporters preserve
the link protocol during export
+
+Previously, some link types where not exported as =protocol:uri= but
+as bare =uri=. This is now changed.
+
+When a link is known by Org mode and does not have a custom ~:export~
+parameter (see A.3 Adding Hyperlink Types section of the manual), the
+link protocol is now not stripped.
+
+For example, if one adds a link type =tel=, but does not define
+~:export~ parameter
+: (org-link-set-parameters "tel")
+=[[tel:12345][John Doe]]= link will be correctly exported to LaTeX as
+=\href{tel:12345}{John Doe}=, not =\href{12345}{John Doe}=.
+
+However, links like =[[elisp:(+ 1 2)]]= will be exported as
+=\url{elisp:(+ 1 2)}=, which may be somewhat unexpected.
+
*** Org mode now fontifies whole table lines (including newline) according to
~org-table~ face
Previously, leading indentation and trailing newline in table rows
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 976c24584..9812ac2b7 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -3231,8 +3231,6 @@ (defun org-html-link (link desc info)
(desc (org-string-nw-p desc))
(path
(cond
- ((member type '("http" "https" "ftp" "mailto" "news"))
- (url-encode-url (concat type ":" raw-path)))
((string= "file" type)
;; During publishing, turn absolute file names belonging
;; to base directory into relative file names. Otherwise,
@@ -3259,7 +3257,7 @@ (defun org-html-link (link desc info)
(concat raw-path
"#"
(org-publish-resolve-external-link option path t))))))
- (t raw-path)))
+ (t (url-encode-url (concat type ":" raw-path)))))
(attributes-plist
(org-combine-plists
;; Extract attributes from parent's paragraph. HACK: Only
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index e3edef3bd..060a01b0e 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2925,12 +2925,10 @@ (defun org-latex-link (link desc info)
link (plist-get info :latex-inline-image-rules)))
(path (org-latex--protect-text
(pcase type
- ((or "http" "https" "ftp" "mailto" "doi")
- (concat type ":" raw-path))
("file"
(org-export-file-uri raw-path))
(_
- raw-path)))))
+ (concat type ":" raw-path))))))
(cond
;; Link type is handled by a special function.
((org-export-custom-protocol-maybe link desc 'latex info))
diff --git a/lisp/ox-man.el b/lisp/ox-man.el
index 1f296baeb..16058fb9a 100644
--- a/lisp/ox-man.el
+++ b/lisp/ox-man.el
@@ -614,10 +614,8 @@ (defun org-man-link (link desc info)
;; Ensure DESC really exists, or set it to nil.
(desc (and (not (string= desc "")) desc))
(path (pcase type
- ((or "http" "https" "ftp" "mailto")
- (concat type ":" raw-path))
("file" (org-export-file-uri raw-path))
- (_ raw-path))))
+ (_ (concat type ":" raw-path)))))
(cond
;; Link type is handled by a special function.
((org-export-custom-protocol-maybe link desc 'man info))
diff --git a/lisp/ox-md.el b/lisp/ox-md.el
index b40d75031..5233ec3eb 100644
--- a/lisp/ox-md.el
+++ b/lisp/ox-md.el
@@ -541,11 +541,9 @@ (defun org-md-link (link desc info)
(type (org-element-property :type link))
(raw-path (org-element-property :path link))
(path (cond
- ((member type '("http" "https" "ftp" "mailto"))
- (concat type ":" raw-path))
((string-equal type "file")
(org-export-file-uri (funcall link-org-files-as-md raw-path)))
- (t raw-path))))
+ (t (concat type ":" raw-path)))))
(cond
;; Link type is handled by a special function.
((org-export-custom-protocol-maybe link desc 'md info))
diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el
index f46b25a9a..778cc62cf 100644
--- a/lisp/ox-odt.el
+++ b/lisp/ox-odt.el
@@ -2246,11 +2246,9 @@ (defun org-odt-link--inline-image (element info)
(cl-assert (org-element-type-p element 'link))
(let* ((src (let* ((type (org-element-property :type element))
(raw-path (org-element-property :path element)))
- (cond ((member type '("http" "https"))
- (concat type ":" raw-path))
- ((file-name-absolute-p raw-path)
+ (cond ((file-name-absolute-p raw-path)
(expand-file-name raw-path))
- (t raw-path))))
+ (t (concat type ":" raw-path)))))
(src-expanded (if (file-name-absolute-p src) src
(expand-file-name src (file-name-directory
(plist-get info :input-file)))))
diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el
index cfbef0c09..f9b73ac6f 100644
--- a/lisp/ox-texinfo.el
+++ b/lisp/ox-texinfo.el
@@ -1321,11 +1321,9 @@ (defun org-texinfo-link (link desc info)
(desc (and (not (string= desc "")) desc))
(path (org-texinfo--sanitize-content
(cond
- ((member type '("http" "https" "ftp"))
- (concat type ":" raw-path))
((string-equal type "file")
(org-export-file-uri raw-path))
- (t raw-path)))))
+ (t (concat type ":" raw-path))))))
(cond
((org-export-custom-protocol-maybe link desc 'texinfo info))
((org-export-inline-image-p link org-texinfo-inline-image-rules)
--
2.43.0
--
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>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [BUG] URI handling is overly complicated and nonstandard [9.6.7 (N/A @ /gnu/store/mg7223g8mw90lccp6mm5g6f3mpjk70si-emacs-org-9.6.7/share/emacs/site-lisp/org-9.6.7/)],
Ihor Radchenko <=