From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/16619 Path: news.gmane.org!.POSTED!not-for-mail From: Matthew Pickering Newsgroups: gmane.text.pandoc Subject: Re: Filter with arguments Date: Fri, 6 Jan 2017 18:42:21 +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: text/plain; charset=UTF-8 X-Trace: blaine.gmane.org 1483728148 18520 195.159.176.226 (6 Jan 2017 18:42:28 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 6 Jan 2017 18:42:28 +0000 (UTC) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBCO2LGEC4AIBBD6KX7BQKGQEZV42J5Y-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Fri Jan 06 19:42:24 2017 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane.org Original-Received: from mail-lf0-f64.google.com ([209.85.215.64]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cPZT1-0003nc-HU for gtp-pandoc-discuss@m.gmane.org; Fri, 06 Jan 2017 19:42:19 +0100 Original-Received: by mail-lf0-f64.google.com with SMTP id o12sf3568508lfg.1 for ; Fri, 06 Jan 2017 10:42:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:in-reply-to:references: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=9aAzqDwufRr3lC3lT/OssYhPAKZ3IifwHfUuys9zucc=; b=J1MKkFcgdMekkB0CU5hMlGv1irblkNsa7nmibM3CVLndKfA6eBupmNw7GrVp6E0GDI +WILpbugm8AbodPr9r19kax8F6LihcUiaaHPYvMKNN/YVxql41IgB0tm9hLD5kLrHL5F UOEuE7kLTY4Chnbj8qjfKDHeqIVACMwzhsI2h/W5Atei1KljFnC26GuWpRaArePwSP9G ceEFri/PQqPoZ+85Ewng3AUGuhER1MgOb4iu8JxNPYclYTk3luLD14t+DASOvCjcCKxT 9WfhcKLvOnMxpkelOqSByIMeT0nJOsHLvSixyAJfVF8pWqYTZEcXF7dx5XHXa295j8GW yfcg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references: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=9aAzqDwufRr3lC3lT/OssYhPAKZ3IifwHfUuys9zucc=; b=XEAXL0DhupBgi+UAYdvcavyv9qP96TMrDfKIE3mwlEg0FslBckkhhf7MfmgPJFWZX8 ewaa+SxB/cXhV1PX3gyr70Eqg8u9jz4QtVdAnNw947nJhur42liL8dNL91nhAdU9j23i 4lzVamD/S+OFf83hwpoHv94yjBbC8w/GrybCPWhD26Jof+6YWzV402MGx2rUqA3BvtME jzTpK8iFY6lsv+GIw3WHS8kosdVDvNTtHaEh+0JU9QIOPBQVSgW4Oe4xDQaPmB+IM+tR 3D+2563x5HHEKErbvifWt3+hHhg1ENtdqD8ZqKqqSBllb0iWolA9fadiSanEjdd9rO9S DCFg== 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:in-reply-to:references: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=9aAzqDwufRr3lC3lT/OssYhPAKZ3IifwHfUuys9zucc=; b=LNuKRWdXlTWSmS3YZbNwyFJfzI5AFn2BqYZ8ZopR6AyOU/eyue/7ICYqCz711DfkXg s18mGNS8sJgr0v/iKP/nK1Q1V7FqXuh3ZrYYC+UxN2yxQj11jSUNmzVH3D0Ev4nVuoRw i4ZvapSavwI5TUJoM+nZ91ZqRN9iT/cAlj4+EHRVsC78FpGoZw8Ft05RhI4G5/Ha5RkU efg3Qva1I9G11yDytRFbfSfGWNUmz1LXP4n44tBf/0whalHbntSDQe1emaxtHbWIM/eG E0kZdLOY/jVvp7gSaat4f3d9B6lGpG0VLPiNPgj7zDqWR6oZ95mQ3P4vRjVvS4f7Xpeo Q4wQ== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AIkVDXIdhKQqJd3TwsvMulBR+/l/dKegcU518t6fzV4hEVnlL3RkxfyP6LYMc2NY/YCTSQ== X-Received: by 10.25.75.9 with SMTP id y9mr33230lfa.1.1483728144216; Fri, 06 Jan 2017 10:42:24 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 10.46.21.6 with SMTP id s6ls3164899ljd.2.gmail; Fri, 06 Jan 2017 10:42:23 -0800 (PST) X-Received: by 10.25.195.195 with SMTP id t186mr7175521lff.9.1483728143365; Fri, 06 Jan 2017 10:42:23 -0800 (PST) Original-Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com. [2a00:1450:400c:c09::242]) by gmr-mx.google.com with ESMTPS id l66si244822wml.0.2017.01.06.10.42.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Jan 2017 10:42:23 -0800 (PST) Received-SPF: pass (google.com: domain of matthewtpickering-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:400c:c09::242 as permitted sender) client-ip=2a00:1450:400c:c09::242; Original-Received: by mail-wm0-x242.google.com with SMTP id l2so7019337wml.2 for ; Fri, 06 Jan 2017 10:42:23 -0800 (PST) X-Received: by 10.223.176.210 with SMTP id j18mr2256585wra.8.1483728142853; Fri, 06 Jan 2017 10:42:22 -0800 (PST) Original-Received: by 10.80.147.129 with HTTP; Fri, 6 Jan 2017 10:42:21 -0800 (PST) In-Reply-To: X-Original-Sender: matthewtpickering-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@gmail.com; spf=pass (google.com: domain of matthewtpickering-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:400c:c09::242 as permitted sender) smtp.mailfrom=matthewtpickering-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE dis=NONE) header.from=gmail.com 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:16619 Archived-At: 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 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 : >> >> +++ 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.