emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Nathan Nichols <nathannichols454@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] Ability to specify :html-head as a function
Date: Mon, 13 May 2024 15:23:11 +0000	[thread overview]
Message-ID: <87zfstenxc.fsf@localhost> (raw)
In-Reply-To: <CACJZKxiwiFpCSvYtovEBU=QpH0WF77k+EboemKwS2BqFWwpmyQ@mail.gmail.com>


Nathan Nichols <nathannichols454@gmail.com> writes:
> Here's a patch that adds the ability to specify :html-head as a function. I
> think this is a logical change because:
>
> 1. It provides a wider range of options for how to use :html-head (before
> :html-head could only be a string, now it can also be a function.)
> 2. It is consistent with the behavior of :html-preamble and
> :html-postamble, which can both either be a string or a function.

Thanks!
This addition makes sense.

> I probably did this wrong but anyway here's my attempt at a patch
> submission. Please let me know if you need any additional information or
> have any questions.
>
> Thanks,
>
> --- a/lisp/org-element.el
> +++ b/lisp/org-element.el
> @@ -5578,9 +5578,8 @@ If there is no affiliated keyword, return the empty string."
>  ;; global indentation from the contents of the current element.
>  
>  (defun org-element-normalize-string (s)
> -  "Ensure string S ends with a single newline character.
> -
> -If S isn't a string return it unchanged.  If S is the empty
> +  "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
> @@ -5589,6 +5588,21 @@ newline character at its end."
>     (t (and (string-match "\\(\n[ \t]*\\)*\\'" s)
>  	   (replace-match "\n" nil nil s)))))

Please, do not remove existing functions.
Also, please do not modify org-element library when it is just for the
purposes of a single exporter. org-element library is the Org mode
parser, used by all parts of Org mode.

Instead, you can simply define a helper function inside ox-html.el.
  
> +;; Test cases for `org-element-normalize-str-or-fn'
> +(cl-assert (string= (org-element-normalize-str-or-fn (lambda (_res) "abcdefg") nil) "abcdefg\n"))
> +(cl-assert (string= (org-element-normalize-str-or-fn "abcdefg") "abcdefg\n") nil)
> +(cl-assert (= (org-element-normalize-str-or-fn 123 nil) 123))

Tests should go to testing/lisp/..., which see.

>  (defun org-element-normalize-contents (element &optional ignore-first)
>    "Normalize plain text in ELEMENT's contents.
>  
> diff --git a/lisp/ox-html.el b/lisp/ox-html.el
> index ec0add65e..72a8590c4 100644
> --- a/lisp/ox-html.el
> +++ b/lisp/ox-html.el
> @@ -131,7 +131,11 @@
>      (:html-equation-reference-format "HTML_EQUATION_REFERENCE_FORMAT" nil org-html-equation-reference-format t)
>      (:html-postamble nil "html-postamble" org-html-postamble)
>      (:html-preamble nil "html-preamble" org-html-preamble)
> -    (:html-head "HTML_HEAD" nil org-html-head newline)
> +    ;; You should be able to use multiple headline properties "#+EXPORT_HTML_HEAD" in a file.
> +    ;; The results of each occurrence will be joined by a newline to form the final string
> +    ;; included in the <head> section.
> +    ;; TODO: Test/verify this works still. See: `org-export-options-alist'.
> +    (:html-head "HTML_HEAD" "html-head" org-html-head newline)

What is the purpose of "html-head" #+options keyword addition?
Also, is TODO comment for you or for others?

-- 
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>


  reply	other threads:[~2024-05-13 15: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 [this message]
     [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
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=87zfstenxc.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=nathannichols454@gmail.com \
    /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).