emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Feraidoon Mehri <feraidoonmehri@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH] ox.el: Refactor variable org-html--id-attr-prefix, ox-html.el: Add support for the ID property to org-html--reference
Date: Sat, 22 Oct 2022 14:47:10 +0330	[thread overview]
Message-ID: <CABKKTciL=YDdyxvND6S2Vxp4_4=uayKEN793VcfhR1P2njzS-Q@mail.gmail.com> (raw)

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


             reply	other threads:[~2022-10-24  6:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-22 11:17 Feraidoon Mehri [this message]
2022-10-25  7:18 ` [PATCH] ox.el: Refactor variable org-html--id-attr-prefix, ox-html.el: Add support for the ID property to org-html--reference Ihor Radchenko
2022-10-26 15:44   ` Bastien Guerry
2022-12-02  6:18   ` Ihor Radchenko
2023-04-05  9:26     ` 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='CABKKTciL=YDdyxvND6S2Vxp4_4=uayKEN793VcfhR1P2njzS-Q@mail.gmail.com' \
    --to=feraidoonmehri@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /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).