Subject: bug#72945: [PATCH 2/2] ox-html: Add support for attr_html in fixed-width blocks

From: "Suhail Singh" <[email-masked]>
Date: Sun, 01 Sep 2024 21:58:02 -0400

* lisp/ox-html.el (org-html-fixed-width): Handle attr_html in a manner
similar to example blocks.

TINYCHANGE
---
 lisp/ox-html.el | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 3e83f02e2..a85b1e6ac 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2728,13 +2728,23 @@ (defun org-html-export-block
 
 ;;;; Fixed Width
 
-(defun org-html-fixed-width (fixed-width _contents _info)
+(defun org-html-fixed-width (fixed-width _contents info)
   "Transcode a FIXED-WIDTH element from Org to HTML.
 CONTENTS is nil.  INFO is a plist holding contextual information."
-  (format "<pre class=\"example\">\n%s</pre>"
-	  (org-html-do-format-code
-	   (org-remove-indentation
-	    (org-element-property :value fixed-width)))))
+  (let ((attributes (org-export-read-attribute :attr_html fixed-width)))
+    (if-let ((class-val (plist-get attributes :class)))
+        (setq attributes (plist-put attributes :class (concat "example " class-val)))
+      (setq attributes (plist-put attributes :class "example")))
+    (format "<pre%s>\n%s</pre>"
+            (let* ((reference (org-html--reference fixed-width info))
+		   (a (org-html--make-attribute-string
+		       (if (or (not reference) (plist-member attributes :id))
+			   attributes
+			 (plist-put attributes :id reference)))))
+	      (if (org-string-nw-p a) (concat " " a) ""))
+	    (org-html-do-format-code
+	     (org-remove-indentation
+	      (org-element-property :value fixed-width))))))
 
 ;;;; Footnote Reference
 
-- 
2.46.0