From: Nathan Nichols <nathannichols454@gmail.com>
To: Ihor Radchenko <yantar92@posteo.net>, emacs-orgmode@gnu.org
Subject: Re: [PATCH] Ability to specify :html-head as a function
Date: Fri, 21 Jun 2024 15:21:05 -0400 [thread overview]
Message-ID: <CACJZKxi4z1x_6r2AqnxODJf9sOrCUj0+_Mj051-YdwsRVuyvLA@mail.gmail.com> (raw)
In-Reply-To: <87jziiptoh.fsf@localhost>
[-- Attachment #1.1: Type: text/plain, Size: 1763 bytes --]
> This looks like a copy-paste of `org-element-normalize-string'.
> Why not simply calling `org-element-normalize-string'?
I changed it at one point, but then changed it back and didn't realize that
it was ultimately unchanged.
Here's a patch that uses `org-element-normalize-string` instead.
> Also, may we move this discussion to Org mailing list? I prefer the
> discussions and development to be public (it helps future maintainers).
Yes, of course. I think I just forgot to hit "reply all".
On Fri, Jun 21, 2024 at 4:47 AM Ihor Radchenko <yantar92@posteo.net> wrote:
> Nathan Nichols <nathannichols454@gmail.com> writes:
>
> > Subject: [PATCH] Added ability to specify :html-head as a string or
> function
> > ...
> > +(defun org-html-normalize-str (s)
> > + "Return S, or evaluate to a string ending with a single newline
> character.
> > +If S isn't a string or a function, return it unchanged. If S is the
> empty
> > +string, return it. Otherwise, return a new string with a single
> > +newline character at its end."
> > + (cond
> > + ((not (stringp s)) s)
> > + ((string= "" s) "")
> > + (t (and (string-match "\\(\n[ \t]*\\)*\\'" s)
> > + (replace-match "\n" nil nil s)))))
>
> This looks like a copy-paste of `org-element-normalize-string'.
> Why not simply calling `org-element-normalize-string'?
>
> Also, may we move this discussion to Org mailing list? I prefer the
> discussions and development to be public (it helps future maintainers).
>
> --
> 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>
>
[-- Attachment #1.2: Type: text/html, Size: 2639 bytes --]
[-- Attachment #2: 0001-Added-ability-to-specify-html-head-as-a-string-or-fu.patch --]
[-- Type: text/x-patch, Size: 2526 bytes --]
From 4f4f5c76a490eaab86d721a1331dcee5307687d0 Mon Sep 17 00:00:00 2001
From: Nate Nichols <nathannichols454@gmail.com>
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 <head>..</head> 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
next prev parent reply other threads:[~2024-06-21 19:22 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-13 0:04 [PATCH] Ability to specify :html-head as a function Nathan Nichols
2024-05-13 15:23 ` Ihor Radchenko
[not found] ` <CACJZKxjn-z2g81zJ2N1_-GMxd2stqC-4wZPVpNSiwtMj1V+jKQ@mail.gmail.com>
[not found] ` <87zfriscml.fsf@localhost>
[not found] ` <CACJZKxgwmRd_CewmqQX8e+PEM=XX=93zasL3JsAovwgSAgRguQ@mail.gmail.com>
[not found] ` <87v824904a.fsf@localhost>
[not found] ` <CACJZKxgjLizWkJ6qpoh759mmM5XjCviJiPbCmuRHiJph2Hbddg@mail.gmail.com>
[not found] ` <87bk3v78zq.fsf@localhost>
[not found] ` <CACJZKxgSGUikb8ecGjtVXi05gYfme8-POAiEWq-6cyWDnXozRg@mail.gmail.com>
[not found] ` <87jziiptoh.fsf@localhost>
2024-06-21 19:21 ` Nathan Nichols [this message]
2024-06-22 12:35 ` Ihor Radchenko
2024-06-29 14:19 ` Nathan Nichols
2024-06-30 8:30 ` Rudolf Adamkovič
2024-06-30 20:13 ` Nathan Nichols
2024-07-02 11:59 ` Ihor Radchenko
2024-07-07 14:34 ` Nathan Nichols
2024-07-07 15:28 ` Ihor Radchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CACJZKxi4z1x_6r2AqnxODJf9sOrCUj0+_Mj051-YdwsRVuyvLA@mail.gmail.com \
--to=nathannichols454@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=yantar92@posteo.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).