public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: BP Jonsson <bpjonsson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: Re: Filter with arguments
Date: Sat, 7 Jan 2017 20:05:36 +0100	[thread overview]
Message-ID: <c21c773d-c958-2e55-725d-90863f5f9792@gmail.com> (raw)
In-Reply-To: <1239e0f1-2538-4781-8a75-90c59f86aabc-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>

Den 2017-01-07 kl. 00:10, skrev Kolen Cheung:
> In addition, the above discussion hasn’t covered the case that one might
> want to write a program that can acts as both a filter and a standalone
> cli.

Is that a realistic scenario? Either the program would have to 
expect pandoc-style JSON as input when used standalone, or it 
could check whether the input is (pandoc-style) JSON and do 
something completely different if it isn't! I have some scripts 
which do essentially the same things to HTML documents as some of 
my pandoc filters, but they use entirely different libraries: an 
HTML parser instead of a JSON parser, and a different library for 
manipulating the data structure produced by the respective parser.

Explicit piping of `-t json` output is also a rather outlandish 
problem: it is now effectively only used by filter authors 
debugging their filters, who then really should not expect to not 
have to specify the output format as an argument to the program on 
the rhs of the pipe.

As for the problem of metadata being interpreted as markdown the 
code which Pandoc::Elements uses to convert metadata to plain data 
is not too complicated (the `string` methods are already there for 
other purposes anyway):

     sub Pandoc::Document::metavalue {
         my $meta = $_[0]->meta;
         return { map { $_ => $meta->{$_}->metavalue } keys %$meta }
     }

     sub Pandoc::Document::MetaMap::metavalue {
         my $map = $_[0]->{c};
         return { map { $_ => $map->{$_}->metavalue } keys %$map }
     }

     sub Pandoc::Document::MetaList::metavalue {
         [ map { $_->metavalue } @{$_[0]->{c}} ]
     }

     sub Pandoc::Document::MetaInlines::metavalue {
         join '', map { $_->string } @{$_[0]->{c}}
     }

     sub Pandoc::Document::MetaBlocks::metavalue {
         join "\n", map { $_->string } @{$_[0]->{c}}
     }

     sub Pandoc::Document::MetaString::metavalue {
         $_[0]->{c}
     }

     sub Pandoc::Document::MetaBool::metavalue {
         $_[0]->{c} ? 1 : 0
     }

As for hierarchical metadata structures being ugly I don't think 
they are. They create a namespace and keep related data together 
without relying on sorting order, and often hierarchical data make 
things easier to do compared to non-hierarchical data. That's the 
reason data structures in general and hierarchical data structures 
in particular were invented. At a user experience level they keep 
each mapping key shorter and less repetitive, since otherwise you 
would in principle have to make every key a 'path' in order to 
avoid field name clashes. I have been in the situation of having 
to emulate hierarcical data structures in languages which don't 
have them, or even associative arrays, in languages which don't 
have them. It's no fun.
Consider a case where the user would supply different data to be 
used in processing elements with different classes with different 
output formats, in an hierachical version

     myfilter:
       class:
         foo:
           latex: ...
           html: ...
         bar:
           latex: ...
           html: ...
         ...
       ...

and a 'non-hierarchical' version

     myfilter-class-foo-latex: ...
     myfilter-class-foo-html: ...
     myfilter-class-bar-latex: ...
     myfilter-class-bar-html: ...

I vastly prefer the first both as a document author and as a 
filter author!

/bpj


-- 
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/c21c773d-c958-2e55-725d-90863f5f9792%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


  parent reply	other threads:[~2017-01-07 19:05 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
     [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 [this message]
     [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=c21c773d-c958-2e55-725d-90863f5f9792@gmail.com \
    --to=bpjonsson-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).