emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] ox.el: Refactor variable org-html--id-attr-prefix, ox-html.el: Add support for the ID property to org-html--reference
@ 2022-10-22 11:17 Feraidoon Mehri
  2022-10-25  7:18 ` Ihor Radchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Feraidoon Mehri @ 2022-10-22 11:17 UTC (permalink / raw)
  To: emacs-orgmode

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

I have already signed the copyright assignment. (Though I used my
other email rudiwillalwaysloveyou@gmail.com when signing it.)

I have manually tested the changes with a custom value for
`org-html--id-attr-prefix', and everything works.

I did not change the behavior of `org-html-prefer-user-labels'; the ID
property will not be used if `org-html-prefer-user-labels' is nil. IMO
this behavior should be changed, and it should be always used, just
like CUSTOM_ID.

Changelog:

* org/ox.el (org-html--id-attr-prefix): Refactor hardcoded "ID-" as a
new private variable.

* org/ox-html.el (org-html--reference): Add support for the ID
property (previously only supported CUSTOM_ID)

These changes make crossfile ID links work in the exported HTML when
`org-html-prefer-user-labels' is not-nil.

[-- Attachment #2: 0001-ox.el-Refactor-variable-org-html-id-attr-prefix-ox-h.patch --]
[-- Type: application/octet-stream, Size: 4115 bytes --]

From 6bc8e8395e57c2bd640edcfc603cb89ddd4b5774 Mon Sep 17 00:00:00 2001
From: Feraidoon Mehri <feraidoonmehri@gmail.com>
Date: Sat, 22 Oct 2022 14:19:24 +0330
Subject: [PATCH] ox.el: Refactor variable org-html--id-attr-prefix,
 ox-html.el: Add support for the ID property to org-html--reference

* org/ox.el (org-html--id-attr-prefix): Refactor hardcoded "ID-" as a
new private variable.

* org/ox-html.el (org-html--reference): Add support for the ID
property (previously only supported CUSTOM_ID)

These changes make crossfile ID links work in the exported HTML when
`org-html-prefer-user-labels' is not-nil.
---
 lisp/org/ox-html.el | 39 ++++++++++++++++++++++++++-------------
 lisp/org/ox-odt.el  |  2 +-
 lisp/org/ox.el      |  3 +++
 3 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/lisp/org/ox-html.el b/lisp/org/ox-html.el
