public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: John MacFarlane <fiddlosopher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: Re: [Maybe bug in docs] Filter “includes.hs” does not work for me
Date: Wed, 27 Jul 2022 08:41:19 -0700	[thread overview]
Message-ID: <16369259-AD86-4025-8D32-00FD58E86C79@gmail.com> (raw)
In-Reply-To: <cada4d72-e81d-b39e-bd05-a6780b6848f5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

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.


  parent reply	other threads:[~2022-07-27 15:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-27 12:14 Jiří Wolker
     [not found] ` <cada4d72-e81d-b39e-bd05-a6780b6848f5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2022-07-27 15:41   ` John MacFarlane [this message]
     [not found]     ` <16369259-AD86-4025-8D32-00FD58E86C79-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2022-07-28 12:47       ` Jiří Wolker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=16369259-AD86-4025-8D32-00FD58E86C79@gmail.com \
    --to=fiddlosopher-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).