public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Conditional compilation - How to?
@ 2019-04-06 16:43 pbeltran
       [not found] ` <61bdaf46-d88a-4ef1-b145-71ad5900fed8-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: pbeltran @ 2019-04-06 16:43 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 1141 bytes --]

My purpose is to generate two versions from the same markdown file. Think 
in a worksheet or a set of reveal slides with and without solutions.

If I use gpp, like suggested here,  
<https://randomdeterminism.wordpress.com/2012/06/01/how-i-stopped-worring-and-started-using-markdown-like-tex/>the 
math expressions in my .md (mathjax) get messed, since \ are escaped.

Is there a way out of the box? For instance, by using custom fenced_divs 
and them telling pandoc to remove that specific div? I've taken a look at 
custom filters but I don't know haskell...

Thanks

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/61bdaf46-d88a-4ef1-b145-71ad5900fed8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 1641 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Conditional compilation - How to?
       [not found] ` <61bdaf46-d88a-4ef1-b145-71ad5900fed8-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-04-06 18:16   ` BPJ
       [not found]     ` <CADAJKhBNWpmcKAAaNw_xo_EeT-JWKVPcnFo9EdDfzyA0+Fpydw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: BPJ @ 2019-04-06 18:16 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 2342 bytes --]

I use a div with a class and a filter which removes divs with that class
like this:

````markdown
:::answer
**Answer:** 42.
:::
````

````lua
function Div (elem)
  if elem.classes:includes('answer') then
    return {} -- delete it
  else
    return elem
  end
end
````

HTH,

/bpj

Den lör 6 apr. 2019 18:44pbeltran <pabelpe-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:

> My purpose is to generate two versions from the same markdown file. Think
> in a worksheet or a set of reveal slides with and without solutions.
>
> If I use gpp, like suggested here,
> <https://randomdeterminism.wordpress.com/2012/06/01/how-i-stopped-worring-and-started-using-markdown-like-tex/>the
> math expressions in my .md (mathjax) get messed, since \ are escaped.
>
> Is there a way out of the box? For instance, by using custom fenced_divs
> and them telling pandoc to remove that specific div? I've taken a look at
> custom filters but I don't know haskell...
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "pandoc-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-discuss/61bdaf46-d88a-4ef1-b145-71ad5900fed8%40googlegroups.com
> <https://groups.google.com/d/msgid/pandoc-discuss/61bdaf46-d88a-4ef1-b145-71ad5900fed8%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CADAJKhBNWpmcKAAaNw_xo_EeT-JWKVPcnFo9EdDfzyA0%2BFpydw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #2: Type: text/html, Size: 3905 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Conditional compilation - How to?
       [not found]     ` <CADAJKhBNWpmcKAAaNw_xo_EeT-JWKVPcnFo9EdDfzyA0+Fpydw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2019-04-06 18:36       ` pbeltran
       [not found]         ` <44645f9a-1670-4f4e-93cc-e24394fa10f4-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: pbeltran @ 2019-04-06 18:36 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 3397 bytes --]

Thanks. Using your script, what I can't do is to include a heading inside 
the fenced div, can't I? The reason is that I need solution to be presented 
in a different slide. I had just found a kind of solution, using heading 
identifiers (although when compiling to beamer it spits a warning (as 
several sections share the same identifier):

local looking_at_section = false
local lvl = 0
local remove = {}  -- delete line if 'remove' array not needed

function Block (elem)
  if elem.t == "Header" then
    -- if elem.classes:includes('remove',1) then

    if elem.identifier == 'answer' then
      looking_at_section = true
      lvl = elem.
level
    else

      looking_at_section = looking_at_section and elem.level >
lvl
    end
  end
  if looking_at_section then
    remove[#remove + 1] = elem  -- delete line if 'remove' array not needed
    return {}
  end
end





El sábado, 6 de abril de 2019, 20:17:02 (UTC+2), BP escribió:
>
> I use a div with a class and a filter which removes divs with that class 
> like this:
>
> ````markdown
> :::answer
> **Answer:** 42.
> :::
> ````
>
> ````lua
> function Div (elem)
>   if elem.classes:includes('answer') then
>     return {} -- delete it
>   else
>     return elem
>   end
> end
> ````
>
> HTH,
>
> /bpj
>
> Den lör 6 apr. 2019 18:44pbeltran <pab...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <javascript:>> skrev:
>
>> My purpose is to generate two versions from the same markdown file. Think 
>> in a worksheet or a set of reveal slides with and without solutions.
>>
>> If I use gpp, like suggested here,  
>> <https://randomdeterminism.wordpress.com/2012/06/01/how-i-stopped-worring-and-started-using-markdown-like-tex/>the 
>> math expressions in my .md (mathjax) get messed, since \ are escaped.
>>
>> Is there a way out of the box? For instance, by using custom fenced_divs 
>> and them telling pandoc to remove that specific div? I've taken a look at 
>> custom filters but I don't know haskell...
>>
>> Thanks
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "pandoc-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>.
>> To post to this group, send email to pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 
>> <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/pandoc-discuss/61bdaf46-d88a-4ef1-b145-71ad5900fed8%40googlegroups.com 
>> <https://groups.google.com/d/msgid/pandoc-discuss/61bdaf46-d88a-4ef1-b145-71ad5900fed8%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/44645f9a-1670-4f4e-93cc-e24394fa10f4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 7565 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Conditional compilation - How to?
       [not found]         ` <44645f9a-1670-4f4e-93cc-e24394fa10f4-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-04-07  5:49           ` BPJ
       [not found]             ` <CADAJKhAL7JGQyMS7A8eYhN7vQLdk7ccVm8=VEwz1keeuY_LVBA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: BPJ @ 2019-04-07  5:49 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 4668 bytes --]

