* Conditionally formatting org-html-postamble-format
@ 2016-01-26 21:46 Kaushal Modi
2016-01-27 18:26 ` Robert H. Klein
0 siblings, 1 reply; 6+ messages in thread
From: Kaushal Modi @ 2016-01-26 21:46 UTC (permalink / raw
To: emacs-org list
[-- Attachment #1: Type: text/plain, Size: 1067 bytes --]
Hi,
I have the org-html-postamble-format set to the below:
(setq org-html-postamble-format
`(("en"
,(concat "Exported using "
;; "%c" is replaced with
`org-html-creator-string'
;; Emacs <VERSION> (Org mode <VERSION>)
"<div style=\"display: inline\"
class=\"creator\">"
"%c</div> "
"by %a. — "
"<div style=\"display: inline\"
class=\"date\">"
"%d</div>"))))
It works great except for the cases where I have set a document author to
nothing using
#+AUTHOR:
What would be the best way to set the postamble so that the "by %a" portion
does not get printed if the %a value is "".
Right now, if the author is nil, the postamble gets exported as:
Exported using
Emacs <http://www.gnu.org/software/emacs/> 25.0.50.1 (Org
<http://orgmode.org/> mode 8.3.3)
by . —
Jan 26 2016, Tue
[-- Attachment #2: Type: text/html, Size: 2188 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Conditionally formatting org-html-postamble-format
2016-01-26 21:46 Conditionally formatting org-html-postamble-format Kaushal Modi
@ 2016-01-27 18:26 ` Robert H. Klein
2016-01-27 18:35 ` Kaushal Modi
0 siblings, 1 reply; 6+ messages in thread
From: Robert H. Klein @ 2016-01-27 18:26 UTC (permalink / raw
To: Kaushal Modi; +Cc: emacs-org list
Hi,
Kaushal Modi <kaushal.modi@gmail.com> wrote:
> Hi,
>
> I have the org-html-postamble-format set to the below:
>
> (setq org-html-postamble-format
> `(("en"
> ,(concat "Exported using "
> ;; "%c" is replaced with
> `org-html-creator-string'
> ;; Emacs <VERSION> (Org mode <VERSION>)
> "<div style=\"display: inline\"
> class=\"creator\">"
> "%c</div> "
> "by %a. — "
> "<div style=\"display: inline\"
> class=\"date\">"
> "%d</div>"))))
>
>
> It works great except for the cases where I have set a document
> author to nothing using
>
> #+AUTHOR:
>
> What would be the best way to set the postamble so that the "by %a"
> portion does not get printed if the %a value is "".
>
> Right now, if the author is nil, the postamble gets exported as:
>
> Exported using
> Emacs <http://www.gnu.org/software/emacs/> 25.0.50.1 (Org
> <http://orgmode.org/> mode 8.3.3)
> by . —
> Jan 26 2016, Tue
how about using a postamble function instead of
html-postamble-format, something like
(let ((author (car (plist-get info :author))))
(when (not (equal author ""))
"by " author ". "))
" - "
instead of "by %a. - "
and similar for the rest of the %-thingies.
Note, you'll probably have to inspect the plist, the (car ...) I'm
using in some project for getting the title.
Best regards
Robert
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Conditionally formatting org-html-postamble-format
2016-01-27 18:26 ` Robert H. Klein
@ 2016-01-27 18:35 ` Kaushal Modi
2016-01-27 19:51 ` Nick Dokos
2016-01-27 19:55 ` Robert H. Klein
0 siblings, 2 replies; 6+ messages in thread
From: Kaushal Modi @ 2016-01-27 18:35 UTC (permalink / raw
To: Robert H. Klein; +Cc: emacs-org list
[-- Attachment #1: Type: text/plain, Size: 393 bytes --]
Hi Robert,
Thanks for the reply.
> how about using a postamble function instead of html-postamble-format
Does it mean that I need to look into modifying the
org-html--build-pre/postamble function?
If so, I will start looking into it but it will take a while as it full of
elisp that I have never used (until today maybe): format-spec, plist-get
and a lot of assoc's and assq's :)
Kaushal
[-- Attachment #2: Type: text/html, Size: 597 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Conditionally formatting org-html-postamble-format
2016-01-27 18:35 ` Kaushal Modi
@ 2016-01-27 19:51 ` Nick Dokos
2016-01-27 19:55 ` Robert H. Klein
1 sibling, 0 replies; 6+ messages in thread
From: Nick Dokos @ 2016-01-27 19:51 UTC (permalink / raw
To: emacs-orgmode
Kaushal Modi <kaushal.modi@gmail.com> writes:
> Hi Robert,
>
> Thanks for the reply.
>
>> how about using a postamble function instead of html-postamble-format
>
> Does it mean that I need to look into modifying the org-html--build-pre/postamble function?
>
No, Robert is talking about the variable org-html-postamble,
which you can set to a function. No need to muck around with
the internals of org.
C-h v org-html-postamble says
,----
| org-html-postamble is a variable defined in ‘ox-html.el’.
| Its value is auto
|
| Documentation:
| Non-nil means insert a postamble in HTML export.
|
| When set to ‘auto’, check against the
| ‘org-export-with-author/email/creator/date’ variables to set the
| content of the postamble. When set to a string, use this string
| as the postamble. When t, insert a string as defined by the
| formatting string in ‘org-html-postamble-format’.
|
| When set to a function, apply this function and insert the
| returned string. The function takes the property list of export
| options as its only argument.
|
| Setting :html-postamble in publishing projects will take
| precedence over this variable.
`----
Try
--8<---------------cut here---------------start------------->8---
(defun foo (info)
"This is my postamble")
(setq org-html-postamble (function foo))
--8<---------------cut here---------------end--------------->8---
and complicate the function as necessary to produce what you want.
Of course, you can use an anonymous function too:
--8<---------------cut here---------------start------------->8---
(setq org-html-postamble (function (lambda (info)
"This is my postamble")))
--8<---------------cut here---------------end--------------->8---
--
Nick
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Conditionally formatting org-html-postamble-format
2016-01-27 18:35 ` Kaushal Modi
2016-01-27 19:51 ` Nick Dokos
@ 2016-01-27 19:55 ` Robert H. Klein
2016-01-28 4:36 ` Kaushal Modi
1 sibling, 1 reply; 6+ messages in thread
From: Robert H. Klein @ 2016-01-27 19:55 UTC (permalink / raw
To: Kaushal Modi; +Cc: emacs-org list
Hi Kaushal,
> Thanks for the reply.
>
> > how about using a postamble function instead of
> > html-postamble-format
>
> Does it mean that I need to look into modifying the
> org-html--build-pre/postamble function?
>
> If so, I will start looking into it but it will take a while as it
> full of elisp that I have never used (until today maybe):
> format-spec, plist-get and a lot of assoc's and assq's :)
No, I have two functions, one for the preamble, one for the postamble,
both returning a string. In the project alist I set :html-preamble
and :html-postamble to those functions (beware of typos):
;; pre- and postamble for html export
(defun linux-e-preamble (info)
(with-temp-buffer
(insert-file-contents "~/linuxdocs/html/preamble.html")
(let ((title (car (plist-get info :title))))
(when title
(if (stringp title)
(let ((case-fold-search t)) ; case-insensitive
(goto-char (point-min))
(while (search-forward "<org-title />" nil t)
(replace-match title))))))
(buffer-string)))
(defun linux-e-postamble (info)
(with-temp-buffer
(insert-file-contents "~/linuxdocs/html/postamble.html")
(buffer-string)))
;; add linux to org-publish-poject-alist
(add-to-list 'org-publish-project-alist
'("linux-e-html"
:base-directory "~/linuxdocs"
:base-extension "org"
:publishing-directory "~/public_html/linuxdocs"
:publishing-function org-html-publish-to-html
:html-head "<link rel=\"stylesheet\" type=\"text/css\"
href=\"css/linuxdocs.css\" />" :html-head-include-default-style nil
:html-head-include-scripts nil
:html-preamble linux-e-preamble
:html-postamble linux-e-postamble
))
Best regards
Robert
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Conditionally formatting org-html-postamble-format
2016-01-27 19:55 ` Robert H. Klein
@ 2016-01-28 4:36 ` Kaushal Modi
0 siblings, 0 replies; 6+ messages in thread
From: Kaushal Modi @ 2016-01-28 4:36 UTC (permalink / raw
To: Robert H. Klein, Nick Dokos; +Cc: emacs-org list
[-- Attachment #1: Type: text/plain, Size: 958 bytes --]
Thank you guys.
With your help, I came up with this solution and it works great! I tested
it with all 4 combinations (author=nil/non-nil and date=nil/non-nil).
# #+AUTHOR:
#+AUTHOR: Kaushal Modi
# #+DATE:
#+DATE: {{{time(%b %e %Y\, %a)}}}
;; Customize the HTML postamble
(defun modi/org-html-postamble-fn (info)
"My custom postamble for org to HTML exports.
INFO is the property list of export options."
(let ((author (car (plist-get info :author)))
(creator (plist-get info :creator))
(date (car (org-export-get-date info)))
(d1 "<div style=\"display: inline\" ")
(d2 "</div>"))
(concat "Exported using "
d1 "class=\"creator\">" creator d2 ; emacs and org versions
(when author
(concat " by " author))
(when date
(concat " on " d1 "class=\"date\">" date d2))
".")))
(setq org-html-postamble #'modi/org-html-postamble-fn) ; default: 'auto
[-- Attachment #2: Type: text/html, Size: 1495 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-01-28 4:37 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-26 21:46 Conditionally formatting org-html-postamble-format Kaushal Modi
2016-01-27 18:26 ` Robert H. Klein
2016-01-27 18:35 ` Kaushal Modi
2016-01-27 19:51 ` Nick Dokos
2016-01-27 19:55 ` Robert H. Klein
2016-01-28 4:36 ` Kaushal Modi
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.