From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/29274 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Julianus Pfeuffer Newsgroups: gmane.text.pandoc Subject: Re: ipynb output: Choose languages to convert to code cells Date: Tue, 21 Sep 2021 10:16:46 -0700 (PDT) Message-ID: References: Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_986_93173505.1632244606968" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36224"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBDEIXP5IZAIBBAFHVCFAMGQEFRKY2HY-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Tue Sep 21 19:16:50 2021 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oo1-f63.google.com ([209.85.161.63]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mSjNy-0009A3-9w for gtp-pandoc-discuss@m.gmane-mx.org; Tue, 21 Sep 2021 19:16:50 +0200 Original-Received: by mail-oo1-f63.google.com with SMTP id f2-20020a4a2202000000b0028c8a8074desf46542326ooa.20 for ; Tue, 21 Sep 2021 10:16:50 -0700 (PDT) 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=C/fQO0vaKsDWvZzJWJ/V4SVWuabC8beVAjrOC2nJ/CQ=; b=WKtqqFUcljGXrq2ntNq+4gJJKHrB1jaEkKMTGZxS+71rORqW6v9t7xSxDLcLrqFTNt mvhZmTScEJmXP+Qgj0xBGgc6cj2AzJZp4pzmd10JEdu/n5YZK0Oec5VXCSxTxSFtJ4qM C7wDzGAD4bA69cpwkFJdnBtUDLnEAO4F1XfFz+tSvr0Y/HQOqqToTd2pLJzZFleTCJDo QZH6QtmX4JxpU4a5TBXGNR1LsXy9qaqrc7xYuCfYCGGUePt6UlGMlOMDXDL/CrsIz0X8 2swqVMjvQCqmNxTVvviVdPg0Lf42TQCnK+yP4re+UTKlVmn6lxn2A9rvMD6gADIjg/dK rOag== 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=C/fQO0vaKsDWvZzJWJ/V4SVWuabC8beVAjrOC2nJ/CQ=; b=TZjPaYObeoqXnxv4A0ChoxDLAdXJwXBFsTdFebPjL6z2323g29cEMRi/sGPJO4EAz7 Ev9vFYmLHuRVk7xpYsWGUWZKz81gDOy762XKQWdmZ9NLHlEqJ20/JLqRnqH4vB5gjeHh FLMoi3GWueUsA8K2mC7EMTSF1jlr7q5mD2BU2ii+S9eMtrQEPVoMP0S+3TD35eG3/aLM DBlbDxFKrYwXg4+KCLTUicwCW7hkV4RZFQ/DfLCr8pznXBjLJ1YoGgxdGgeQeaUlbQWF htchDn1aV6QCYHjsbXfyXsZt6c9KY1/Rkotl1zUagj1CbIXsdGk211i2Z+tI9TymqOEq p1hg== 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=C/fQO0vaKsDWvZzJWJ/V4SVWuabC8beVAjrOC2nJ/CQ=; b=oUTE7jx9xEHw+bLlWWV6uvA11weePeOYEqwB+Z6p1hZ7P2Or/RJqo2/i+/pJ3NhMMy PZ/ZEfBpRSefFc7MIW3eSkccyKJc12ozdUEvGKUS/EDzeYUeXLsda5q4JnPUctp1sQaz dGDjEQjRMiclg1k0wmAs8qMNa9LNRR3cY45xZEka+O5Dce32PKn3wT8gNcHM7+iiKz/K 0fPzeLXFuJ4yGBFGQnN12UTwKDD/sh4FKBfWXry3HMT3Z19bokhYTl75YFld6vHV87Ey CES9EuQJn46q2L6HV8uYv1SXh+51Pt+gnGEapuQ6hM+ovfeUrUh5mFe+kYt3zU6q0/hm KZKA== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM532Ao2Eygpgr/nR0r8l0avAJLCXHcag8BjpdjQZZlOAY2uEYztKT PT+0OaKgEtghZ5qr9cSMlLk= X-Google-Smtp-Source: ABdhPJzwHwD1lntWo426he5B8CYeP5CraH2rAiaDEMS5+BNJbH/mcHIBUwrt4LZJumWipBR/JBKqNw== X-Received: by 2002:a54:4688:: with SMTP id k8mr4718029oic.70.1632244609167; Tue, 21 Sep 2021 10:16:49 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6808:114:: with SMTP id b20ls1383420oie.10.gmail; Tue, 21 Sep 2021 10:16:47 -0700 (PDT) X-Received: by 2002:a05:6808:1823:: with SMTP id bh35mr1063867oib.53.1632244607518; Tue, 21 Sep 2021 10:16:47 -0700 (PDT) In-Reply-To: X-Original-Sender: jule.pf-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:29274 Archived-At: ------=_Part_986_93173505.1632244606968 Content-Type: multipart/alternative; boundary="----=_Part_987_267544223.1632244606968" ------=_Part_987_267544223.1632244606968 Content-Type: text/plain; charset="UTF-8" Thanks for the quick hint. I had to lookup how to apply filters but it was rather straightforward (only a bit hard to infer the structure of the python objects from the Haskell data type documentation). In case someone is interested, the following hacky filter worked at first glance. #!/usr/local/bin/python3 """ Pandoc filter to convert code blocks of certain language classes to code class """ from pandocfilters import * def addCodeClass(key, value, format, meta): if key == 'CodeBlock': [[ident, classes, keyvals], code] = value if "python" in classes: classes.remove("python") classes.append("code") return CodeBlock([ident, classes, keyvals], code) if __name__ == "__main__": toJSONFilter(addCodeClass) John MacFarlane schrieb am Dienstag, 21. September 2021 um 18:04:16 UTC+2: > > You could use a filter to add the "code" class to, say, > all code blocks with the "python" class. > > Julianus Pfeuffer writes: > > > Hi all, > > > > does anyone know of a way, how to decide which code language to convert > to > > an ipynb code cell? > > The default is "code" but of course no one would just use "code" as a > > language description in input formats that are not specifically written > for > > this pandoc conversion to ipynb. > > > > I am envisioning to be able to specify e.g. python, R as languages of my > > input code blocks (as long as the input format supports a language tag, > > e.g. Markdown or rst) which should be converted to executable code cells > in > > the notebook. > > > > Is this possible? > > > > Thanks and cheers > > Julianus > > > > -- > > 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-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To view this discussion on the web visit > https://groups.google.com/d/msgid/pandoc-discuss/e539846c-74da-4636-82ea-f63cfcf8ee0bn%40googlegroups.com > . > -- 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/d0820aab-e573-4d91-a97e-1716beff5630n%40googlegroups.com. ------=_Part_987_267544223.1632244606968 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks for the quick hint. I had to lookup how to apply filters but it was = rather straightforward (only a bit hard to infer the structure of the pytho= n objects from the Haskell data type documentation).
In case someone is= interested, the following hacky filter worked at first glance.

#!/usr/local/bin/python3

"""
Pandoc fil= ter to convert code blocks of certain language classes to code class=
"""

from pandocfilt= ers import *

<= div>def addCodeClass(key, value, format, meta):<= /font>
  if key =3D=3D 'CodeBlock= ':
    [[ident, class= es, keyvals], code] =3D value
&= nbsp;   if "python" in classes:
      classes.remove("python")
      classes.append("code")
    return CodeBlock([ident, cl= asses, keyvals], code)

if __name__ =3D=3D "__main__":
  toJSONFilter(addCodeClass)<= /font>

John MacFarlane schrieb am Dienstag, 21. September= 2021 um 18:04:16 UTC+2:

You could use a filter to add the "code" class to, say,
all code blocks with the "python" class.

Julianus Pfeuffer <jul...= @gmail.com> writes:

> Hi all,
>
> does anyone know of a way, how to decide which code language to co= nvert to=20
> an ipynb code cell?
> The default is "code" but of course no one would just us= e "code" as a=20
> language description in input formats that are not specifically wr= itten for=20
> this pandoc conversion to ipynb.
>
> I am envisioning to be able to specify e.g. python, R as languages= of my=20
> input code blocks (as long as the input format supports a language= tag,=20
> e.g. Markdown or rst) which should be converted to executable code= cells in=20
> the notebook.
>
> Is this possible?
>
> Thanks and cheers
> Julianus
>
> --=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 email to pandoc-discus..= .@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/e539= 846c-74da-4636-82ea-f63cfcf8ee0bn%40googlegroups.com.

--
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/d0820aab-e573-4d91-a97e-1716beff5630n%40googlegroups.= com.
------=_Part_987_267544223.1632244606968-- ------=_Part_986_93173505.1632244606968--