* Creation of a filter that accepts an option
@ 2018-10-02 13:55 kiko.fernandez-1zs4UD6AkMk
[not found] ` <643e81d5-c3a2-4f68-927c-0500bb6ffd46-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: kiko.fernandez-1zs4UD6AkMk @ 2018-10-02 13:55 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 2251 bytes --]
Hi,
I am trying to create a filter that shows/hides notes. I have the notation
that if there is a fenced code block with attribute "note" then the fenced
block is really a note.
With this filter, I will remove all "note" blocks from the final output and
my supervisor will only see the good stuff. However, I would like to
re-include the notes for myself, in case I read the PDF or HTML version. Is
there a way to create a filter that, based on the first character or option
that I pass, decides to show or hide these notes?
My code so far looks like this:
```
module Main where
import Text.Pandoc.JSON
import Debug.Trace
removeFenceNotes :: Block -> Block
removeFenceNotes cb@(CodeBlock (id, classes, namevals) contents) =
case lookup "note" namevals of
Just f -> Div ("", [], []) []
Nothing -> cb
removeFenceNotes x = x
main :: IO ()
main = do c <- getChar
if c == 'e' then toJSONFilter removeFenceNotes
else toJSONFilter removeFenceNotes -- Should show notes removing
the code block and reinterpreting the text
```
When I decide to show notes, I would like to remove the code block and
reinterpret the markdown in the standard way.
I got it to work if there is no case to consider, i.e., no 'e' (for
enabled) or such stuff.
Is this possible to do?
Thanks!
P.S. I do not mind to do it using footnotes, since there is no
reinterpretation of the string received. However I thought that it would be
a good exercise to see if this is doable.
If I get this to work, I would like to write a brief article on
opensource.com in line with recent articles that I have been putting there.
I hope that this is ok.
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/643e81d5-c3a2-4f68-927c-0500bb6ffd46%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[-- Attachment #1.2: Type: text/html, Size: 3059 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Creation of a filter that accepts an option
[not found] ` <643e81d5-c3a2-4f68-927c-0500bb6ffd46-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2018-10-02 14:01 ` Robert Zenz
[not found] ` <5BB37A37.3050801-q1xk7osDwJUWQnjQ7V0W7w@public.gmane.org>
2018-10-02 21:39 ` Kolen Cheung
2018-10-04 8:21 ` kiko.fernandez-1zs4UD6AkMk
2 siblings, 1 reply; 8+ messages in thread
From: Robert Zenz @ 2018-10-02 14:01 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
You could use environment variables. Something like this:
$ KEEP_NOTES=true pandoc ...
And in the Lua filter:
if os.getenv("KEEP_NOTES") == nil then
-- Hide the notes here.
end
On 02.10.2018 15:55, kiko.fernandez-1zs4UD6AkMk@public.gmane.org wrote:
> Hi,
>
> I am trying to create a filter that shows/hides notes. I have the notation
> that if there is a fenced code block with attribute "note" then the fenced
> block is really a note.
> With this filter, I will remove all "note" blocks from the final output and
> my supervisor will only see the good stuff. However, I would like to
> re-include the notes for myself, in case I read the PDF or HTML version. Is
> there a way to create a filter that, based on the first character or option
> that I pass, decides to show or hide these notes?
>
> My code so far looks like this:
>
> ```
> module Main where
>
> import Text.Pandoc.JSON
> import Debug.Trace
>
> removeFenceNotes :: Block -> Block
> removeFenceNotes cb@(CodeBlock (id, classes, namevals) contents) =
> case lookup "note" namevals of
> Just f -> Div ("", [], []) []
> Nothing -> cb
> removeFenceNotes x = x
>
> main :: IO ()
> main = do c <- getChar
> if c == 'e' then toJSONFilter removeFenceNotes
> else toJSONFilter removeFenceNotes -- Should show notes removing
> the code block and reinterpreting the text
> ```
>
> When I decide to show notes, I would like to remove the code block and
> reinterpret the markdown in the standard way.
>
> I got it to work if there is no case to consider, i.e., no 'e' (for
> enabled) or such stuff.
> Is this possible to do?
>
> Thanks!
>
> P.S. I do not mind to do it using footnotes, since there is no
> reinterpretation of the string received. However I thought that it would be
> a good exercise to see if this is doable.
> If I get this to work, I would like to write a brief article on
> opensource.com in line with recent articles that I have been putting there.
> I hope that this is ok.
>
> Thanks.
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Creation of a filter that accepts an option
[not found] ` <5BB37A37.3050801-q1xk7osDwJUWQnjQ7V0W7w@public.gmane.org>
@ 2018-10-02 14:03 ` Robert Zenz
0 siblings, 0 replies; 8+ messages in thread
From: Robert Zenz @ 2018-10-02 14:03 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
Well, just realized you don't use Lua...but I guess the mechanic is the same, or
at least close.
Also you'd only provide the environment variable if you wanted to keep the
notes, obviously.
On 02.10.2018 16:01, Robert Zenz wrote:
> You could use environment variables. Something like this:
>
> $ KEEP_NOTES=true pandoc ...
>
> And in the Lua filter:
>
> if os.getenv("KEEP_NOTES") == nil then
> -- Hide the notes here.
> end
>
> On 02.10.2018 15:55, kiko.fernandez-1zs4UD6AkMk@public.gmane.org wrote:
>> Hi,
>>
>> I am trying to create a filter that shows/hides notes. I have the notation
>> that if there is a fenced code block with attribute "note" then the fenced
>> block is really a note.
>> With this filter, I will remove all "note" blocks from the final output and
>> my supervisor will only see the good stuff. However, I would like to
>> re-include the notes for myself, in case I read the PDF or HTML version. Is
>> there a way to create a filter that, based on the first character or option
>> that I pass, decides to show or hide these notes?
>>
>> My code so far looks like this:
>>
>> ```
>> module Main where
>>
>> import Text.Pandoc.JSON
>> import Debug.Trace
>>
>> removeFenceNotes :: Block -> Block
>> removeFenceNotes cb@(CodeBlock (id, classes, namevals) contents) =
>> case lookup "note" namevals of
>> Just f -> Div ("", [], []) []
>> Nothing -> cb
>> removeFenceNotes x = x
>>
>> main :: IO ()
>> main = do c <- getChar
>> if c == 'e' then toJSONFilter removeFenceNotes
>> else toJSONFilter removeFenceNotes -- Should show notes removing
>> the code block and reinterpreting the text
>> ```
>>
>> When I decide to show notes, I would like to remove the code block and
>> reinterpret the markdown in the standard way.
>>
>> I got it to work if there is no case to consider, i.e., no 'e' (for
>> enabled) or such stuff.
>> Is this possible to do?
>>
>> Thanks!
>>
>> P.S. I do not mind to do it using footnotes, since there is no
>> reinterpretation of the string received. However I thought that it would be
>> a good exercise to see if this is doable.
>> If I get this to work, I would like to write a brief article on
>> opensource.com in line with recent articles that I have been putting there.
>> I hope that this is ok.
>>
>> Thanks.
>>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Creation of a filter that accepts an option
[not found] ` <643e81d5-c3a2-4f68-927c-0500bb6ffd46-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2018-10-02 14:01 ` Robert Zenz
@ 2018-10-02 21:39 ` Kolen Cheung
[not found] ` <6d5f7166-099c-4fa7-92c9-b60146ea97a5-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2018-10-04 8:21 ` kiko.fernandez-1zs4UD6AkMk
2 siblings, 1 reply; 8+ messages in thread
From: Kolen Cheung @ 2018-10-02 21:39 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 731 bytes --]
c.f. the thread
in https://groups.google.com/d/msg/pandoc-discuss/LIAfgkZKUiE/_KfI3VI6EgAJ about
filter arg. In short env. var. is the way to go right now.
--
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/6d5f7166-099c-4fa7-92c9-b60146ea97a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[-- Attachment #1.2: Type: text/html, Size: 1146 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Creation of a filter that accepts an option
[not found] ` <6d5f7166-099c-4fa7-92c9-b60146ea97a5-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2018-10-03 13:56 ` kiko.fernandez-1zs4UD6AkMk
0 siblings, 0 replies; 8+ messages in thread
From: kiko.fernandez-1zs4UD6AkMk @ 2018-10-03 13:56 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 4223 bytes --]
Thanks everyone, the env vars worked perfectly well.
I got it to almost work doing reinterpretation of the AST.
There is just one tiny thing that doesn't seem to work, and that is adding
a citation to a Listing.
I am going to copy-paste the filter and the example. Hopefully, someone who
knows more Pandoc
internals can help me understand what is going on, and possibly, how to fix
it.
Thanks
```Haskell filter
module Main where
import Text.Pandoc.JSON
import System.IO.Error (catchIOError)
import System.Environment (getEnv)
import Text.Pandoc
import Data.Text (Text, pack)
import qualified Data.Map as M
writeMd :: Pandoc -> PandocIO Text
writeMd p = writeMarkdown def p
readMd :: Text -> PandocIO Pandoc
readMd t = readMarkdown def t
removeFenceNotes :: Block -> Block
removeFenceNotes cb@(CodeBlock (_, _, namevals) _) =
case lookup "note" namevals of
Just _ -> Div ("", [], []) []
Nothing -> cb
removeFenceNotes x = x
reinterpretation :: Block -> IO [Block]
reinterpretation cb@(CodeBlock (_, _, namevals) text) =
case lookup "note" namevals of
Just _ -> do
p <- runIOorExplode $ readMd (pack text)
textMd <- runIOorExplode $ writeMd p
p' <- runIOorExplode $ readMd textMd
case p' of
Pandoc _ b -> return b
Nothing -> return [cb]
reinterpretation x = return [x]
main = do
v <- catchIOError (getEnv "FILTERING_MODE") (\_ -> return "")
case v of
"WITH_COMMENTS" -> toJSONFilter reinterpretation
"NO_COMMENTS" -> toJSONFilter removeFenceNotes -- disable comments
_ -> return ()
```
I call Pandoc with the following command:
```
FILTERING_MODE=WITH_COMMENTS pandoc -s -f markdown -F filters -F
pandoc-crossref meta.yaml -o test.pdf TEST.md
```
and the TEST.md file looks as follows:
```
# Capabilities status
```{#lst:maybeLinearSupport .encore
caption="Support for `Maybe`'s do not fully work with `linear` types."}
subord class Two
var x: int
def init(): unit
this.x = 5
end
end
linear class One: Id
var sub: Two
def init(): unit
this.sub = new Two()
end
def x(): int
this.sub.x
end
def setX(x: int): unit
this.sub.x = x
end
end
-- this function does not compile. I cannot get it to
-- compile in any possible way
fun moo(var m: Maybe[One]): One
match consume m with
case Nothing => consume new One()
case Just(z) => consume(z)
end
end
```
In @lst:maybeLinearSupport, if `One` is `read`, then the function `moo` who
receives
a `Maybe[One]` works. The distinction between a `read Maybe[One]` and a
`linear Maybe[One]`
prevents us from reusing this function, i.e., the annotations of `var` and
`val`
are different and the function cannot be polymorphic on its *mode*.
~~~{note=""}
linearity seems to be more related to a property of the object rather than
a mode by itself. this means, @lst:maybeLinearSupport can declare a
function that
we know does not use any linear and we could declare another function that
may
be `read`, `local` or any other mode that has to be treated *linearly*.
what are the implications of this?
~~~
```
The end result contains the notes without the code block scope and also
contain the
all markdown items well-formatted, i.e., bold, italics, etc. The only thing
that didn't work
was reading the reference `@lst:maybeLinearSupport`, which is printed as it
looks, instead
of referencing the figure.
Thanks.
On Tuesday, October 2, 2018 at 11:39:41 PM UTC+2, Kolen Cheung wrote:
>
> c.f. the thread in
> https://groups.google.com/d/msg/pandoc-discuss/LIAfgkZKUiE/_KfI3VI6EgAJ about
> filter arg. In short env. var. is the way to go right now.
>
--
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/53d16307-c278-4f3a-8934-f44d9e40862c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[-- Attachment #1.2: Type: text/html, Size: 6103 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Creation of a filter that accepts an option
[not found] ` <643e81d5-c3a2-4f68-927c-0500bb6ffd46-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2018-10-02 14:01 ` Robert Zenz
2018-10-02 21:39 ` Kolen Cheung
@ 2018-10-04 8:21 ` kiko.fernandez-1zs4UD6AkMk
[not found] ` <e28b2c92-2f45-4c2a-9bb6-8084c2f95ad3-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2 siblings, 1 reply; 8+ messages in thread
From: kiko.fernandez-1zs4UD6AkMk @ 2018-10-04 8:21 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 2972 bytes --]
I fixed it walking a bit more. For some reason, the citation @XXXX is read
as a (Str x)
value instead of a Cite value. Walking the tree and pattern matching solved
it.
Thanks.
I will hopefully publish this in opensource.com in a month or so, maybe
earlier.
I think the "walk" function is awesome and more people should know that
building
a filter is not that difficult and it is fun!
I will post the link to the article once it is published, so that the
community can
read how I built it and how it works.
Thanks everyone
On Tuesday, October 2, 2018 at 3:55:10 PM UTC+2, kiko.fe...-1zs4UD6AkMk@public.gmane.org wrote:
>
> Hi,
>
> I am trying to create a filter that shows/hides notes. I have the notation
> that if there is a fenced code block with attribute "note" then the fenced
> block is really a note.
> With this filter, I will remove all "note" blocks from the final output
> and my supervisor will only see the good stuff. However, I would like to
> re-include the notes for myself, in case I read the PDF or HTML version. Is
> there a way to create a filter that, based on the first character or option
> that I pass, decides to show or hide these notes?
>
> My code so far looks like this:
>
> ```
> module Main where
>
> import Text.Pandoc.JSON
> import Debug.Trace
>
> removeFenceNotes :: Block -> Block
> removeFenceNotes cb@(CodeBlock (id, classes, namevals) contents) =
> case lookup "note" namevals of
> Just f -> Div ("", [], []) []
> Nothing -> cb
> removeFenceNotes x = x
>
> main :: IO ()
> main = do c <- getChar
> if c == 'e' then toJSONFilter removeFenceNotes
> else toJSONFilter removeFenceNotes -- Should show notes removing
> the code block and reinterpreting the text
> ```
>
> When I decide to show notes, I would like to remove the code block and
> reinterpret the markdown in the standard way.
>
> I got it to work if there is no case to consider, i.e., no 'e' (for
> enabled) or such stuff.
> Is this possible to do?
>
> Thanks!
>
> P.S. I do not mind to do it using footnotes, since there is no
> reinterpretation of the string received. However I thought that it would be
> a good exercise to see if this is doable.
> If I get this to work, I would like to write a brief article on
> opensource.com in line with recent articles that I have been putting
> there. I hope that this is ok.
>
> 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/e28b2c92-2f45-4c2a-9bb6-8084c2f95ad3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[-- Attachment #1.2: Type: text/html, Size: 4408 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Creation of a filter that accepts an option
[not found] ` <e28b2c92-2f45-4c2a-9bb6-8084c2f95ad3-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2018-10-04 16:22 ` John MacFarlane
[not found] ` <m2d0spu1eu.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: John MacFarlane @ 2018-10-04 16:22 UTC (permalink / raw)
To: kiko.fernandez-1zs4UD6AkMk, pandoc-discuss
kiko.fernandez-1zs4UD6AkMk@public.gmane.org writes:
> I fixed it walking a bit more. For some reason, the citation @XXXX is read
> as a (Str x)
> value instead of a Cite value. Walking the tree and pattern matching solved
> it.
Perhaps because you're running your filter after
pandoc-crossref, which would convert it to a Str?
Yes, filters are definitely fun and not too hard.
Good to publicize that!
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Creation of a filter that accepts an option
[not found] ` <m2d0spu1eu.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
@ 2018-10-05 10:33 ` kiko.fernandez-1zs4UD6AkMk
0 siblings, 0 replies; 8+ messages in thread
From: kiko.fernandez-1zs4UD6AkMk @ 2018-10-05 10:33 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 1480 bytes --]
Hi John,
thanks for your advise. However, wouldn't this apply the my filter, named
filters, first and then the pandoc-cross-ref?
FILTERING_MODE=WITH_COMMENTS pandoc -s -f markdown -F filters -F
pandoc-crossref meta.yaml -o test.pdf TEST.md
In any case, I tried changing the order and didn't get it to work without
pattern matching on the Str data value.
I found that weird.
On Thursday, October 4, 2018 at 6:23:05 PM UTC+2, John MacFarlane wrote:
>
> kiko.fe...-1zs4UD6AkMk@public.gmane.org <javascript:> writes:
>
> > I fixed it walking a bit more. For some reason, the citation @XXXX is
> read
> > as a (Str x)
> > value instead of a Cite value. Walking the tree and pattern matching
> solved
> > it.
>
> Perhaps because you're running your filter after
> pandoc-crossref, which would convert it to a Str?
>
> Yes, filters are definitely fun and not too hard.
> Good to publicize that!
>
--
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/f91cf9f6-8d38-43ac-b3a5-b21070c66e14%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[-- Attachment #1.2: Type: text/html, Size: 2368 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2018-10-05 10:33 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-02 13:55 Creation of a filter that accepts an option kiko.fernandez-1zs4UD6AkMk
[not found] ` <643e81d5-c3a2-4f68-927c-0500bb6ffd46-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2018-10-02 14:01 ` Robert Zenz
[not found] ` <5BB37A37.3050801-q1xk7osDwJUWQnjQ7V0W7w@public.gmane.org>
2018-10-02 14:03 ` Robert Zenz
2018-10-02 21:39 ` Kolen Cheung
[not found] ` <6d5f7166-099c-4fa7-92c9-b60146ea97a5-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2018-10-03 13:56 ` kiko.fernandez-1zs4UD6AkMk
2018-10-04 8:21 ` kiko.fernandez-1zs4UD6AkMk
[not found] ` <e28b2c92-2f45-4c2a-9bb6-8084c2f95ad3-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2018-10-04 16:22 ` John MacFarlane
[not found] ` <m2d0spu1eu.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2018-10-05 10:33 ` kiko.fernandez-1zs4UD6AkMk
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).