all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] ox-texinfo: Support links in headings
@ 2024-08-31 20:35 Rudolf Adamkovič
  2024-09-15 12:37 ` Ihor Radchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Rudolf Adamkovič @ 2024-08-31 20:35 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Rudolf Adamkovic

From: Rudolf Adamkovic <rudolf@adamkovic.org>

* etc/ORG-NEWS (Texinfo exporter now supports links in headings):
Announce the new feature.
* lisp/ox-texinfo.el: (org-texinfo--format-entries,
org-texinfo--get-node, org-texinfo--sanitize-title-reference,
org-texinfo--sanitize-title): A 2-step change: (1) Rename
`--sanitize-title' to `--sanitize-title-reference' and (2) create a
new `--sanitize-title' sanitation function.  The new function is less
strict in that does not remove links, which should be allowed in
sectioning commands, such as `@unnumbered'.  The old function remains
more strict, which is useful for generating `@node' names, for
example.
* testing/lisp/test-ox-texinfo.el:
(test-ox-texinfo/headings-with-links): Test the new functionality to
avoid regressions in the future.
---
 etc/ORG-NEWS                    |  6 ++++++
 lisp/ox-texinfo.el              | 17 +++++++++++++++--
 testing/lisp/test-ox-texinfo.el | 28 ++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 392788055..a9357aa28 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -223,6 +223,12 @@ This way, attachments will remain accessible when opening symlinked Org file.
 When no attach dir exists, Org mode will still prefer creating it in
 the "default" directory - where the symlink is located.
 
+*** Texinfo exporter now supports links in headings
+
+The Texinfo exporter no longer removes links from headings.  This
+applies to all headings, below and above the =H= and =toc= export
+=#+OPTIONS:=.
+
 * Version 9.7
 
 ** Important announcements and breaking changes
diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el
index 6adee9fca..d710b892d 100644
--- a/lisp/ox-texinfo.el
+++ b/lisp/ox-texinfo.el
@@ -524,7 +524,7 @@ node or anchor name is unique."
 		(org-texinfo--sanitize-node
 		 (pcase (org-element-type datum)
 		   (`headline
