public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: Matthew Pickering <matthewtpickering-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: Re: Filter with arguments
Date: Fri, 6 Jan 2017 18:42:21 +0000	[thread overview]
Message-ID: <CALuQ0m8Jx2N_nKKOL5i5pNM9houf_iUe2Z54uWeajm2oVEZW5w@mail.gmail.com> (raw)
In-Reply-To: <CADAJKhCPn81DsWpzWSQHv59ii+SLXmz4Ww5ru1mSmP4eRQozow-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

Communicating arguments though env vars is very ad-hoc, an option
"--filter-arguments" (like Joost suggests) which took a string and
passed it to the filter when invoked would be sufficient.

pandoc --filter myfilter --filter-options="--foo --baz --bar"

results in pandoc calling

myfilter csv --foo --baz --bar

I investigated reimplementing pandoc-lit as a filter but it was not
possible because the program has a lot of command line arguments you
need to specify.

The worry about passing the format as the first argument being
confusing could be overcome by embedding more metadata into the JSON
input.

Matt

On Fri, Jan 6, 2017 at 6:32 PM, BPJ <bpj-J3H7GcXPSITLoDKTGw+V6w@public.gmane.org> wrote:
> The best way to pass options to filters is through metadata. That gets
> considerably easier if the filter can use a function which converts a
> structure of metadata objects into a plain data structure so that `MetsMap`s
> get converted to plain associative arrays, `MetaList`s to plain arrays and
> other `Meta` elements to plain strings or booleans. It is easy to write such
> a function using existing walking and steingification functions.
>
> Once you get the hang of that you don't feel any need to pass custom
> arguments to filters because it is so convenient to do filter config in the
> document. A useful way to avoid a lot of metadata keys prefixed with filter
> names is to have a single key equal to the filter name with a mapping as
> value which contains the options for that filter. Nothing hinders you from
> also checking environment variables if metadata options are undefined and
> use hardcoded defaults only if the env vars are also undefined. I do so
> often enough to have written a helper function.
>
> /bpj
>
> fre 6 jan. 2017 kl. 14:00 skrev John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org>:
>>
>> +++ Joost Kremers [Jan 06 17 13:27 ]:
>>
>> >
>>
>> >On Fri, Jan 06 2017, John MacFarlane wrote:
>>
>> >>This is a pretty common request.  A couple of complications:
>>
>> >>
>>
>> >>1.  Pandoc calls each filter with one argument, the name of
>>
>> >>the output format.  (Filters thus have access to this.)
>>
>> >>If we allowed `-F "pantable -t csv"`, how would this work?
>>
>> >>Would pandoc call `pantable latex -t csv`?  Would the filter
>>
>> >>be expecting this?
>>
>> >
>>
>> >For a properly written filter that shouldn't be a problem, should it?
>>
>> >You just need to decide on one way of doing it and stick to it.
>>
>> >Filters then need to be updated accordingly. Or are you worried about
>>
>> >backward compatibility?
>>
>>
>>
>> Well, I'm anticipating people getting confused.  "I said to
>>
>> run --filter 'myfilter myarg', and for some reason 'myarg'
>>
>> isn't the first argument!"
>>
>>
>>
>> What's wrong with communicating options to filters through
>>
>> environment variables, which you can already do?
>>
>>
>>
>>     PANTABLE_OUTPUT="csv" pandoc --filter pantable
>>
>>
>>
>> >pandoc --filter "My Cool Filter.py" --filter-args "-t csv"
>>
>> >
>>
>> >with each --filter-args referring to the immediately preceding
>>
>> >--filters option. Depending on how Pandoc calls filters, it may even
>>
>> >be possible to just pass it the literal string argument of
>>
>> >--filter-args without having to parse it into different options.
>>
>>
>>
>> I think this is too complex, with --filter-args affecting
>>
>> the immediately preceding --filter option.
>>
>>
>>
>> Again, I'd have to be convinced that environment variables
>>
>> don't already provide a perfectly adequate way to do this.
>>
>>
>>
>> --
>>
>> 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/20170106125852.GA1662%40Administrateurs-iMac-3.local.
>>
>> 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/CADAJKhCPn81DsWpzWSQHv59ii%2BSLXmz4Ww5ru1mSmP4eRQozow%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.


  parent reply	other threads:[~2017-01-06 18:42 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-06  4:32 [Feature Request] " Kolen Cheung
     [not found] ` <e8cf9c92-7aa7-4841-85d0-7464c771cf6e-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2017-01-06 11:46   ` John MacFarlane
     [not found]     ` <20170106114647.GG791-BKjuZOBx5Kn2N3qrpRCZGbhGAdq7xJNKhPhL2mjWHbk@public.gmane.org>
2017-01-06 12:27       ` Joost Kremers
     [not found]         ` <8760ls8jby.fsf-97jfqw80gc6171pxa8y+qA@public.gmane.org>
2017-01-06 12:58           ` John MacFarlane
     [not found]             ` <20170106125852.GA1662-BKjuZOBx5Kn2N3qrpRCZGbhGAdq7xJNKhPhL2mjWHbk@public.gmane.org>
2017-01-06 18:32               ` BPJ
     [not found]                 ` <CADAJKhCPn81DsWpzWSQHv59ii+SLXmz4Ww5ru1mSmP4eRQozow-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-06 18:42                   ` Matthew Pickering [this message]
     [not found]                     ` <CALuQ0m8Jx2N_nKKOL5i5pNM9houf_iUe2Z54uWeajm2oVEZW5w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-06 19:47                       ` BPJ
2017-01-06 21:11                       ` John MacFarlane
     [not found]                         ` <20170106211115.GA30105-l/d5Ua9yGnxXsXJlQylH7w@public.gmane.org>
2017-01-06 21:36                           ` BPJ
2017-01-08 19:40               ` Joost Kremers
2017-01-06 23:10       ` Kolen Cheung
     [not found]         ` <1239e0f1-2538-4781-8a75-90c59f86aabc-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2017-01-07 19:05           ` BP Jonsson
     [not found]             ` <c21c773d-c958-2e55-725d-90863f5f9792-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-01-07 20:51               ` Kolen Cheung
     [not found]                 ` <de2e97b1-17a4-4f70-8c17-b3cd960dceb2-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2017-01-07 22:53                   ` BP Jonsson
     [not found]                     ` <CAFC_yuTR=2UQZPN4EFbKTCOAwR9tOoS1+sYy5rLRViNo908s-Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-08  9:09                       ` John MacFarlane
     [not found]                         ` <CADAJKhAwBq+mxsimD83aefMEUCm025i5QaNvfpGBzrAWrB7atQ@mail.gmail.com>
     [not found]                           ` <CADAJKhACOpd-yQHTBTrL4VbCg8zyGiJX7WwECsifGtihbyyzCA@mail.gmail.com>
     [not found]                             ` <CADAJKhACOpd-yQHTBTrL4VbCg8zyGiJX7WwECsifGtihbyyzCA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-08 11:21                               ` Melroch
2017-01-08 20:51   ` [Feature Request] " Kolen Cheung
     [not found]     ` <434dc10f-02a1-4bbc-a41c-3a29398ca635-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2017-01-09 11:26       ` BP Jonsson
     [not found]         ` <CAFC_yuRuuDDfbok7Gds-kdj_ySqvpF0psnTUn0-TRvdEhRUs+Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-08-06 23:33           ` Kolen Cheung
2018-06-20 14:58   ` Peter Zagubisalo

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=CALuQ0m8Jx2N_nKKOL5i5pNM9houf_iUe2Z54uWeajm2oVEZW5w@mail.gmail.com \
    --to=matthewtpickering-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).