I seem to be forever on the quest to be able to conditionally include things in
the export based upon tags or options or something. I’m trying to stay 100%
within Org and not use external programs like cpp or m4.
Today’s issue is a conditional drawer inside a description list. At the end of
this email I will include my sample code.
If you look at the result of exporting the test case to HTML, you will notice
that the test 2 output has extra space around the "with drawer a description
list that includes a list”. This is because it is inside a paragraph that the
test 1 output does not have. But also notice that the test 2 has three
description lists instead of just one: the items before the drawer, the items
in the drawer, and the items after the drawer. If the drawer is not included
as in test 3, then there are two description lists instead of three.
I believe the paragraph is because the description list is not one list in test
2 but three lists and this probably triggers something in the output of a list
to put things into paragraphs. Thus, I believe the real issue / question is
that Test 2 puts into three separate lists.
I’m not horribly shocked by this and I can understand if the reply is that this
is working as designed but I thought I would mention it.
Macros that conditionally expand based upon settings work if the item will
format into a single line. But if the output needs multiple lines such as the
case of including another list, then that method won’t work and results in
"Inline error: multiline result cannot be used”. I’ve not be able to get Babel
to work satisfactorily in this case either.
For now, I’m just going to accept the output and move on. It doesn’t look that
bad in my case.
Test sample:
#+OPTIONS: d:("included-drawer")
* Using drawers
Test 1 blah blah blah
* with no drawer a description list that includes a list
* heading 1 before the drawer ::
description 1
* heading 2 before the drawer ::
description 2
* heading 3 inside drawer ::
description 3 has a list
* item 1
* item 2
* item 3
* heading 4 inside drawer ::
description 4
* heading 5 after drawer ::
description 5
Test 2 blah blah blah
* with included drawer a description list that includes a list
* heading 1 before the drawer ::
description 1
* heading 2 before the drawer ::
description 2
:included-drawer:
* heading 3 inside drawer ::
description 3 has a list
* item 1
* item 2
* item 3
* heading 4 inside drawer ::
description 4
:end:
* heading 5 after drawer ::
description 5
Test 3 blah blah blah
* with drawer that is not included a description list that includes a list
* heading 1 before the drawer ::
description 1
* heading 2 before the drawer ::
description 2
:excluded-drawer:
* heading 3 inside drawer ::
description 3 has a list
* item 1
* item 2
* item 3
* heading 4 inside drawer ::
description 4
:end:
* heading 5 after drawer ::
description 5
* Using macros
#+NAME: one-line
#+HEADER: :var flag=0
#+HEADER: :var string=""
#+BEGIN_SRC elisp :exports none
(if (eq flag 1)
(string-replace "\n" "" string))
#+END_SRC
In the sample below, item 2 is not included in the export while item 4 is.
* description heading 1 :: text for heading 1
call_one-line(0, "* description heading 2 ::
text for heading 2")
* description heading 3 :: text for heading 3
call_one-line(1, "* description heading 4 ::
text for heading 4")
* description heading 5 :: text for heading 5
# Local Variables:
# org-babel-inline-result-wrap: "%s"
# org-confirm-babel-evaluate: nil
# org-html-head: ""
# End: