From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/16618 Path: news.gmane.org!.POSTED!not-for-mail From: BPJ Newsgroups: gmane.text.pandoc Subject: Re: Filter with arguments Date: Fri, 06 Jan 2017 18:32:04 +0000 Message-ID: References: <20170106114647.GG791@Administrateurs-iMac-3.local> <8760ls8jby.fsf@fastmail.fm> <20170106125852.GA1662@Administrateurs-iMac-3.local> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=f403045ec68eb253400545713ccb X-Trace: blaine.gmane.org 1483727549 11191 195.159.176.226 (6 Jan 2017 18:32:29 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 6 Jan 2017 18:32:29 +0000 (UTC) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBCWMVYEK54FRBMGFX7BQKGQE5JROFZI-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Fri Jan 06 19:32:24 2017 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane.org Original-Received: from mail-wm0-f56.google.com ([74.125.82.56]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cPZJE-00014S-V3 for gtp-pandoc-discuss@m.gmane.org; Fri, 06 Jan 2017 19:32:13 +0100 Original-Received: by mail-wm0-f56.google.com with SMTP id t79sf6923353wmt.0 for ; Fri, 06 Jan 2017 10:32:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:references:in-reply-to:from:date:message-id :subject:to:x-original-sender:x-original-authentication-results :reply-to:precedence:mailing-list:list-id:x-spam-checked-in-group :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=8VLgyTbDv2DW3DC6hs2jl4zXVqoWTxZBZSYf9DQMcYk=; b=q5pwi5+GNq+km4U0rAYZ9Dg9KmdSmm9mr29bVlJ8/aVhJsYUsIpFDW7aE7DejoTqqN ACbkygXWgad+dmBixHLVRLLwNAosyrmnOuVcJW7wpdQUK9vWW/KLTu9WaMYKda41WuwG Fxw4v8bFNGW8XkZ+e5yrzD8RRwC0S17TJUw7+mQCdGQAJKSdEmGht4tPCgQVQSJ4acGM juNhljz8HOKRsl7Ys3IGkjel0vdPkBvavg+S6U8EVy6LMSlqhwf+14An1Z6PO7XFK/dO ByYrdDd6IVH6XJ1BZEF13sztR2+QtDNX92fIZ01dXctbiseTUDKGww/BcemfrbLNBXHE 7ijw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:references:in-reply-to:from :date:message-id:subject:to:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=8VLgyTbDv2DW3DC6hs2jl4zXVqoWTxZBZSYf9DQMcYk=; b=CMPuzFN2jTNEFI9CIK6JWmB5iZVscJ4+NGhKa1Oi3dbX3YjRWpSaX/TV9vbQwwP+4P wGYlmXTkc6YTnAP9DnH6n6QM61HKXi71Wac6kCxBPtn1eLaIJC6F54ZBhxGeV6bRv6am FksjKjjHEjxwHU6M6bmpdnU+EG6XKA6kjm1IiNbsFRlYW3/AOGVwBd2bTWfPlW6DQyWc Sm9aQcYfNgXpYXFb2LkCinWgvsusVoL4HzEOU/9biB/97h3VsGVynrlCzd/TmKqwLTLp LCarsgtS3YwNcgrkm6JMjXmK8fCRsAlCfvn6occejUfmD4SRGOeCVIqXos7SFIIqIamZ 057g== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AIkVDXLHxWCsH8ZlBocKMeCRtZ6ZPziLaZR5yJbsl3q9OvecmDcUqI7ndkRbZpNEhdqHug== X-Received: by 10.28.29.78 with SMTP id d75mr4624wmd.1.1483727537529; Fri, 06 Jan 2017 10:32:17 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 10.28.140.6 with SMTP id o6ls367247wmd.7.canary-gmail; Fri, 06 Jan 2017 10:32:16 -0800 (PST) X-Received: by 10.28.153.73 with SMTP id b70mr59wme.14.1483727536536; Fri, 06 Jan 2017 10:32:16 -0800 (PST) Original-Received: from mail-lf0-f43.google.com (mail-lf0-f43.google.com. [209.85.215.43]) by gmr-mx.google.com with ESMTPS id f71si162922wmf.2.2017.01.06.10.32.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Jan 2017 10:32:16 -0800 (PST) Received-SPF: pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Original-Received: by mail-lf0-f43.google.com with SMTP id v186so4630731lfa.1 for ; Fri, 06 Jan 2017 10:32:16 -0800 (PST) X-Received: by 10.46.78.1 with SMTP id c1mr26466590ljb.39.1483727535492; Fri, 06 Jan 2017 10:32:15 -0800 (PST) In-Reply-To: <20170106125852.GA1662-BKjuZOBx5Kn2N3qrpRCZGbhGAdq7xJNKhPhL2mjWHbk@public.gmane.org> X-Original-Sender: melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.215.43 as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Precedence: list Mailing-list: list pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org; contact pandoc-discuss+owners-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-ID: X-Google-Group-Id: 1007024079513 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Xref: news.gmane.org gmane.text.pandoc:16618 Archived-At: --f403045ec68eb253400545713ccb Content-Type: text/plain; charset=UTF-8 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 : > +++ 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. --f403045ec68eb253400545713ccb Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
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 stru= cture of metadata objects into a plain data structure so that `MetsMap`s ge= t converted to plain associative arrays, `MetaList`s to plain arrays and ot= her `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 prefix= ed 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 hind= ers you from also checking environment variables if metadata options are un= defined 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 k= l. 14:00 skrev John MacFarlane <jgm@= berkeley.edu>:
+++ Joost Kre= mers [Jan 06 17 13:27 ]:

>

>On Fri, Jan 06 2017, John MacFarlane wrote:

>>This is a pretty common request.=C2=A0 A couple of complic= ations:

>>

>= >1.=C2=A0 Pandoc calls each filter with one argument, the name of

>>the output format.=C2=A0 (Filters thus have ac= cess to this.)

>>If we allowed `-F "p= antable -t csv"`, how would this work?

>= >Would pandoc call `pantable latex -t csv`?=C2=A0 Would the filter

>>be expecting this?
>

>For a properly written filter that sho= uldn'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.=C2=A0 "I said to

run --f= ilter 'myfilter myarg', and for some reason 'myarg'

isn't the first argument!"



What's wrong with communicating opt= ions to filters through

environment variables, w= hich you can already do?



=C2=A0 =C2=A0 PANTABLE_OUTPUT=3D"csv" pandoc --filter pantab= le



>pandoc --filt= er "My Cool Filter.py" --filter-args "-t csv"

>

>with each --filter-a= rgs 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 argu= ment of

>--filter-args without having to pars= e 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 convinc= ed that environment variables

don't already = provide a perfectly adequate way to do this.


--

You received this me= ssage because you are subscribed to the Google Groups "pandoc-discuss&= quot; group.

To unsubscribe from this group and = stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to pandoc-discuss@googleg= roups.com.

To view this discussion on the we= b visit https://groups.google.com/d/msgid/pandoc-discu= ss/20170106125852.GA1662%40Administrateurs-iMac-3.local.

For more options, visit https://g= roups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups &= quot;pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to pand= oc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://group= s.google.com/d/msgid/pandoc-discuss/CADAJKhCPn81DsWpzWSQHv59ii%2BSLXmz4Ww5r= u1mSmP4eRQozow%40mail.gmail.com.
For more options, visit http= s://groups.google.com/d/optout.
--f403045ec68eb253400545713ccb--