index 9cf9125aeb..77fd66d711 100644
--- a/lisp/org/ox-html.el
+++ b/lisp/org/ox-html.el
@@ -1653,22 +1653,35 @@ When NAMED-ONLY is non-nil and DATUM has no NAME keyword, return
 nil.  This doesn't apply to headlines, inline tasks, radio
 targets and targets."
   (let* ((type (org-element-type datum))
-	 (user-label
-	  (org-element-property
-	   (pcase type
-	     ((or `headline `inlinetask) :CUSTOM_ID)
-	     ((or `radio-target `target) :value)
-	     (_ :name))
-	   datum)))
+         (custom-id-p nil)
+         (user-label
+          (or
+           (org-element-property
+            (pcase type
+              ((or `headline `inlinetask)
+               (progn
+                 (setq custom-id-p t)
+                 :CUSTOM_ID))
+              ((or `radio-target `target) :value)
+              (_ :name))
+            datum)
+           (if-let
+               ((id-property (org-element-property
+                              :ID
+                              datum)))
+               (progn
+                 (setq custom-id-p nil)
+                 (concat org-html--id-attr-prefix id-property))))))
+
     (cond
      ((and user-label
-	   (or (plist-get info :html-prefer-user-labels)
-	       ;; Used CUSTOM_ID property unconditionally.
-	       (memq type '(headline inlinetask))))
+           (or (plist-get info :html-prefer-user-labels)
+               ;; Used CUSTOM_ID property unconditionally.
+               custom-id-p))
       user-label)
      ((and named-only
-	   (not (memq type '(headline inlinetask radio-target target)))
-	   (not user-label))
+           (not (memq type '(headline inlinetask radio-target target)))
+           (not user-label))
       nil)
      (t
       (org-export-get-reference datum info)))))
@@ -3149,7 +3162,7 @@ INFO is a plist holding contextual information.  See
 	(pcase (org-element-type destination)
 	  ;; ID link points to an external file.
 	  (`plain-text
-	   (let ((fragment (concat "ID-" path))
+	   (let ((fragment (concat org-html--id-attr-prefix path))
 		 ;; Treat links to ".org" files as ".html", if needed.
 		 (path (funcall link-org-files-as-html-maybe
 				destination info)))
diff --git a/lisp/org/ox-odt.el b/lisp/org/ox-odt.el
index 7f2e8ba47f..d2c14237ac 100644
--- a/lisp/org/ox-odt.el
+++ b/lisp/org/ox-odt.el
@@ -1802,7 +1802,7 @@ holding contextual information."
 	   ;; Extra targets.
 	   (extra-targets
 	    (let ((id (org-element-property :ID headline)))
-	      (if id (org-odt--target "" (concat "ID-" id)) "")))
+	      (if id (org-odt--target "" (concat org-html--id-attr-prefix id)) "")))
 	   ;; Title.
 	   (anchored-title (org-odt--target full-text id)))
       (cond
diff --git a/lisp/org/ox.el b/lisp/org/ox.el
index 56bb4b74df..cc67c25e35 100644
--- a/lisp/org/ox.el
+++ b/lisp/org/ox.el
@@ -269,6 +269,9 @@ When this copy is created, all Org related local variables not in
 this list are copied to the new buffer.  Variables with an
 unreadable value are also ignored.")
 
+(defvar org-html--id-attr-prefix "ID-"
+  "Prefix to use in ID attributes of exported HTML elements when the ID is being determined from the ID property.")
+
 (defvar org-export-async-debug nil
   "Non-nil means asynchronous export process should leave data behind.
 
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] ox.el: Refactor variable org-html--id-attr-prefix, ox-html.el: Add support for the ID property to org-html--reference
  2022-10-22 11:17 [PATCH] ox.el: Refactor variable org-html--id-attr-prefix, ox-html.el: Add support for the ID property to org-html--reference Feraidoon Mehri
@ 2022-10-25  7:18 ` Ihor Radchenko
  2022-10-26 15:44   ` Bastien Guerry
  2022-12-02  6:18   ` Ihor Radchenko
  0 siblings, 2 replies; 5+ messages in thread
From: Ihor Radchenko @ 2022-10-25  7:18 UTC (permalink / raw)
  To: Feraidoon Mehri, Bastien; +Cc: emacs-orgmode

Feraidoon Mehri <feraidoonmehri@gmail.com> writes:

> I have already signed the copyright assignment. (Though I used my
> other email rudiwillalwaysloveyou@gmail.com when signing it.)

Bastien, could you kindly check the FSF records?

> I have manually tested the changes with a custom value for
> `org-html--id-attr-prefix', and everything works.
>
> I did not change the behavior of `org-html-prefer-user-labels'; the ID
> property will not be used if `org-html-prefer-user-labels' is nil. IMO
> this behavior should be changed, and it should be always used, just
> like CUSTOM_ID.

Thanks for the patch!
See my comments below.

> * org/ox.el (org-html--id-attr-prefix): Refactor hardcoded "ID-" as a
> new private variable.

org-html-* variable do not belong to the general ox.el library.  It
should only be added to ox-html.el.

> -	 (user-label
> -	  (org-element-property
> -	   (pcase type
> -	     ((or `headline `inlinetask) :CUSTOM_ID)
> -	     ((or `radio-target `target) :value)
> -	     (_ :name))
> -	   datum)))
> +         (custom-id-p nil)
> +         (user-label
> +          (or
> +           (org-element-property
> +            (pcase type
> +              ((or `headline `inlinetask)
> +               (progn
> +                 (setq custom-id-p t)
> +                 :CUSTOM_ID))
> +              ((or `radio-target `target) :value)
> +              (_ :name))
> +            datum)
> +           (if-let
> +               ((id-property (org-element-property
> +                              :ID
> +                              datum)))
> +               (progn
> +                 (setq custom-id-p nil)
> +                 (concat org-html--id-attr-prefix id-property))))))

This is a bit awkward to read.
Can you instead let-bind custom-id as a separate variable and leave :ID
to user-label? Then, you will not need to juggle setq custom-id-p and
the code will become more readable.

> diff --git a/lisp/org/ox-odt.el b/lisp/org/ox-odt.el
> index 7f2e8ba47f..d2c14237ac 100644
> --- a/lisp/org/ox-odt.el
> +++ b/lisp/org/ox-odt.el
> @@ -1802,7 +1802,7 @@ holding contextual information."
>  	   ;; Extra targets.
>  	   (extra-targets
>  	    (let ((id (org-element-property :ID headline)))
> -	      (if id (org-odt--target "" (concat "ID-" id)) "")))
> +	      (if id (org-odt--target "" (concat org-html--id-attr-prefix id)) "")))

It is surprising that org-html-* variable has anything to do with ODT
export. Please define a separate constant in ox-odt.

-- 
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>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ox.el: Refactor variable org-html--id-attr-prefix, ox-html.el: Add support for the ID property to org-html--reference
  2022-10-25  7:18 ` Ihor Radchenko
@ 2022-10-26 15:44   ` Bastien Guerry
  2022-12-02  6:18   ` Ihor Radchenko
  1 sibling, 0 replies; 5+ messages in thread
From: Bastien Guerry @ 2022-10-26 15:44 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Feraidoon Mehri, emacs-orgmode

Hi Ihor,

Ihor Radchenko <yantar92@posteo.net> writes:

>> I have already signed the copyright assignment. (Though I used my
>> other email rudiwillalwaysloveyou@gmail.com when signing it.)
>
> Bastien, could you kindly check the FSF records?

Yes, I confirm the FSF record is here.

-- 
 Bastien


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ox.el: Refactor variable org-html--id-attr-prefix, ox-html.el: Add support for the ID property to org-html--reference
  2022-10-25  7:18 ` Ihor Radchenko
  2022-10-26 15:44   ` Bastien Guerry
@ 2022-12-02  6:18   ` Ihor Radchenko
  2023-04-05  9:26     ` Ihor Radchenko
  1 sibling, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2022-12-02  6:18 UTC (permalink / raw)
  To: Feraidoon Mehri; +Cc: Bastien, emacs-orgmode

Ihor Radchenko <yantar92@posteo.net> writes:

> Thanks for the patch!
> See my comments below.

Feraidoon, have you had a chance to look into my comments?

-- 
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>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ox.el: Refactor variable org-html--id-attr-prefix, ox-html.el: Add support for the ID property to org-html--reference
  2022-12-02  6:18   ` Ihor Radchenko
@ 2023-04-05  9:26     ` Ihor Radchenko
  0 siblings, 0 replies; 5+ messages in thread
From: Ihor Radchenko @ 2023-04-05  9:26 UTC (permalink / raw)
  To: Feraidoon Mehri; +Cc: Bastien, emacs-orgmode

Ihor Radchenko <yantar92@posteo.net> writes:

> Ihor Radchenko <yantar92@posteo.net> writes:
>
>> Thanks for the patch!
>> See my comments below.
>
> Feraidoon, have you had a chance to look into my comments?

Applied, with amendments, onto main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=5e9953fa0

You are now listed as an Org contributor.
https://git.sr.ht/~bzg/worg/commit/fb807476

-- 
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>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-04-05  9:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-22 11:17 [PATCH] ox.el: Refactor variable org-html--id-attr-prefix, ox-html.el: Add support for the ID property to org-html--reference Feraidoon Mehri
2022-10-25  7:18 ` Ihor Radchenko
2022-10-26 15:44   ` Bastien Guerry
2022-12-02  6:18   ` Ihor Radchenko
2023-04-05  9:26     ` Ihor Radchenko

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).