* lisp/ox-texinfo.el (org-texinfo-src-block): Preserve the language
field during export.
* etc/ORG-NEWS (Version 9.8): Add news entry.
---
Hello all,

When exporting source blocks to Texinfo, the language is removed
(unless it is lisp). This hurts the ability to use the Texinfo files
to generate additional documentation, such as (info "(texinfo) Syntax
Highlighting").

 etc/ORG-NEWS       | 20 ++++++++++++++++++++
 lisp/ox-texinfo.el | 11 +++++++----
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 05280f3de..fbbc75724 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -572,6 +572,26 @@ will be defined as empty and not produce any metadata if 
their
 corresponding ~org-latex-with-author~, ~org-latex-with-title~, or
 ~org-latex-with-creator~ option is set to ~nil~.
 
+*** Texinfo exporter now preserves source block language during export
+
+The Texinfo exporter no longer removes the language from source blocks
+during export.
+
+For example, exporting the following to Texinfo
+
+#+begin_src org
+,#+begin_src emacs-lisp
+(message "Hello World!")
+,#+end_src
+#+end_src
+
+will result in
+
+#+begin_src texinfo
+@example emacs-lisp
+(message "Hello World!")
+@end example
+#+end_src
 * Version 9.7
 
 ** Important announcements and breaking changes
diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el
index a99656c3c..e88333595 100644
--- a/lisp/ox-texinfo.el
+++ b/lisp/ox-texinfo.el
@@ -1745,13 +1745,16 @@ as a communication channel."
   "Transcode a SRC-BLOCK element from Org to Texinfo.
 CONTENTS holds the contents of the item.  INFO is a plist holding
 contextual information."
-  (let* ((lisp (string-match-p
-                "lisp"
-               (or (org-element-property :language src-block) "")))
+  (let* ((language (org-element-property :language src-block))
+         (lisp (and language (string-match-p "lisp" language)))
         (code (org-texinfo--sanitize-content
                (org-export-format-code-default src-block info)))
         (value (format
-                (if lisp "@lisp\n%s@end lisp" "@example\n%s@end example")
+                 (cond
+                  (lisp "@lisp\n%s@end lisp")
+                  (language (format "@example %s\n%%s@end example" language))
+                  ;; Language is mandatory but allow nil for compatibility.
+                  (t "@example\n%s@end example"))
                 code))
         (caption (org-export-get-caption src-block))
         (shortcaption (org-export-get-caption src-block t)))
-- 
2.48.1


Reply via email to