Nathan Nichols <nathannichols...@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 via email to