From: "Sébastien Boisgérault" <sebastien.boisgerault-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Re: Pandoc Document Model in Python
Date: Sat, 4 Dec 2021 08:48:58 -0800 (PST) [thread overview]
Message-ID: <42a53bd7-98db-4bca-a6c8-d052a03fbf40n@googlegroups.com> (raw)
In-Reply-To: <1e952a20-a77f-4987-9e7f-bac963ba4385n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
[-- Attachment #1.1: Type: text/plain, Size: 4392 bytes --]
I also don't know if panflute supports pattern matching (not seen any
examples in the doc). For example is there a pattern like this one ?
>>> doc = pandoc.read("Hello world!")
>>> match doc:
... case Pandoc(Meta(meta), [Para(inlines)]):
... assert meta == {}
... print(inlines)
[Str('Hello'), Space(), Str('world!')]
Cheers,
Sébastien
Le samedi 4 décembre 2021 à 17:17:46 UTC+1, Sébastien Boisgérault a écrit :
> To be honest I have not studied panflute in great details (started my own
> project before panflute 1.0 was released when my use case was not covered
> yet).
> I guess that there is a lot of common ground here but with different
> elements of style, so if you are a happy user of panflute, i don't avise
> you to change.
> I'd say that panflute probably feels higher-level (and maybe terser for
> the common use cases ?) and pandoc (Python) more minimalistic and slightly
> more Haskell-ish.
>
> Some misc. things I can think of:
>
> - Pandoc (python) adapts the AST model which is used to the pandoc
> version discovered on your system (or to the one you specify),
> so you will probably only need a single version of it, even if you
> deal with several pandoc binaries.
>
> - Our hierarchy of classes is automatically generated (from the
> registered Haskell type info). So if you know the original data model
> <https://hackage.haskell.org/package/pandoc-types-1.22.1/docs/Text-Pandoc-Definition.html>,
> then you're already covered.
> If you don't know it, it is documented
> <https://boisgera.github.io/pandoc/api/#pandoctypes> but you can also
> discover it interactively in the Python interpreter (which I like very much
> ❤️):
>
> >>> from pandoc.types import *
> >>> Pandoc
> Pandoc(Meta, [Block])
> >>> Block
> Block = Plain([Inline])
> | Para([Inline])
> | LineBlock([[Inline]])
> ...
> | Div(Attr, [Block])
> | Null()
> >>> Para
> Para([Inline])
> >>> Inline
> Inline = Str(String)
> | Emph([Inline])
> | Strong([Inline])
> | Strikeout([Inline])
> ...
> | Note([Block])
> | Span(Attr, [Inline])
>
> I don't know how the panflute type hierarchy is generated (manually ?)
> and exactly what the trade-offs are in each case.
> For example we don't use named arguments for the pandoc element
> arguments since there is no such thing in Haskell.
> There are differences such as Para(Str('eggs')) for panflute but Para(
> [Str('eggs')]) for pandoc (Python) (to compare with the Haskell type info
> <https://hackage.haskell.org/package/pandoc-types-1.22.1/docs/Text-Pandoc-Definition.html#t:Block>
> )
> The panflute types have also more methods while ours are rather "dumb"
> (mere algebraic data types) which is a matter of taste I guess (?).
> But overall the (AST) type hierarchy feels very similar.
>
> - I think that apart from the AST, the core of panflute is probably
> run_filter, while our core tool is pandoc.iter, a (top-down,
> document-order) iterator.
>
> - The dynamic type checking of panflute is very nice 👍. I don't have
> the equivalent (yet) and that can honestly sometimes be a pain.
>
> If you are a regular panflute user and can have a quick look our docs
> <https://boisgera.github.io/pandoc/>, especially the examples of code,
> I'd appreciate some feedback about what you like and don't like!
>
> Cheers,
>
> Sébastien
>
> Le samedi 4 décembre 2021 à 16:30:46 UTC+1, Joseph a écrit :
>
>> Can you speak to what the advantages of this would be over panflute?
>>
>> http://scorreia.com/software/panflute/
>>
>> On 21-12-04 09:43, Sébastien Boisgérault wrote:
>> > AFAICT filters are document AST to AST transformations. In this Python
>> library, docs (Pandoc instances) represent this AST, so a typical AST
>> (in-place) transform would be:
>>
>
--
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/42a53bd7-98db-4bca-a6c8-d052a03fbf40n%40googlegroups.com.
[-- Attachment #1.2: Type: text/html, Size: 7194 bytes --]
next prev parent reply other threads:[~2021-12-04 16:48 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <AQHX6RGokE17J35tB0eLtRDrIrd1JqwiXcS8///5/wCAABOrKA==>
[not found] ` <AQHX6RGokE17J35tB0eLtRDrIrd1JqwiXcS8>
2021-12-04 13:20 ` Sébastien Boisgérault
[not found] ` <f224cd2c-7d68-40b4-a855-7d4d0d7aa442n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-12-04 14:06 ` AW: " denis.maier-NSENcxR/0n0
[not found] ` <3b5d75fe4e2a45e38ab45a820d110faf-NSENcxR/0n0@public.gmane.org>
2021-12-04 14:43 ` Sébastien Boisgérault
[not found] ` <de1fd005-0d0d-49a2-86cc-5a72c764835dn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-12-04 14:58 ` AW: " denis.maier-NSENcxR/0n0
[not found] ` <fafa9cffd5e4437c865e71875b2f58a2-NSENcxR/0n0@public.gmane.org>
2021-12-04 15:35 ` Sébastien Boisgérault
2021-12-04 15:30 ` Joseph Reagle
[not found] ` <fe2b314b-863d-f8c0-8dfc-1104422fbf52-T1oY19WcHSwdnm+yROfE0A@public.gmane.org>
2021-12-04 16:17 ` Sébastien Boisgérault
[not found] ` <1e952a20-a77f-4987-9e7f-bac963ba4385n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-12-04 16:48 ` Sébastien Boisgérault [this message]
2021-12-04 17:30 ` John MacFarlane
2021-12-22 18:05 ` Joseph Reagle
[not found] ` <c0c49e25-898d-c72c-3303-69005985ea01-T1oY19WcHSwdnm+yROfE0A@public.gmane.org>
2021-12-23 10:56 ` Sébastien Boisgérault
[not found] ` <e45c083b-fff3-46ac-8af5-b416c60f6a97n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-12-23 14:25 ` Joseph Reagle
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=42a53bd7-98db-4bca-a6c8-d052a03fbf40n@googlegroups.com \
--to=sebastien.boisgerault-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).