You can use any attributes on headings, including classes:

````markdown
## The heading  {.class}
````

The problem with headings inside divs is that pandoc sometimes ignores
them, i.e. in the auto-generated table of contents and apparently also when
identifying slides, probably because slides themselves need to be top level
divs.


Den lör 6 apr. 2019 20:36pbeltran <pabelpe-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:

> Thanks. Using your script, what I can't do is to include a heading inside
> the fenced div, can't I? The reason is that I need solution to be presented
> in a different slide. I had just found a kind of solution, using heading
> identifiers (although when compiling to beamer it spits a warning (as
> several sections share the same identifier):
>
> local looking_at_section = false
> local lvl = 0
> local remove = {}  -- delete line if 'remove' array not needed
>
> function Block (elem)
>   if elem.t == "Header" then
>     -- if elem.classes:includes('remove',1) then
>
>     if elem.identifier == 'answer' then
>       looking_at_section = true
>       lvl = elem.
> level
>     else
>
>       looking_at_section = looking_at_section and elem.level >
> lvl
>     end
>   end
>   if looking_at_section then
>     remove[#remove + 1] = elem  -- delete line if 'remove' array not needed
>     return {}
>   end
> end
>
>
>
>
>
> El sábado, 6 de abril de 2019, 20:17:02 (UTC+2), BP escribió:
>>
>> I use a div with a class and a filter which removes divs with that class
>> like this:
>>
>> ````markdown
>> :::answer
>> **Answer:** 42.
>> :::
>> ````
>>
>> ````lua
>> function Div (elem)
>>   if elem.classes:includes('answer') then
>>     return {} -- delete it
>>   else
>>     return elem
>>   end
>> end
>> ````
>>
>> HTH,
>>
>> /bpj
>>
>> Den lör 6 apr. 2019 18:44pbeltran <pab...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:
>>
>>> My purpose is to generate two versions from the same markdown file.
>>> Think in a worksheet or a set of reveal slides with and without solutions.
>>>
>>> If I use gpp, like suggested here,
>>> <https://randomdeterminism.wordpress.com/2012/06/01/how-i-stopped-worring-and-started-using-markdown-like-tex/>the
>>> math expressions in my .md (mathjax) get messed, since \ are escaped.
>>>
>>> Is there a way out of the box? For instance, by using custom fenced_divs
>>> and them telling pandoc to remove that specific div? I've taken a look at
>>> custom filters but I don't know haskell...
>>>
>>> Thanks
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "pandoc-discuss" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to pandoc-...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>>> To post to this group, send email to pandoc-...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/pandoc-discuss/61bdaf46-d88a-4ef1-b145-71ad5900fed8%40googlegroups.com
>>> <https://groups.google.com/d/msgid/pandoc-discuss/61bdaf46-d88a-4ef1-b145-71ad5900fed8%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "pandoc-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-discuss/44645f9a-1670-4f4e-93cc-e24394fa10f4%40googlegroups.com
> <https://groups.google.com/d/msgid/pandoc-discuss/44645f9a-1670-4f4e-93cc-e24394fa10f4%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CADAJKhAL7JGQyMS7A8eYhN7vQLdk7ccVm8%3DVEwz1keeuY_LVBA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #2: Type: text/html, Size: 8412 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Conditional compilation - How to?
       [not found]             ` <CADAJKhAL7JGQyMS7A8eYhN7vQLdk7ccVm8=VEwz1keeuY_LVBA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2019-04-07  6:46               ` pbeltran
       [not found]                 ` <5fc2de0f-82db-4d02-9dc9-ff5db8a8b9b4-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: pbeltran @ 2019-04-07  6:46 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 4896 bytes --]

Ok, thanks.

El domingo, 7 de abril de 2019, 7:49:36 (UTC+2), BP escribió:
>
> You can use any attributes on headings, including classes:
>
> ````markdown
> ## The heading  {.class}
> ````
>
> The problem with headings inside divs is that pandoc sometimes ignores 
> them, i.e. in the auto-generated table of contents and apparently also when 
> identifying slides, probably because slides themselves need to be top level 
> divs.
>
>
> Den lör 6 apr. 2019 20:36pbeltran <pab...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <javascript:>> skrev:
>
>> Thanks. Using your script, what I can't do is to include a heading inside 
>> the fenced div, can't I? The reason is that I need solution to be presented 
>> in a different slide. I had just found a kind of solution, using heading 
>> identifiers (although when compiling to beamer it spits a warning (as 
>> several sections share the same identifier):
>>
>> local looking_at_section = false
>> local lvl = 0
>> local remove = {}  -- delete line if 'remove' array not needed
>>
>> function Block (elem)
>>   if elem.t == "Header" then
>>     -- if elem.classes:includes('remove',1) then
>>
>>     if elem.identifier == 'answer' then
>>       looking_at_section = true
>>       lvl = elem.
>> level
>>     else
>>
>>       looking_at_section = looking_at_section and elem.level >
>> lvl
>>     end
>>   end
>>   if looking_at_section then
>>     remove[#remove + 1] = elem  -- delete line if 'remove' array not 
>> needed
>>     return {}
>>   end
>> end
>>
>>
>>
>>
>>
>> El sábado, 6 de abril de 2019, 20:17:02 (UTC+2), BP escribió:
>>>
>>> I use a div with a class and a filter which removes divs with that class 
>>> like this:
>>>
>>> ````markdown
>>> :::answer
>>> **Answer:** 42.
>>> :::
>>> ````
>>>
>>> ````lua
>>> function Div (elem)
>>>   if elem.classes:includes('answer') then
>>>     return {} -- delete it
>>>   else
>>>     return elem
>>>   end
>>> end
>>> ````
>>>
>>> HTH,
>>>
>>> /bpj
>>>
>>> Den lör 6 apr. 2019 18:44pbeltran <pab...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:
>>>
>>>> My purpose is to generate two versions from the same markdown file. 
>>>> Think in a worksheet or a set of reveal slides with and without solutions.
>>>>
>>>> If I use gpp, like suggested here,  
>>>> <https://randomdeterminism.wordpress.com/2012/06/01/how-i-stopped-worring-and-started-using-markdown-like-tex/>the 
>>>> math expressions in my .md (mathjax) get messed, since \ are escaped.
>>>>
>>>> Is there a way out of the box? For instance, by using custom 
>>>> fenced_divs and them telling pandoc to remove that specific div? I've taken 
>>>> a look at custom filters but I don't know haskell...
>>>>
>>>> Thanks
>>>>
>>>> -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "pandoc-discuss" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to pandoc-...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>>>> To post to this group, send email to pandoc-...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/pandoc-discuss/61bdaf46-d88a-4ef1-b145-71ad5900fed8%40googlegroups.com 
>>>> <https://groups.google.com/d/msgid/pandoc-discuss/61bdaf46-d88a-4ef1-b145-71ad5900fed8%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "pandoc-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>.
>> To post to this group, send email to pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 
>> <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/pandoc-discuss/44645f9a-1670-4f4e-93cc-e24394fa10f4%40googlegroups.com 
>> <https://groups.google.com/d/msgid/pandoc-discuss/44645f9a-1670-4f4e-93cc-e24394fa10f4%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/5fc2de0f-82db-4d02-9dc9-ff5db8a8b9b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 9425 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Conditional compilation - How to?
       [not found]                 ` <5fc2de0f-82db-4d02-9dc9-ff5db8a8b9b4-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-04-07 12:03                   ` BPJ
       [not found]                     ` <5a4d26a3-b9b7-dda1-d437-6e7cdd519dba-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: BPJ @ 2019-04-07 12:03 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw, pbeltran


The filter will probably be more effective (faster) if you just 
visit Header and Div elements.  You can do that by returning a 
table of tables from the filter script like this:

````lua
local function remove_cond (elem)
   if elem.classes:includes('conditional') then
     return {} -- delete it
   else
     return elem
   end
end

return {
   { Header = remove_cond, Div = remove_cond },
}
````

although on second thought I would probably prefer to have the 
(unmarked) heading inside the div in the source, and use a filter 
to replace the div with its content instead of removing it when I 
want to include the conditional content.
This does make the filter a bit more complicated, but makes the 
Markdown source cleaner.

````lua
-- include.lua - include conditional content
function Div (elem)
   if elem.classes:includes('conditional') then
     return elem.content -- replace div with its content
   else
     return elem
   end
end
````

In fact my preference would probably be to use the same filter for 
both actions and set a metadata flag value to true when I want to 
keep rather than remove conditional content.
This makes usage somewhat more complicated, but maintenance 
easier, since if you need to change the filter, you can do all the 
changes in one place, rather than having to keep two scripts in 
synch.  This is IMHO always preferable.

````````lua
--[========================================[

# conditional.lua - conditional content in Pandoc

## Usage

### In your Markdown source

Put content which should be conditionally included inside
a div with a class `conditional`:

````markdown
:::conditional
## Answer to question 1

42
:::
````

### To remove conditional content

Run the filter with `-M keep_cond=false` (the default):

````sh
pandoc --lua-filter=conditional.lua -M keep_cond=false input.md
````

### To keep conditional content

Run the filter with `-M keep_cond=true`, to have the filter remove
the wrapping divs around conditional content. This is important to 
get the
table of contents and/or slides in a presentation right!

````sh
pandoc --lua-filter=conditional.lua -M keep_cond=false input.md
````

## Copyright and license

| This software is Copyright (c) 2019 by Benct Philip Jonsson.
|
| This is free software, licensed under:
|
|   The MIT (X11) License
| See <http://www.opensource.org/licenses/mit-license.php>.

--]========================================]

local keep_cond = false

local function get_meta (meta)
   local flag_value = meta.keep_cond
   if nil ~= flag_value then -- if not nil i.e. if explicitly set
     assert(
       'boolean' == type(flag_value),
       'expected value of metadata field keep_cond to be boolean 
(true or false)'
     )
     keep_cond = flag_value
   end
   return meta
end

local function do_cond (elem)
   if elem.classes:includes('conditional') then
     if keep_cond then
       return elem.content -- replace with its content
     else -- if we're discarding conditional
       return {} -- remove from AST
     end
   else -- if not conditional
     return elem
   end
end

return {
   -- run first as separate filter to get metadata value
   { Meta = get_meta },
   -- run as a second filter after metadata value has been checked
   { Div  = do_cond },
}
````````

Den 2019-04-07 kl. 08:46, skrev pbeltran:
> Ok, thanks.
> 
> El domingo, 7 de abril de 2019, 7:49:36 (UTC+2), BP escribió:
>>
>> You can use any attributes on headings, including classes:
>>
>> ````markdown
>> ## The heading  {.class}
>> ````
>>
>> The problem with headings inside divs is that pandoc sometimes ignores
>> them, i.e. in the auto-generated table of contents and apparently also when
>> identifying slides, probably because slides themselves need to be top level
>> divs.
>>
>>
>> Den lör 6 apr. 2019 20:36pbeltran <pab...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <javascript:>> skrev:
>>
>>> Thanks. Using your script, what I can't do is to include a heading inside
>>> the fenced div, can't I? The reason is that I need solution to be presented
>>> in a different slide. I had just found a kind of solution, using heading
>>> identifiers (although when compiling to beamer it spits a warning (as
>>> several sections share the same identifier):
>>>
>>> local looking_at_section = false
>>> local lvl = 0
>>> local remove = {}  -- delete line if 'remove' array not needed
>>>
>>> function Block (elem)
>>>    if elem.t == "Header" then
>>>      -- if elem.classes:includes('remove',1) then
>>>
>>>      if elem.identifier == 'answer' then
>>>        looking_at_section = true
>>>        lvl = elem.
>>> level
>>>      else
>>>
>>>        looking_at_section = looking_at_section and elem.level >
>>> lvl
>>>      end
>>>    end
>>>    if looking_at_section then
>>>      remove[#remove + 1] = elem  -- delete line if 'remove' array not
>>> needed
>>>      return {}
>>>    end
>>> end
>>>
>>>
>>>
>>>
>>>
>>> El sábado, 6 de abril de 2019, 20:17:02 (UTC+2), BP escribió:
>>>>
>>>> I use a div with a class and a filter which removes divs with that class
>>>> like this:
>>>>
>>>> ````markdown
>>>> :::answer
>>>> **Answer:** 42.
>>>> :::
>>>> ````
>>>>
>>>> ````lua
>>>> function Div (elem)
>>>>    if elem.classes:includes('answer') then
>>>>      return {} -- delete it
>>>>    else
>>>>      return elem
>>>>    end
>>>> end
>>>> ````
>>>>
>>>> HTH,
>>>>
>>>> /bpj
>>>>
>>>> Den lör 6 apr. 2019 18:44pbeltran <pab...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:
>>>>
>>>>> My purpose is to generate two versions from the same markdown file.
>>>>> Think in a worksheet or a set of reveal slides with and without solutions.
>>>>>
>>>>> If I use gpp, like suggested here,
>>>>> <https://randomdeterminism.wordpress.com/2012/06/01/how-i-stopped-worring-and-started-using-markdown-like-tex/>the
>>>>> math expressions in my .md (mathjax) get messed, since \ are escaped.
>>>>>
>>>>> Is there a way out of the box? For instance, by using custom
>>>>> fenced_divs and them telling pandoc to remove that specific div? I've taken
>>>>> a look at custom filters but I don't know haskell...
>>>>>
>>>>> Thanks
>>>>>
>>>>> -- 
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "pandoc-discuss" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to pandoc-...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>>>>> To post to this group, send email to pandoc-...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/pandoc-discuss/61bdaf46-d88a-4ef1-b145-71ad5900fed8%40googlegroups.com
>>>>> <https://groups.google.com/d/msgid/pandoc-discuss/61bdaf46-d88a-4ef1-b145-71ad5900fed8%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>> -- 
>>> You received this message because you are subscribed to the Google Groups
>>> "pandoc-discuss" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>.
>>> To post to this group, send email to pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
>>> <javascript:>.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/pandoc-discuss/44645f9a-1670-4f4e-93cc-e24394fa10f4%40googlegroups.com
>>> <https://groups.google.com/d/msgid/pandoc-discuss/44645f9a-1670-4f4e-93cc-e24394fa10f4%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
> 

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/5a4d26a3-b9b7-dda1-d437-6e7cdd519dba%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Conditional compilation - How to?
       [not found]                     ` <5a4d26a3-b9b7-dda1-d437-6e7cdd519dba-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2019-06-26  0:56                       ` Hans Kunkell
       [not found]                         ` <1375b479-60d6-4514-8c72-db60f3355ab8-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: Hans Kunkell @ 2019-06-26  0:56 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 1333 bytes --]

Hi!

Perhaps you are satisfied with the way discussed earlier. I have an 
alternative solution for those who are interested.

I also had the need to make two versions of a document where most of the 
contents are the same. My solution was to have single file and where needed 
write like this:
<<< internal
Contents here will be in *internal* version. You may include any valid 
markdown here.
<<< external
... For external version ...
>>>

The attached bash script will parse the file and depending on targeting 
internal or external version (or whatever identifiers you prefer) two 
different intermediate files will be created and then processed by pandoc.

This is the way I solved it and if you find it useful for your needs, 
please use it!

Regards
Hans

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/1375b479-60d6-4514-8c72-db60f3355ab8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 2243 bytes --]

[-- Attachment #2: multi.sh.txt --]
[-- Type: text/plain, Size: 1145 bytes --]

#!/bin/bash

SOURCESCRIPT="$0"
SAVEINTERMEDIATE=true

function prep() {
	OUTPUTFILE="$1"
	shift
	TARGET="$1"
	shift
	
	$SAVEINTERMEDIATE && INTERMEDIATEFILE="$OUTPUTFILE-intermediate.md" || INTERMEDIATEFILE="/dev/null"

	awk -f <(sed -e '/[B]EGIN_AWK1/,/[E]ND_AWK1/!d' "$SOURCESCRIPT") \
		-v target="$TARGET" \
		$@ | tee "$INTERMEDIATEFILE" | \
		pandoc -f markdown \
			--standalone \
			--reference-doc=reference.odt \
			-o "$OUTPUTFILE"

	return $?

}

prep "output-internal.odt" internal $@
prep "output-external.odt" external $@

exit

#BEGIN_AWK1

/^<<</ {
	nextconditional = trim(substr($0, 4))
	if (nextconditional == conditional)
		print "Already inside conditional. Please check source." > "/dev/stderr"
	conditional = nextconditional
	next
}

/^>>>/ {
	conditional = ""
	next
}


// {
	if (conditional) {
		if (conditional != target)
			next
	}

	print
}


# From: https://stackoverflow.com/questions/9985528/how-can-i-trim-white-space-from-a-variable-in-awk
function ltrim(s) { sub(/^[ \t\r\n]+/, "", s); return s }
function rtrim(s) { sub(/[ \t\r\n]+$/, "", s); return s }
function trim(s) { return rtrim(ltrim(s)); }

#END_AWK1

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Conditional compilation - How to?
       [not found]                         ` <1375b479-60d6-4514-8c72-db60f3355ab8-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-06-26  8:25                           ` pbeltran
       [not found]                             ` <9ab5d37d-74c0-4793-81fe-c6cdab9e253d-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: pbeltran @ 2019-06-26  8:25 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 1595 bytes --]

Thanks, I'm working with the solution via lua filters, as I need not two, 
but several versions.

El miércoles, 26 de junio de 2019, 2:56:59 (UTC+2), Hans Kunkell escribió:
>
> Hi!
>
> Perhaps you are satisfied with the way discussed earlier. I have an 
> alternative solution for those who are interested.
>
> I also had the need to make two versions of a document where most of the 
> contents are the same. My solution was to have single file and where needed 
> write like this:
> <<< internal
> Contents here will be in *internal* version. You may include any valid 
> markdown here.
> <<< external
> ... For external version ...
> >>>
>
> The attached bash script will parse the file and depending on targeting 
> internal or external version (or whatever identifiers you prefer) two 
> different intermediate files will be created and then processed by pandoc.
>
> This is the way I solved it and if you find it useful for your needs, 
> please use it!
>
> Regards
> Hans
>
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/9ab5d37d-74c0-4793-81fe-c6cdab9e253d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 2446 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Conditional compilation - How to?
       [not found]                             ` <9ab5d37d-74c0-4793-81fe-c6cdab9e253d-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-06-26  8:31                               ` Hans Kunkell
       [not found]                                 ` <4f0d389c-c21c-4069-a344-ef6ce1efb113-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: Hans Kunkell @ 2019-06-26  8:31 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 1990 bytes --]

Hi pbeltran,

ok, I understand. My script is not limited to 2 versions but any number. 
internal and external was just the choice I use.

I guess a lua filter is better for your workflow, I just wanted to share 
another possible method, it may help some other.

Have a nice day!

Hans

Den onsdag 26 juni 2019 kl. 17:25:02 UTC+9 skrev pbeltran:
>
> Thanks, I'm working with the solution via lua filters, as I need not two, 
> but several versions.
>
> El miércoles, 26 de junio de 2019, 2:56:59 (UTC+2), Hans Kunkell escribió:
>>
>> Hi!
>>
>> Perhaps you are satisfied with the way discussed earlier. I have an 
>> alternative solution for those who are interested.
>>
>> I also had the need to make two versions of a document where most of the 
>> contents are the same. My solution was to have single file and where needed 
>> write like this:
>> <<< internal
>> Contents here will be in *internal* version. You may include any valid 
>> markdown here.
>> <<< external
>> ... For external version ...
>> >>>
>>
>> The attached bash script will parse the file and depending on targeting 
>> internal or external version (or whatever identifiers you prefer) two 
>> different intermediate files will be created and then processed by pandoc.
>>
>> This is the way I solved it and if you find it useful for your needs, 
>> please use it!
>>
>> Regards
>> Hans
>>
>>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/4f0d389c-c21c-4069-a344-ef6ce1efb113%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 3046 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Conditional compilation - How to?
       [not found]                                 ` <4f0d389c-c21c-4069-a344-ef6ce1efb113-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-06-26  8:40                                   ` pbeltran
  0 siblings, 0 replies; 10+ messages in thread
From: pbeltran @ 2019-06-26  8:40 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 2163 bytes --]

Great! 
I'll take a look. Thanks!

El miércoles, 26 de junio de 2019, 10:31:16 (UTC+2), Hans Kunkell escribió:
>
> Hi pbeltran,
>
> ok, I understand. My script is not limited to 2 versions but any number. 
> internal and external was just the choice I use.
>
> I guess a lua filter is better for your workflow, I just wanted to share 
> another possible method, it may help some other.
>
> Have a nice day!
>
> Hans
>
> Den onsdag 26 juni 2019 kl. 17:25:02 UTC+9 skrev pbeltran:
>>
>> Thanks, I'm working with the solution via lua filters, as I need not two, 
>> but several versions.
>>
>> El miércoles, 26 de junio de 2019, 2:56:59 (UTC+2), Hans Kunkell escribió:
>>>
>>> Hi!
>>>
>>> Perhaps you are satisfied with the way discussed earlier. I have an 
>>> alternative solution for those who are interested.
>>>
>>> I also had the need to make two versions of a document where most of the 
>>> contents are the same. My solution was to have single file and where needed 
>>> write like this:
>>> <<< internal
>>> Contents here will be in *internal* version. You may include any valid 
>>> markdown here.
>>> <<< external
>>> ... For external version ...
>>> >>>
>>>
>>> The attached bash script will parse the file and depending on targeting 
>>> internal or external version (or whatever identifiers you prefer) two 
>>> different intermediate files will be created and then processed by pandoc.
>>>
>>> This is the way I solved it and if you find it useful for your needs, 
>>> please use it!
>>>
>>> Regards
>>> Hans
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/695a09ca-b37a-4cee-a9bc-a321c0477d95%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 3325 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-06-26  8:40 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-06 16:43 Conditional compilation - How to? pbeltran
     [not found] ` <61bdaf46-d88a-4ef1-b145-71ad5900fed8-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-04-06 18:16   ` BPJ
     [not found]     ` <CADAJKhBNWpmcKAAaNw_xo_EeT-JWKVPcnFo9EdDfzyA0+Fpydw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-04-06 18:36       ` pbeltran
     [not found]         ` <44645f9a-1670-4f4e-93cc-e24394fa10f4-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-04-07  5:49           ` BPJ
     [not found]             ` <CADAJKhAL7JGQyMS7A8eYhN7vQLdk7ccVm8=VEwz1keeuY_LVBA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-04-07  6:46               ` pbeltran
     [not found]                 ` <5fc2de0f-82db-4d02-9dc9-ff5db8a8b9b4-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-04-07 12:03                   ` BPJ
     [not found]                     ` <5a4d26a3-b9b7-dda1-d437-6e7cdd519dba-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2019-06-26  0:56                       ` Hans Kunkell
     [not found]                         ` <1375b479-60d6-4514-8c72-db60f3355ab8-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-06-26  8:25                           ` pbeltran
     [not found]                             ` <9ab5d37d-74c0-4793-81fe-c6cdab9e253d-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-06-26  8:31                               ` Hans Kunkell
     [not found]                                 ` <4f0d389c-c21c-4069-a344-ef6ce1efb113-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-06-26  8:40                                   ` pbeltran

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 NNTP newsgroup(s).