-		    (org-texinfo--sanitize-title
+		    (org-texinfo--sanitize-title-reference
 		     (org-export-get-alt-title datum info) info))
 		   (`radio-target
 		    (org-export-data (org-element-contents datum) info))
@@ -569,6 +569,19 @@ periods, commas and colons."
 (defun org-texinfo--sanitize-title (title info)
   "Make TITLE suitable as a section name.
 TITLE is a string or a secondary string.  INFO is the current
+export state, as a plist."
+  (org-export-data-with-backend
+   title
+   (org-export-create-backend
+    :parent 'texinfo
+    :transcoders `((footnote-reference . ,#'ignore)
+                   (radio-target . ,(lambda (_r c _) c))
+                   (target . ,#'ignore)))
+   info))
+
+(defun org-texinfo--sanitize-title-reference (title info)
+  "Make TITLE suitable as a section reference.
+TITLE is a string or a secondary string.  INFO is the current
 export state, as a plist."
   (org-export-data-with-backend
    title (org-export-toc-entry-backend 'texinfo) info))
@@ -1468,7 +1481,7 @@ a plist containing contextual information."
 	      ;; name.  Remove them.
 	      (replace-regexp-in-string
 	       "[ \t]*:+" ""
-	       (org-texinfo--sanitize-title
+	       (org-texinfo--sanitize-title-reference
 		(org-export-get-alt-title h info) info)))
 	     (node (org-texinfo--get-node h info))
 	     (entry (concat "* " title ":"
diff --git a/testing/lisp/test-ox-texinfo.el b/testing/lisp/test-ox-texinfo.el
index b16a344e7..917c7f1cd 100644
--- a/testing/lisp/test-ox-texinfo.el
+++ b/testing/lisp/test-ox-texinfo.el
@@ -345,5 +345,33 @@ body
        (should-not (org-element-contents section))
        (should (eq first-heading (org-element-parent section)))))))
 
+\f
+;;; Headings with links
+
+(ert-deftest test-ox-texinfo/headings-with-links ()
+  "Test node and chapter names."
+  (should
+   (org-test-with-temp-text
+       (string-join
+        (list "* Heading 1"
+              "  ...."
+              "* Heading 2 ([[* Heading 1][Heading 1]])"
+              "  ....")
+        "\n")
+     (let ((export-buffer "*Test Texinfo Export*")
+           (org-export-show-temporary-export-buffer nil))
+       (org-export-to-buffer 'texinfo export-buffer
+         nil nil nil nil nil
+         #'texinfo-mode)
+       (with-current-buffer export-buffer
+         (goto-char (point-min))
+         (and
+          (re-search-forward "^* Heading 1::$")
+          (re-search-forward "^* Heading 2 (Heading 1)::$")
+          (re-search-forward "^@node Heading 1$")
+          (re-search-forward "^@chapter Heading 1$")
+          (re-search-forward "^@node Heading 2 (Heading 1)$")
+          (re-search-forward "^@chapter Heading 2 (@ref{Heading 1})$")))))))
+
 (provide 'test-ox-texinfo)
 ;;; test-ox-texinfo.el end here
-- 
2.46.0



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

* Re: [PATCH] ox-texinfo: Support links in headings
  2024-08-31 20:35 [PATCH] ox-texinfo: Support links in headings Rudolf Adamkovič
@ 2024-09-15 12:37 ` Ihor Radchenko
  2024-09-15 21:12   ` Rudolf Adamkovič
  0 siblings, 1 reply; 4+ messages in thread
From: Ihor Radchenko @ 2024-09-15 12:37 UTC (permalink / raw)
  To: Rudolf Adamkovič; +Cc: emacs-orgmode

Rudolf Adamkovič <rudolf@adamkovic.org> writes:

> From: Rudolf Adamkovic <rudolf@adamkovic.org>
>
> * etc/ORG-NEWS (Texinfo exporter now supports links in headings):
> Announce the new feature.
> * lisp/ox-texinfo.el: (org-texinfo--format-entries,
> org-texinfo--get-node, org-texinfo--sanitize-title-reference,
> org-texinfo--sanitize-title): A 2-step change: (1) Rename
> `--sanitize-title' to `--sanitize-title-reference' and (2) create a
> new `--sanitize-title' sanitation function.  The new function is less
> strict in that does not remove links, which should be allowed in
> sectioning commands, such as `@unnumbered'.  The old function remains
> more strict, which is useful for generating `@node' names, for
> example.
> * testing/lisp/test-ox-texinfo.el:
> (test-ox-texinfo/headings-with-links): Test the new functionality to
> avoid regressions in the future.

Thanks!

I tried to run make test and your new test fails:

Test test-ox-texinfo/headings-with-links condition:
    (search-failed "^@chapter Heading 2 (@ref{Heading 1})$")

May you please fix this and also rebase the patch onto the latest main?

-- 
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] 4+ messages in thread

* Re: [PATCH] ox-texinfo: Support links in headings
  2024-09-15 12:37 ` Ihor Radchenko
@ 2024-09-15 21:12   ` Rudolf Adamkovič
  2024-09-16 19:00     ` Ihor Radchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Rudolf Adamkovič @ 2024-09-15 21:12 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

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

Ihor Radchenko <yantar92@posteo.net> writes:

> I tried to run make test and your new test fails: [...]

Yup, `4829bacff', which you merged in the meantime, broke the test, as
it changed how `@ref's are generated.

> May you please fix this and also rebase the patch onto the latest main?

Rebased.

Rudy


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-texinfo-Support-links-in-headings.patch --]
[-- Type: text/x-patch, Size: 4863 bytes --]

From 56ff9d12d9644b076bb59e36715b3f82ed76b6a2 Mon Sep 17 00:00:00 2001
From: Rudolf Adamkovic <rudolf@adamkovic.org>
Date: Sat, 24 Aug 2024 21:37:29 +0200
Subject: [PATCH] ox-texinfo: Support links in headings

* etc/ORG-NEWS (Texinfo exporter now supports links in headings):
Announce the new feature.
* lisp/ox-texinfo.el: (org-texinfo--format-entries,
org-texinfo--get-node, org-texinfo--sanitize-title-reference,
org-texinfo--sanitize-title): A 2-step change: (1) Rename
`--sanitize-title' to `--sanitize-title-reference' and (2) create a
new `--sanitize-title' sanitation function.  The new function is less
strict in that does not remove links, which should be allowed in
sectioning commands, such as `@unnumbered'.  The old function remains
more strict, which is useful for generating `@node' names, for
example.
* testing/lisp/test-ox-texinfo.el:
(test-ox-texinfo/headings-with-links): Test the new functionality to
avoid regressions in the future.
---
 etc/ORG-NEWS                    |  6 ++++++
 lisp/ox-texinfo.el              | 17 +++++++++++++++--
 testing/lisp/test-ox-texinfo.el | 29 +++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 392788055..a9357aa28 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -223,6 +223,12 @@ This way, attachments will remain accessible when opening symlinked Org file.
 When no attach dir exists, Org mode will still prefer creating it in
 the "default" directory - where the symlink is located.
 
+*** Texinfo exporter now supports links in headings
+
+The Texinfo exporter no longer removes links from headings.  This
+applies to all headings, below and above the =H= and =toc= export
+=#+OPTIONS:=.
+
 * Version 9.7
 
 ** Important announcements and breaking changes
diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el
index 2da90ca0f..d3cd5cde1 100644
--- a/lisp/ox-texinfo.el
+++ b/lisp/ox-texinfo.el
@@ -524,7 +524,7 @@ node or anchor name is unique."
 		(org-texinfo--sanitize-node
 		 (pcase (org-element-type datum)
 		   (`headline
-		    (org-texinfo--sanitize-title
+		    (org-texinfo--sanitize-title-reference
 		     (org-export-get-alt-title datum info) info))
 		   (`radio-target
 		    (org-export-data (org-element-contents datum) info))
@@ -569,6 +569,19 @@ periods, commas and colons."
 (defun org-texinfo--sanitize-title (title info)
   "Make TITLE suitable as a section name.
 TITLE is a string or a secondary string.  INFO is the current
+export state, as a plist."
+  (org-export-data-with-backend
+   title
+   (org-export-create-backend
+    :parent 'texinfo
+    :transcoders `((footnote-reference . ,#'ignore)
+                   (radio-target . ,(lambda (_r c _) c))
+                   (target . ,#'ignore)))
+   info))
+
+(defun org-texinfo--sanitize-title-reference (title info)
+  "Make TITLE suitable as a section reference.
+TITLE is a string or a secondary string.  INFO is the current
 export state, as a plist."
   (org-export-data-with-backend
    title (org-export-toc-entry-backend 'texinfo) info))
@@ -1468,7 +1481,7 @@ a plist containing contextual information."
 	      ;; name.  Remove them.
 	      (replace-regexp-in-string
 	       "[ \t]*:+" ""
-	       (org-texinfo--sanitize-title
+	       (org-texinfo--sanitize-title-reference
 		(org-export-get-alt-title h info) info)))
 	     (node (org-texinfo--get-node h info))
 	     (entry (concat "* " title ":"
diff --git a/testing/lisp/test-ox-texinfo.el b/testing/lisp/test-ox-texinfo.el
index d4552459d..d74760024 100644
--- a/testing/lisp/test-ox-texinfo.el
+++ b/testing/lisp/test-ox-texinfo.el
@@ -374,5 +374,34 @@ body
           (re-search-forward "@ref{B, , B}")
           (re-search-forward "@ref{B, , C}")))))))
 
+\f
+;;; Headings with links
+
+(ert-deftest test-ox-texinfo/headings-with-links ()
+  "Test node and chapter names."
+  (should
+   (org-test-with-temp-text
+       (string-join
+        (list "* Heading 1"
+              "  ...."
+              "* Heading 2 ([[* Heading 1][Heading 1]])"
+              "  ....")
+        "\n")
+     (let ((export-buffer "*Test Texinfo Export*")
+           (org-export-show-temporary-export-buffer nil))
+       (org-export-to-buffer 'texinfo export-buffer
+         nil nil nil nil nil
+         #'texinfo-mode)
+       (with-current-buffer export-buffer
+         (goto-char (point-min))
+         (and
+          (re-search-forward "^* Heading 1::$")
+          (re-search-forward "^* Heading 2 (Heading 1)::$")
+          (re-search-forward "^@node Heading 1$")
+          (re-search-forward "^@chapter Heading 1$")
+          (re-search-forward "^@node Heading 2 (Heading 1)$")
+          (re-search-forward
+           "^@chapter Heading 2 (@ref{Heading 1, , Heading 1})$")))))))
+
 (provide 'test-ox-texinfo)
 ;;; test-ox-texinfo.el end here
-- 
2.39.3 (Apple Git-146)


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

-- 
"I love deadlines.  I love the whooshing noise they make as they go by."
--- Douglas Adams, The Salmon of Doubt, 2002

Rudolf Adamkovič <rudolf@adamkovic.org> [he/him]
http://adamkovic.org

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

* Re: [PATCH] ox-texinfo: Support links in headings
  2024-09-15 21:12   ` Rudolf Adamkovič
@ 2024-09-16 19:00     ` Ihor Radchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Ihor Radchenko @ 2024-09-16 19:00 UTC (permalink / raw)
  To: Rudolf Adamkovič; +Cc: emacs-orgmode

Rudolf Adamkovič <rudolf@adamkovic.org> writes:

> Ihor Radchenko <yantar92@posteo.net> writes:
>
>> I tried to run make test and your new test fails: [...]
>
> Yup, `4829bacff', which you merged in the meantime, broke the test, as
> it changed how `@ref's are generated.
>
>> May you please fix this and also rebase the patch onto the latest main?
>
> Rebased.

Thanks!
Applied, onto main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=6443c83bd1

-- 
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] 4+ messages in thread

end of thread, other threads:[~2024-09-16 19:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-31 20:35 [PATCH] ox-texinfo: Support links in headings Rudolf Adamkovič
2024-09-15 12:37 ` Ihor Radchenko
2024-09-15 21:12   ` Rudolf Adamkovič
2024-09-16 19:00     ` Ihor Radchenko

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.