From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/29669 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?S=C3=A9bastien_Boisg=C3=A9rault?= Newsgroups: gmane.text.pandoc Subject: Re: Pandoc Document Model in Python Date: Sat, 4 Dec 2021 06:43:42 -0800 (PST) Message-ID: References: <3b5d75fe4e2a45e38ab45a820d110faf@unibe.ch> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_1240_1426696528.1638629022778" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16382"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCIOBSUCXMMRBH75VWGQMGQEA6CKH6A-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Sat Dec 04 15:43:46 2021 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oi1-f186.google.com ([209.85.167.186]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mtWGQ-00046v-GW for gtp-pandoc-discuss@m.gmane-mx.org; Sat, 04 Dec 2021 15:43:46 +0100 Original-Received: by mail-oi1-f186.google.com with SMTP id y21-20020aca4b15000000b002a819a3cd6dsf4287625oia.15 for ; Sat, 04 Dec 2021 06:43:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:date:from:to:message-id:in-reply-to:references:subject :mime-version:x-original-sender:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:list-subscribe :list-unsubscribe; bh=O5HKrODdgnoj+CojuFv3Q96hx9isIFyDyhDGefjERco=; b=WkBEICSKe1oSOVP0LD9Hwz2yBXsp9eDnLRdQLhoKyH+J/9jXdOfC0NmTSuxIpRN+sa HMv+kuHijnEEez6xSh7X597y2ZUrpern4pXSS9//2YDvsCX9YPW+1DUbBmt2f7BAlvti ekofF4YfcCV1uSR/xcQ6JYEtgR+nwZTR0oTgZfI1XH3xYZKBnHVT2azlOSCyAaCxfr5T IW+TsLDhuSPPb4vEU+3nN8vwjOMc+3xxjXFxdIkXIOZNTRSe1JXIvbBkribDyLsWne7b jf+QncH51OC/hqnmQ/8sYbx2IoNvTICc9EJK/8jplU0b/3Ba3OJfz6HD9oCIG3NH8nYj euEA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:message-id:in-reply-to:references:subject:mime-version :x-original-sender:reply-to:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=O5HKrODdgnoj+CojuFv3Q96hx9isIFyDyhDGefjERco=; b=B45AkckH6T0jshyMBEW5277Xix9VO2fM5Pkv0OstSYUhqb4gKTfr3T2IOhzxLqmoFt gRweCUg14EboVt3dUPj8B7kBPjWJBw8YY1Y8f5xDwwSLa/C8ROgVRSG8ijIeiYj5r3c3 Xt2Ni10pUgldp06Ydo2p2n0c0Bc81v8KPs32KpXbsEiFQy08drrX6P1/UWk9K6udoxpd muy9qQCY7724OPZ5RFgRAxb+3rV5jmW1SWXv9qqjy5AgV0TIvauQfZ6naqwb3BHFDiWw L5LYnxeUjDtlsoycy9YAzc+ROjvwmuCsoSiCIlN/SnC3NOUsi8v1v6GeC68rY+sCuQlm 1SZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:date:from:to:message-id:in-reply-to :references:subject:mime-version:x-original-sender:reply-to :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=O5HKrODdgnoj+CojuFv3Q96hx9isIFyDyhDGefjERco=; b=nhPb2Se6aFhHaVUNR9lyov+k0j1CAoqVZ/uyYEPE+TMKjVpfN4SFgTbeh7z9gRdkeb 6XvtKFID0IBLnBH2ww2UKjkCI/QosZKG+qH0DEfWw0WB2UMLgp7FO0XitbTseWMG2SrC pPUx2m/c8NfjBQTVwY7tO24axPutA1aaWavz0tGMdbpejvTeJtPh1rQLKH7+2uBy5O8y VE27qYfN4omvJwe8xVYJo06rxLiU93fr0YhXIod/Mx/9E5jJ8QfwGHtcY94raFvWWHhX I7lXWXGlGgO/mh+tqKdwEycKWbiDzXs1VHtwiBQXAf0Hi32pjTl7zZ1hTar6nGmA0Dqh VYyQ== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM531mqL4fGh+Zkz2Yzhg4ZS2hlF6a99UGk4vFP2jd86CqBzvk5UU5 MuDufvyGY8By3FgKcDk2kH8= X-Google-Smtp-Source: ABdhPJyehuB/g+5nuDFglrTC3i/p3U//5PTZJ5n+FtABmH/MwtlDu0KBUy97EDbJfM7aH5zU+vmYNA== X-Received: by 2002:a05:6808:11c8:: with SMTP id p8mr15026984oiv.72.1638629024962; Sat, 04 Dec 2021 06:43:44 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a9d:457:: with SMTP id 81ls4258338otc.5.gmail; Sat, 04 Dec 2021 06:43:43 -0800 (PST) X-Received: by 2002:a9d:490c:: with SMTP id e12mr21546298otf.90.1638629023349; Sat, 04 Dec 2021 06:43:43 -0800 (PST) In-Reply-To: <3b5d75fe4e2a45e38ab45a820d110faf-NSENcxR/0n0@public.gmane.org> X-Original-Sender: Sebastien.Boisgerault-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.io gmane.text.pandoc:29669 Archived-At: ------=_Part_1240_1426696528.1638629022778 Content-Type: multipart/alternative; boundary="----=_Part_1241_1910515514.1638629022778" ------=_Part_1241_1910515514.1638629022778 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable (Ooops probably answered Denis only and not the group. Here we go again!) AFAICT filters are document AST to AST transformations. In this Python=20 library, docs (Pandoc instances) represent this AST, so a typical AST=20 (in-place) transform would be: import pandoc from pandoc.types import * def uppercase(doc):=20 for elt in pandoc.iter(doc): if isinstance(elt, Str): elt[0] =3D elt[0].upper() # elt: Str(Text) If you need to make a markdown to markdown transformation instead, you read= =20 the input markdown, transform it then write it back: >>> markdown =3D "Hello world!" >>> doc =3D pandoc.read(markdown) >>> uppercase(doc) >>> markdown =3D pandoc.write(doc) >>> print(markdown) HELLO WORLD! There are more examples here: https://boisgera.github.io/pandoc/examples/ and a documentation of common patterns here: https://boisgera.github.io/pandoc/cookbook/ Cheers,=20 S=C3=A9bastien Le samedi 4 d=C3=A9cembre 2021 =C3=A0 15:06:10 UTC+1, denis...-NSENcxR/0n0@public.gmane.org a = =C3=A9crit : > Hi Sebastian > Looks interesting. But I don't undertake how you'd use that as an=20 > alternative to a filter. Can you give an example? > Denis > > > > ________________________________________ > Von: pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org im Auftrag= =20 > von S=C3=A9bastien Boisg=C3=A9rault > Gesendet: Samstag, 4. Dezember 2021 14:20:03 > An: pandoc-discuss > Betreff: Pandoc Document Model in Python > > Hi everyone, > > I have just released the 2.0 version of a pandoc python library which=20 > exposes the Pandoc document model to Python : > > https://github.com/boisgera/pandoc#-overview > > The main goal is to enable all kinds of analysis, generation and=20 > transformation of documents with Python (roughly speaking, an alternative= =20 > to pandoc filters); it is not to convert from one format to another (it c= an=20 > do it, but so can the standard pandoc command-line tool). > > Feedback welcome ! > > Cheers, > > S=C3=A9bastien > > > > -- > You received this message because you are subscribed to the Google Groups= =20 > "pandoc-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an= =20 > email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. > To view this discussion on the web visit=20 > https://groups.google.com/d/msgid/pandoc-discuss/f224cd2c-7d68-40b4-a855-= 7d4d0d7aa442n%40googlegroups.com > < > https://groups.google.com/d/msgid/pandoc-discuss/f224cd2c-7d68-40b4-a855-= 7d4d0d7aa442n%40googlegroups.com?utm_medium=3Demail&utm_source=3Dfooter > >. > --=20 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 e= mail 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/de1fd005-0d0d-49a2-86cc-5a72c764835dn%40googlegroups.com. ------=_Part_1241_1910515514.1638629022778 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
(Ooops probably answered Denis only and not the group. Here we go agai= n!)

AFAICT filters are document AST to AST transfo= rmations. In this Python library, docs (Pandoc instances) represent this AS= T, so a typical AST (in-place) transform would be:

=
import pandoc
from pandoc.types import *

def uppercase(doc):
    for elt in pandoc.iter(doc):<= br>        if isinstance(elt, Str):
&= nbsp;           elt[0] = =3D elt[0].upper() # elt: Str(Text)

If you nee= d to make a markdown to markdown transformation instead, you read the input= markdown, transform it then write it back:

&g= t;>> markdown =3D "Hello world!"
>>> doc =3D p= andoc.read(markdown)
>>> uppercase(doc)
>>> = markdown =3D pandoc.write(doc)
>>> print(markdown)
HELLO WOR= LD!

There are more examples here:

    https://boisgera.github.io/pandoc/examples/
<= div>
and a documentation of common patterns here:
<= br>
    https://boisgera.github.io/pandoc/cookbook= /

Cheers,

S=C3= =A9bastien

Le samedi 4 d=C3=A9cembre 2021 =C3=A0 15:06:10 UT= C+1, denis...-NSENcxR/0n0@public.gmane.org a =C3=A9crit=C2=A0:
Hi Sebastian
Looks interesting. But I don't undertake how you'd use that as = an alternative to a filter. Can you give an example?
Denis



________________________________________
Von: pandoc-...@googlegroups= .com <pandoc-...@googlegr= oups.com> im Auftrag von S=C3=A9bastien Boisg=C3=A9rault <sebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Gesendet: Samstag, 4. Dezember 2021 14:20:03
An: pandoc-discuss
Betreff: Pandoc Document Model in Python

Hi everyone,

I have just released the 2.0 version of a pandoc python library which e= xposes the Pandoc document model to Python :

https://github.com/boisgera/pandoc#-overview

The main goal is to enable all kinds of analysis, generation and transf= ormation of documents with Python (roughly speaking, an alternative to pand= oc filters); it is not to convert from one format to another (it can do it,= but so can the standard pandoc command-line tool).

Feedback welcome !

Cheers,

S=C3=A9bastien



--
You received this message because you are subscribed to the Google Grou= ps "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send = an email to pandoc-discus...@goo= glegroups.com<mailto:pand= oc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/f224cd2c-7d= 68-40b4-a855-7d4d0d7aa442n%40googlegroups.com<https://groups.google.com/d/msgid/pandoc-di= scuss/f224cd2c-7d68-40b4-a855-7d4d0d7aa442n%40googlegroups.com?utm_medium= =3Demail&utm_source=3Dfooter>.

--
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 view this discussion on the web visit https://groups.google.com/d= /msgid/pandoc-discuss/de1fd005-0d0d-49a2-86cc-5a72c764835dn%40googlegroups.= com.
------=_Part_1241_1910515514.1638629022778-- ------=_Part_1240_1426696528.1638629022778--