* [Maybe bug in docs] Filter “includes.hs” does not work for me
@ 2022-07-27 12:14 Jiří Wolker
[not found] ` <cada4d72-e81d-b39e-bd05-a6780b6848f5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Jiří Wolker @ 2022-07-27 12:14 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
Hello everyone,
I've probably found a bug in filter example that can be found in the
docs (https://pandoc.org/filters.html#include-files). The original
source code is:
#!/usr/bin/env runhaskell
-- includes.hs
import Text.Pandoc.JSON
import qualified Data.Text.IO as TIO
import qualified Data.Text as T
doInclude :: Block -> IO Block
doInclude cb@(CodeBlock (id, classes, namevals) contents) =
case lookup "include" namevals of
Just f -> CodeBlock (id, classes, namevals) <$>
TIO.readFile (T.unpack f)
Nothing -> return cb
doInclude x = return x
main :: IO ()
main = toJSONFilter doInclude
When I tried to execute it, it fails:
…/include.hs:12:25: error:
* Couldn't match type `T.Text' with `[Char]'
Expected: [(String, T.Text)]
Actual: [(T.Text, T.Text)]
* In the second argument of `lookup', namely `namevals'
In the expression: lookup "include" namevals
In the expression:
case lookup "include" namevals of
Just f
-> CodeBlock (id, classes, namevals) <$> TIO.readFile
(T.unpack f)
Nothing -> return cb
|
12 | case lookup "include" namevals of
| ^^^^^^^^
Error running filter …/filters/include.hs:
Filter returned error status 1
To fix the filter, I had to change the line with “case” to this:
case lookup (T.pack "include") namevals of
(i.e. call T.pack on the string literal.)
I am quite new to Haskell, correct me if I am wrong.
It is possible that this is dependent on the version of Haskell. I use
runghc 9.0.2 to run the script.
P.S.: It would be nice to include few scripts in the Pandoc
distribution. Ideas: includes.hs, directory listing (I write a div with
special class and it produces directory listing in the text.) I will
probably write the listing filter soon. It could be nice for creating
directory “overview”/readme files.
Thanks.
Jiří
--
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/cada4d72-e81d-b39e-bd05-a6780b6848f5%40gmail.com.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Maybe bug in docs] Filter “includes.hs” does not work for me
[not found] ` <cada4d72-e81d-b39e-bd05-a6780b6848f5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2022-07-27 15:41 ` John MacFarlane
[not found] ` <16369259-AD86-4025-8D32-00FD58E86C79-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: John MacFarlane @ 2022-07-27 15:41 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
You're right. I will fix that in the documentation (though it won't update on the website til the next release). Thank you.
> On Jul 27, 2022, at 5:14 AM, Jiří Wolker <woljiri-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> Hello everyone,
>
> I've probably found a bug in filter example that can be found in the docs (https://pandoc.org/filters.html#include-files). The original source code is:
>
> #!/usr/bin/env runhaskell
> -- includes.hs
> import Text.Pandoc.JSON
> import qualified Data.Text.IO as TIO
> import qualified Data.Text as T
>
> doInclude :: Block -> IO Block
> doInclude cb@(CodeBlock (id, classes, namevals) contents) =
> case lookup "include" namevals of
> Just f -> CodeBlock (id, classes, namevals) <$>
> TIO.readFile (T.unpack f)
> Nothing -> return cb
> doInclude x = return x
>
> main :: IO ()
> main = toJSONFilter doInclude
>
> When I tried to execute it, it fails:
>
> …/include.hs:12:25: error:
> * Couldn't match type `T.Text' with `[Char]'
> Expected: [(String, T.Text)]
> Actual: [(T.Text, T.Text)]
> * In the second argument of `lookup', namely `namevals'
> In the expression: lookup "include" namevals
> In the expression:
> case lookup "include" namevals of
> Just f
> -> CodeBlock (id, classes, namevals) <$> TIO.readFile (T.unpack f)
> Nothing -> return cb
> |
> 12 | case lookup "include" namevals of
> | ^^^^^^^^
> Error running filter …/filters/include.hs:
> Filter returned error status 1
>
> To fix the filter, I had to change the line with “case” to this:
>
> case lookup (T.pack "include") namevals of
>
> (i.e. call T.pack on the string literal.)
>
> I am quite new to Haskell, correct me if I am wrong.
>
> It is possible that this is dependent on the version of Haskell. I use runghc 9.0.2 to run the script.
>
> P.S.: It would be nice to include few scripts in the Pandoc distribution. Ideas: includes.hs, directory listing (I write a div with special class and it produces directory listing in the text.) I will probably write the listing filter soon. It could be nice for creating directory “overview”/readme files.
>
>
> Thanks.
> Jiří
>
> --
> 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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/cada4d72-e81d-b39e-bd05-a6780b6848f5%40gmail.com.
--
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/16369259-AD86-4025-8D32-00FD58E86C79%40gmail.com.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Maybe bug in docs] Filter “includes.hs” does not work for me
[not found] ` <16369259-AD86-4025-8D32-00FD58E86C79-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2022-07-28 12:47 ` Jiří Wolker
0 siblings, 0 replies; 3+ messages in thread
From: Jiří Wolker @ 2022-07-28 12:47 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 3467 bytes --]
Thanks for the fix. I had to recollect how to write programs in Haskell.
I'll start new thread for the “P.S.” part of my original message.
Dne středa 27. července 2022 v 17:41:26 UTC+2 uživatel fiddlosopher napsal:
> You're right. I will fix that in the documentation (though it won't update
> on the website til the next release). Thank you.
>
>
>
> > On Jul 27, 2022, at 5:14 AM, Jiří Wolker <wol...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> >
> > Hello everyone,
> >
> > I've probably found a bug in filter example that can be found in the
> docs (https://pandoc.org/filters.html#include-files). The original source
> code is:
> >
> > #!/usr/bin/env runhaskell
> > -- includes.hs
> > import Text.Pandoc.JSON
> > import qualified Data.Text.IO as TIO
> > import qualified Data.Text as T
> >
> > doInclude :: Block -> IO Block
> > doInclude cb@(CodeBlock (id, classes, namevals) contents) =
> > case lookup "include" namevals of
> > Just f -> CodeBlock (id, classes, namevals) <$>
> > TIO.readFile (T.unpack f)
> > Nothing -> return cb
> > doInclude x = return x
> >
> > main :: IO ()
> > main = toJSONFilter doInclude
> >
> > When I tried to execute it, it fails:
> >
> > …/include.hs:12:25: error:
> > * Couldn't match type `T.Text' with `[Char]'
> > Expected: [(String, T.Text)]
> > Actual: [(T.Text, T.Text)]
> > * In the second argument of `lookup', namely `namevals'
> > In the expression: lookup "include" namevals
> > In the expression:
> > case lookup "include" namevals of
> > Just f
> > -> CodeBlock (id, classes, namevals) <$> TIO.readFile (T.unpack f)
> > Nothing -> return cb
> > |
> > 12 | case lookup "include" namevals of
> > | ^^^^^^^^
> > Error running filter …/filters/include.hs:
> > Filter returned error status 1
> >
> > To fix the filter, I had to change the line with “case” to this:
> >
> > case lookup (T.pack "include") namevals of
> >
> > (i.e. call T.pack on the string literal.)
> >
> > I am quite new to Haskell, correct me if I am wrong.
> >
> > It is possible that this is dependent on the version of Haskell. I use
> runghc 9.0.2 to run the script.
> >
> > P.S.: It would be nice to include few scripts in the Pandoc
> distribution. Ideas: includes.hs, directory listing (I write a div with
> special class and it produces directory listing in the text.) I will
> probably write the listing filter soon. It could be nice for creating
> directory “overview”/readme files.
> >
> >
> > Thanks.
> > Jiří
> >
> > --
> > 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-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-discuss/cada4d72-e81d-b39e-bd05-a6780b6848f5%40gmail.com.
>
>
>
--
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/6cbf4958-24a5-46f7-95b8-b095018d96c7n%40googlegroups.com.
[-- Attachment #1.2: Type: text/html, Size: 5461 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-07-28 12:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-27 12:14 [Maybe bug in docs] Filter “includes.hs” does not work for me Jiří Wolker
[not found] ` <cada4d72-e81d-b39e-bd05-a6780b6848f5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2022-07-27 15:41 ` John MacFarlane
[not found] ` <16369259-AD86-4025-8D32-00FD58E86C79-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2022-07-28 12:47 ` Jiří Wolker
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).