Subject: bug#72945: [PATCH 1/2] ox-html: Add support for attr_html for source code blocks

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

* lisp/ox-html.el (org-html-src-block): Add org-src-container class to
any class attributes specified via the attr_html keyword.

TINYCHANGE
---
 lisp/ox-html.el | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 446698758..3e83f02e2 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -3667,14 +3667,24 @@ (defun org-html-src-block
 contextual information."
   (if (org-export-read-attribute :attr_html src-block :textarea)
       (org-html--textarea-block src-block)
-    (let* ((lang (org-element-property :language src-block))
+    (let* ((attributes (org-export-read-attribute :attr_html src-block))
+           (lang (org-element-property :language src-block))
 	   (code (org-html-format-code src-block info))
 	   (label (let ((lbl (org-html--reference src-block info t)))
 		    (if lbl (format " id=\"%s\"" lbl) "")))
 	   (klipsify  (and  (plist-get info :html-klipsify-src)
                             (member lang '("javascript" "js"
 					   "ruby" "scheme" "clojure" "php" "html")))))
-      (format "<div class=\"org-src-container\">\n%s%s\n</div>"
+      (if-let ((class-val (plist-get attributes :class)))
+          (setq attributes (plist-put attributes :class (concat "org-src-container " class-val)))
+        (setq attributes (plist-put attributes :class "org-src-container")))
+      (format "<div%s>\n%s%s\n</div>"
+              (let* ((reference (org-html--reference src-block 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) ""))
 	      ;; Build caption.
 	      (let ((caption (org-export-get-caption src-block)))
 		(if (not caption) ""

base-commit: 3428b522fb83c793d0915d63a30601eb993e2b30
-- 
2.46.0