From 4f4f5c76a490eaab86d721a1331dcee5307687d0 Mon Sep 17 00:00:00 2001 From: Nate Nichols Date: Thu, 20 Jun 2024 14:25:35 -0400 Subject: [PATCH] Added ability to specify :html-head as a string or function --- lisp/ox-html.el | 13 ++++++++++--- testing/lisp/test-ox-html.el | 6 ++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index d1687cf5a..0139aa88c 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -2001,15 +2001,22 @@ INFO is a plist used as a communication channel." org-html-meta-tags)) "")))) +(defun org-html-normalize-str-or-fn (input &rest trailing) + "If INPUT is a string, it is passed to `org-element-normalize-string'. +If INPUT is a function, it is applied to arguments TRAILING, and the result is +passed to `org-element-normalize-string'." + (let ((s (if (functionp input) (format "%s" (apply input trailing)) input))) + (org-element-normalize-str s))) + (defun org-html--build-head (info) "Return information for the .. of the HTML output. INFO is a plist used as a communication channel." (org-element-normalize-string (concat (when (plist-get info :html-head-include-default-style) - (org-element-normalize-string org-html-style-default)) - (org-element-normalize-string (plist-get info :html-head)) - (org-element-normalize-string (plist-get info :html-head-extra)) + (org-element-normalize-str org-html-style-default)) + (org-html-normalize-str-or-fn (plist-get info :html-head) info) + (org-html-normalize-str-or-fn (plist-get info :html-head-extra) info) (when (and (plist-get info :html-htmlized-css-url) (eq org-html-htmlize-output-type 'css)) (org-html-close-tag "link" diff --git a/testing/lisp/test-ox-html.el b/testing/lisp/test-ox-html.el index 0959d1441..d079cd271 100644 --- a/testing/lisp/test-ox-html.el +++ b/testing/lisp/test-ox-html.el @@ -996,5 +996,11 @@ entirely." (should (= 0 (how-many "Created: "))) (should (= 1 (how-many "Author=Monsieur Oeuf"))))))) +(ert-deftest ox-html/test-normalize-str-or-fn () + ;; Test cases for `org-element-normalize-str-or-fn' + (should (string= (org-html-normalize-str-or-fn (lambda (_res) "abcdefg") nil) "abcdefg\n")) + (should (string= (org-html-normalize-str-or-fn "abcdefg") "abcdefg\n")) + (should (= (org-element-normalize-str-or-fn 123 nil) 123))) + (provide 'test-ox-html) ;;; test-ox-html.el ends here -- 2.34.1