From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/29097 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Cl=C3=A9ment_Aubert?= Newsgroups: gmane.text.pandoc Subject: Re: Passing multiple options to lua-filter from CLI Date: Fri, 20 Aug 2021 14:19:37 -0400 Message-ID: References: Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000068d18b05ca01b736" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36944"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBCM37TODUUORBVXE76EAMGQEEXXA7IY-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Fri Aug 20 20:20:10 2021 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-ua1-f58.google.com ([209.85.222.58]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mH97g-0009G6-R6 for gtp-pandoc-discuss@m.gmane-mx.org; Fri, 20 Aug 2021 20:20:09 +0200 Original-Received: by mail-ua1-f58.google.com with SMTP id q17-20020ab067110000b02902ab3c0123c1sf2549267uam.8 for ; Fri, 20 Aug 2021 11:20:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1629483607; cv=pass; d=google.com; s=arc-20160816; b=aYzWXEobzIMM5xs9dVMwC2yaocaJCaw4a07PNwj2QWNRFR+iYsugjaR+MflraiQG4G BCQa747AY18J2M2icIQDobJ4gC28tCrMG9K+6rjnipaO6BqyLTE9j4ML++Gx5Ulw9PV1 XTmQ9+J15oY8gwbZNgy3bLWaC/qUY1TFRShz0cnmMnUzLexsSWmyI3wFO3mRif9Z2Dgm Lyw8+j6++yQ9u3UHBUV88L+sOs0TRqCxGyQJtinYpPIAtGMIXwPZgTd+43H4nDBDYTVe pNx4UCZRiy/vlh1A4DmS4QM2cL3KLoPk9fWIsZr03UF8ad3Ry3rx5ZVWsgcjfdIAAmT7 N3Ew== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:to:subject:message-id:date :from:in-reply-to:references:mime-version:sender:dkim-signature :dkim-signature; bh=hI+6T2xxmFYzaUD9FE4Xl+BjQqz1BvTp+XcOJm6dIEU=; b=HQqR7X0cyblfr2zGQGgV8Jp4xHN5wF+pHXLDN7lELFTCEpcajxcNzUBbDhslAIZjBQ McipkJHAuyCXTnkBwFw5bH3+6/s2YGCNqpcIu7nlcGiUt3yJkh223k0Icwi8iJq+nrZl ac3yJldUtMiYzx9jJY9MYoxNzq9TOskS7IfXqebdmxovGzyVz0vTRxTtz23vr2CQCv0q 2L/G8pfkAYQ8lyruWFBMiCHUNViSTQngR4IgEAlbGUS2lJTGd5kLzQtPB8NSlEbUrMrD ukMlAPYv2MVnQ3DyrSw0DPgPsTwoQxMnouUq9HJ1GY4kEVnX2JQuJDRwDbCb8flVNwPg gLqQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="MsnqH/RY"; spf=pass (google.com: domain of aubert.clement-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2607:f8b0:4864:20::636 as permitted sender) smtp.mailfrom=aubert.clement-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:mime-version:references:in-reply-to:from:date:message-id :subject:to:x-original-sender:x-original-authentication-results :reply-to:precedence:mailing-list:list-id:list-post:list-help :list-archive:list-subscribe:list-unsubscribe; bh=hI+6T2xxmFYzaUD9FE4Xl+BjQqz1BvTp+XcOJm6dIEU=; b=pIPdXkwsuKRZiKewveXT6lC1F1QKsKWZCzzk7dsUPaAJtAur1A5NUynz8AGGIdAXZd nnmt+pB87rtF6pvZdJC3LrlECwRdbAhvQ2xwgpWj6NrwBVsSuO2c8ceWXkgPiAxBLVlp iBFxX4bL1LFm634wYlknEorXVZksxpJRZO/l49nsVQlufDR3dInT7xNfqiuZeSNMh+wu Hy0AvKkfcLrlVUC8jXL0FeEygFfOujk/3xiI9W3Ul/lje4BFDJ6ZuV065OKCwKyDSJWy hjC7JWL1xEATZkPSd2uNy+I1CWKqsDKb2BZg+TrjgHHCYXot8INFaCTLoioXnQE5hVls PRJA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :x-original-sender:x-original-authentication-results:reply-to :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=hI+6T2xxmFYzaUD9FE4Xl+BjQqz1BvTp+XcOJm6dIEU=; b=hkHh4y+U9Wy9coRtaHV/v2V11TeHX129U4bR27BZgMbql1VMrVabXGnpGCKJUO/mqe 0fcpfIOoqzB+0rRWT82PulFG1avPBZR4QbGClwHEvUTKYK2KKt8PSoM1cONTW9Q8alic 1MYEu1J7XXZPj9TmcqiZCQTZpO1HQ9slUDV+ITRl9rMdNZDuzyIV9nE0zXLwSI0Y8beS clEKGJBX8EgOJs0HMDFp2ST88D5+QJZLMiO7VSWBpDZSzEdiq99OKal1riYPdofP/dYb 461sJpX9v+7idV/2TENYVEYfl/d++s0cXnrgLzxcW/kjutX+Y15wvsgAg4wEL87NOq9C hBgA== 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:references:in-reply-to: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=hI+6T2xxmFYzaUD9FE4Xl+BjQqz1BvTp+XcOJm6dIEU=; b=RCaUEmgHJln2ImdXZcWSPqrZrDX37bOSvIxHhP+/SuQvwhX+aDoF0bj2w/UOGpmR/V LdL8EjG0ikkmk7uRCB/aS83/KHOTGVg2heUghc4F/UBmP2XPRFV1F1zztS/ojJgV9x+1 XI+CLKqR5tHj8USKdeP/wpfQj2qwQrJ2pwyCb8AgG2DiQABPJMof4xCcDvx3QjNPFqc1 y7E+4YOpgKlAePIpZeU3KOgxLJSyZ/VL1MkyuG1B4PCOXH+spCZEHMpkbtWJZ3p4K3tG oXOEGddW26Ul8pBt9286t2auT7vS3j/gLSC2/G2m6cNqqVHgroDwPB4UdmcvtvAjAvJq KNyg== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM533xhCxdOcE8FtcNGt0Z72SxjFOnl3srRL3XjBr9Eu/VIq24edXF Z8cJhQtJzF6HNDTCnazjhjs= X-Google-Smtp-Source: ABdhPJwA8FFcg8D0t/268qz2vEjwGvyiIBgoNfwvg7IGPYm3sjFu4K9oD7fvq6vSAgobhjVG0Qag9Q== X-Received: by 2002:a1f:a906:: with SMTP id s6mr16688230vke.14.1629483607824; Fri, 20 Aug 2021 11:20:07 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a67:7c84:: with SMTP id x126ls1846863vsc.3.gmail; Fri, 20 Aug 2021 11:20:05 -0700 (PDT) X-Received: by 2002:a05:6102:a1a:: with SMTP id t26mr18374911vsa.46.1629483605818; Fri, 20 Aug 2021 11:20:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629483605; cv=none; d=google.com; s=arc-20160816; b=SdJC/r49CLwNaCKi6mMpCiG1r9/XoAeQ+5KROUPEJhYFmnjXjiDoNTCT84jytea/rm /OYmZkQEcnktTJW8JYFYe4DmLEzol4VI0IQX5UoRYmhQpgtMS44piL30Iv8gTvp1T7MY 2MlglYITh7/XK3U5Y8QuKdFFiJgvfVG+EluiDSwbKVGyXFUDyvICOx+5L/UAoK7IQm9L iCNGRoa1syeijlRusjcjesVtseq9bM/1SKEOUs4+tN23mB59j+XaRW8iBRTvupsV9Iee tzMATMDbwUR1xt2+BcgC8QsfqJOOW1An/w9HbwGimt4ZNHu1FSokK94C37HeLXf8jP7r 2jVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=rz1T83K8lKNQtOaWSIrFek8N19X8hxjyccbf97DQb3k=; b=Mv0tJ3MuGmyAXmtTJ9YIBvD4OhYM5TPBjnzn7sruCC1ANN3wJ571PjTYFtxFRaPm11 b7vUP5U0lTMs+rVZ8YrXxvu6EDSeNTrB2TKmaTuS639swdHRK1xTSO7ZAo0Incn5F1RE AfyjwiJxUJbBYHdHnzfF57KqaVvjzsMB+fsXwfdvsLtqScny4nRTAqrmjfr6olT621sF OFzEJbUifWw6gRer47lRurcNEba11ossldGCEMz0rWr+OKCCIpSQW8f4uMHUR7NWyPrw VnZukxoR97uojTHVULhA39CIkJiSisw6jBnvM1Kh3bjVWl2IF/vAQk5kxPFNrE8NF0LU 1uLA== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="MsnqH/RY"; spf=pass (google.com: domain of aubert.clement-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2607:f8b0:4864:20::636 as permitted sender) smtp.mailfrom=aubert.clement-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Original-Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com. [2607:f8b0:4864:20::636]) by gmr-mx.google.com with ESMTPS id z25si491287uae.0.2021.08.20.11.20.05 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 20 Aug 2021 11:20:05 -0700 (PDT) Received-SPF: pass (google.com: domain of aubert.clement-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2607:f8b0:4864:20::636 as permitted sender) client-ip=2607:f8b0:4864:20::636; Original-Received: by mail-pl1-x636.google.com with SMTP id l11so6425644plk.6 for ; Fri, 20 Aug 2021 11:20:05 -0700 (PDT) X-Received: by 2002:a17:902:ac90:b029:12d:5098:43a5 with SMTP id h16-20020a170902ac90b029012d509843a5mr17607932plr.19.1629483604427; Fri, 20 Aug 2021 11:20:04 -0700 (PDT) In-Reply-To: X-Original-Sender: aubert.clement-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="MsnqH/RY"; spf=pass (google.com: domain of aubert.clement-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2607:f8b0:4864:20::636 as permitted sender) smtp.mailfrom=aubert.clement-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE 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.io gmane.text.pandoc:29097 Archived-At: --00000000000068d18b05ca01b736 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I'm sorry, the issue is on my end. It works perfectly on your small example, but not on my bigger document that involves multiple other options, make file and the like. I'll investigate, but you definitely answered my question, thanks a lot! Cl=C3=A9ment. Le ven. 20 ao=C3=BBt 2021 =C3=A0 13:21, William Lupton a =C3=A9crit : > You can't use my utils because I didn't supply it! I suggested using > inspect (https://github.com/kikito/inspect.lua) to get something similar. > Sorry... I was just using my utils to illustrate the AST. > > Anyway, please can you run this in your local environment and report what > you see? If you don't see the same as me then I don't know what to sugges= t! > > Filter (this has changed a little bit but not substantively): > > *% *cat default-code-class.lua > > local use_utils =3D false > > local utils =3D nil > > > if use_utils then > > utils =3D require 'utils' > > end > > > local default_code_classes =3D {} > > > local function get_default_code_class(meta) > > if utils then > > utils.temp('meta', meta) > > end > > if meta['default-code-class'] then > > default_code_classes =3D > > {pandoc.utils.stringify(meta['default-code-class'])} > > end > > end > > > local function add_default_code_class(el) > > if utils then > > utils.temp(el) > > end > > if #(el.classes) =3D=3D 0 then > > el.classes =3D default_code_classes > > return el > > end > > end > > > return {{Meta=3Dget_default_code_class}, > > {Code=3Dadd_default_code_class, CodeBlock=3Dadd_default_code_clas= s}} > > Markdown: > > *% *cat code.md > > This is `inline code`. > > > ``` > > This is a code block. > > ``` > > Invocation: > > *% *pandoc -L default-code-class.lua code.md -M default-code-class=3D"c > numberLines" > >

This is inline code.

> >
This is a code block.
> > On Fri, 20 Aug 2021 at 18:03, Cl=C3=A9ment Aubert > wrote: > >> Thanks! >> >> pandoc -v >> pandoc 2.14.1 >> Compiled with pandoc-types 1.22, texmath 0.12.3, skylighting 0.11, >> citeproc 0.4.1, ipynb 0.1.0.1 >> User data directory: /home/caubert/.local/share/pandoc >> >> with the first line (about utils), I now get >> >> Error running filter templates/filters/default-code-class.lua: >> templates/filters/default-code-class.lua:1: module 'utils' not found: >> utilsis not one of pandoc's default packages >> no field package.preload['utils'] >> no file '/usr/local/share/lua/5.3/utils.lua' >> no file '/usr/local/share/lua/5.3/utils/init.lua' >> no file '/usr/local/lib/lua/5.3/utils.lua' >> no file '/usr/local/lib/lua/5.3/utils/init.lua' >> no file './utils.lua' >> no file './utils/init.lua' >> no file '/usr/local/lib/lua/5.3/utils.so' >> no file '/usr/local/lib/lua/5.3/loadall.so' >> no file './utils.so' >> stack traceback: >> [C]: in function 'require' >> templates/filters/default-code-class.lua:1: in main chunk >> make: *** [Makefile:281: build/labs/If/index.html] Error 83 >> >> without it, I get >> >> Error running filter templates/filters/default-code-class.lua: >> templates/filters/default-code-class.lua:7: attempt to index a nil value >> (global 'utils') >> stack traceback: >> templates/filters/default-code-class.lua:7: in function >> 'get_default_code_class' >> make: *** [Makefile:281: build/labs/If/index.html] Error 83 >> >> >> >> >> >> Le ven. 20 ao=C3=BBt 2021 =C3=A0 12:26, William Lupton >> a =C3=A9crit : >> >>> Inline... >>> >>> On Fri, 20 Aug 2021 at 17:06, Cl=C3=A9ment Aubert >>> wrote: >>> >>>> Thanks a lot for looking into it! >>>> It does not seem to produce the desired effect on my end. >>>> >>>> Could you explain how changing >>>> return {{Meta =3D get_default_code_class}, >>>> {Code =3D add_default_code_class}, >>>> {CodeBlock =3D add_default_code_class}} >>>> into >>>> return {{Meta=3Dget_default_code_class}, >>>> {CodeBlock=3Dadd_default_code_class}} >>>> (as far as I can tell, this is the only modification) is supposed to >>>> achieve the desired effect? >>>> >>> >>> Ah, well I don't think that you included this in your original message, >>> so I thought that was the problem :). >>> >>> return {{Meta =3D get_default_code_class}, >>> {Code =3D add_default_code_class}, >>> {CodeBlock =3D add_default_code_class}} >>> >>> You are correct: the only difference is that you have Code. You could >>> combine Code and CodeBlock into a single pass, as in: >>> >>> return {{Meta=3Dget_default_code_class}, >>> {Code=3Dadd_default_code_class, CodeBlock=3Dadd_default_code_cl= ass}} >>> >>> But it _does_ work for me! Maybe add some debug output? Here I'm using >>> my own inspect-like function but the standard inspect would probably be >>> similar. >>> >>> Pandoc version? I'm using 2.14.1. >>> >>> *% *cat default-code-class.lua >>> >>> utils =3D require 'utils' >>> >>> >>> local default_code_classes =3D {} >>> >>> >>> function get_default_code_class(meta) >>> >>> utils.temp('meta', meta) >>> >>> if meta['default-code-class'] then >>> >>> default_code_classes =3D >>> {pandoc.utils.stringify(meta['default-code-class'])} >>> >>> end >>> >>> end >>> >>> >>> function add_default_code_class(el) >>> >>> utils.temp(el.tag, el) >>> >>> if #(el.classes) =3D=3D 0 then >>> >>> el.classes =3D default_code_classes >>> >>> return el >>> >>> end >>> >>> end >>> >>> >>> return {{Meta=3Dget_default_code_class}, >>> >>> {Code=3Dadd_default_code_class, CodeBlock=3Dadd_default_code_cl= ass}} >>> >>> >>> *% *LUA_PATH=3D../?.lua pandoc -L default-code-class.lua code.md -M >>> default-code-class=3D"c numberLines" >>> >>> (#) meta {default-code-class: "c numberLines"} >>> >>> (#) Code Code { >>> >>> attr: Attr { >>> >>> attributes: {} >>> >>> classes: {} >>> >>> identifier: "" >>> >>> } >>> >>> text: "inline code" >>> >>> } >>> >>> (#) CodeBlock CodeBlock { >>> >>> attr: Attr { >>> >>> attributes: {} >>> >>> classes: {} >>> >>> identifier: "" >>> >>> } >>> >>> text: "This is a code block." >>> >>> } >>> >>>

This is inline code.

>>> >>>
This is a code block.
>>> >>> Thanks! >>>> >>>> Le ven. 20 ao=C3=BBt 2021 =C3=A0 11:57, William Lupton < >>>> wlupton-QSt+ys/nuMyEUIsrzH9SikB+6BGkLq7r@public.gmane.org> a =C3=A9crit : >>>> >>>>> I think you need a two-pass filter, one to pick up the metadata and >>>>> the other to use it (this is because Meta is called nearly last). >>>>> >>>>> This works (I've re-ordered your functions and declared a local >>>>> variable, but this probably wasn't necessary). >>>>> >>>>> *% *cat default-code-class.lua >>>>> >>>>> local default_code_classes =3D {} >>>>> >>>>> >>>>> function get_default_code_class(meta) >>>>> >>>>> if meta['default-code-class'] then >>>>> >>>>> default_code_classes =3D >>>>> {pandoc.utils.stringify(meta['default-code-class'])} >>>>> >>>>> end >>>>> >>>>> end >>>>> >>>>> >>>>> function add_default_code_class(el) >>>>> >>>>> if #(el.classes) =3D=3D 0 then >>>>> >>>>> el.classes =3D default_code_classes >>>>> >>>>> return el >>>>> >>>>> end >>>>> >>>>> end >>>>> >>>>> >>>>> return {{Meta=3Dget_default_code_class}, >>>>> {CodeBlock=3Dadd_default_code_class}} >>>>> >>>>> >>>>> *% *pandoc -L default-code-class.lua code.md -M default-code-class=3D= "c >>>>> numberLines" >>>>> >>>>>
>>>>> >>>>> On Fri, 20 Aug 2021 at 16:29, Cl=C3=A9ment Aubert >>>>> wrote: >>>>> >>>>>> Hi, >>>>>> >>>>>> This question relates to >>>>>> https://github.com/jgm/pandoc/issues/2104#issuecomment-595983954 >>>>>> There is a lua filter containing >>>>>> >>>>>> ``` lua >>>>>> function add_default_code_class(el) >>>>>> if #(el.classes) =3D=3D 0 then >>>>>> el.classes =3D default_code_classes >>>>>> return el >>>>>> end >>>>>> end >>>>>> >>>>>> function get_default_code_class(meta) >>>>>> if meta['default-code-class'] then >>>>>> default_code_classes =3D >>>>>> {pandoc.utils.stringify(meta['default-code-class'])} >>>>>> end >>>>>> end >>>>>> ``` >>>>>> >>>>>> and I'm trying to tweak it so that two classes can be passed from th= e >>>>>> command-line, eg. using >>>>>> >>>>>> --lua-filter default-code-class.lua -M default-code-class=3Dc, >>>>>> numberLines >>>>>> >>>>>> but can't find a way. >>>>>> >>>>>> Thanks! >>>>>> Cl=C3=A9ment. >>>>>> >>>>>> -- >>>>>> 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/c025fcc7-ff39-4993-= 97f0-3dc8a7107724n%40googlegroups.com >>>>>> >>>>>> . >>>>>> >>>>> -- >>>>> You received this message because you are subscribed to a topic in th= e >>>>> Google Groups "pandoc-discuss" group. >>>>> To unsubscribe from this topic, visit >>>>> https://groups.google.com/d/topic/pandoc-discuss/NrRuAcm1otQ/unsubscr= ibe >>>>> . >>>>> To unsubscribe from this group and all its topics, 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/CAEe_xxgqyK6%2BT3kmb= 7sNUckEJrS81cwm05iCvauKOA0Z3doRcg%40mail.gmail.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/CAPGHSezmvUZSEApp0fGC= ezjUNcqSJJCMBaLGTaPUc86tSoUS0A%40mail.gmail.com >>>> >>>> . >>>> >>> -- >>> You received this message because you are subscribed to a topic in the >>> Google Groups "pandoc-discuss" group. >>> To unsubscribe from this topic, visit >>> https://groups.google.com/d/topic/pandoc-discuss/NrRuAcm1otQ/unsubscrib= e >>> . >>> To unsubscribe from this group and all its topics, 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/CAEe_xxgDzL%2BQjar4bGf= UndO7Pq-RimWPmN5tzYSV3B6BUh0Nrg%40mail.gmail.com >>> >>> . >>> >> -- >> You received this message because you are subscribed to the Google Group= s >> "pandoc-discuss" group. >> To unsubscribe from this group and stop receiving emails from it, send a= n >> 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/CAPGHSewt%3DnK73AHRJ4C6= yMs_rdRkcXAiJXeY0MEYo1pAxX4ugQ%40mail.gmail.com >> >> . >> > -- > You received this message because you are subscribed to a topic in the > Google Groups "pandoc-discuss" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/pandoc-discuss/NrRuAcm1otQ/unsubscribe. > To unsubscribe from this group and all its topics, 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/CAEe_xxjF_GT3XXobnhGizje= _U6VDcODV0ubGR0dDN%3DDj_U2B3A%40mail.gmail.com > > . > --=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/CAPGHSexHuj0T1n%2B-rOFjnVe5ZLw5Y_iqQEsn1yjECZSdy3e9QQ%40mail= .gmail.com. --00000000000068d18b05ca01b736 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I'm sorry, the issue is on my end.
It w= orks perfectly on your small example, but not on my bigger document that in= volves multiple other options, make file and the like.

=
I'll investigate, but you definitely answered my question, thanks = a lot!
Cl=C3=A9ment.

Le=C2=A0ven. 20 ao=C3=BBt 2021 =C3= =A0=C2=A013:21, William Lupton <wlupton-QSt+ys/nuMyEUIsrzH9SikB+6BGkLq7r@public.gmane.org> a =C3=A9crit=C2=A0:
You can't use my utils because I didn't supply=C2=A0it! I sug= gested using inspect (https://github.com/kikito/inspect.lua) to get something = similar. Sorry... I was just using my utils to illustrate the AST.

Anyway, please can you run this in your local = environment and report what you see? If you don't see the same as me th= en I don't know what to suggest!

Filter (this = has changed a little bit but not substantively):

% = cat defau= lt-code-class.lua

local use_utils =3D false

local utils =3D nil


if use_utils then

=C2=A0 =C2=A0 uti= ls =3D require 'utils'

end


local default_code_classes =3D= {}


local function get_default_cod= e_class(meta)

=C2=A0 if utils t= hen

=C2=A0 =C2=A0 =C2=A0 utils.temp('meta', meta)

=C2=A0 end=

=C2=A0 if meta[&#= 39;default-code-class'] then

=C2=A0 =C2=A0 =C2=A0 default_code_classes =3D

=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 {pandoc.utils.stringify(meta['default-code-class'= ])}

=C2=A0 end=

end


local function add_default_cod= e_class(el)

=C2=A0 =C2=A0 if = utils then

=C2=A0 =C2=A0 =C2=A0 =C2= =A0 utils.temp(el)

=C2=A0 =C2=A0 end=

=C2=A0 =C2=A0 if = #(el.classes) =3D=3D 0 then

=C2=A0 =C2=A0 =C2=A0 =C2= =A0 el.classes =3D default_code_classes

=C2=A0 =C2=A0 =C2=A0 =C2= =A0 return el

=C2=A0 =C2=A0 end=

end


return {{Meta=3Dget_default_co= de_class},

=C2=A0 =C2=A0 =C2=A0 =C2= =A0 {Code=3Dadd_default_code_class, CodeBlock=3Dadd_default_code_cla= ss}}


Markdown:

% = cat code.= md=C2=A0

This is `inline code`.<= /p>


```

This is a code block.

```


<= /div>
Invocation:

% = pandoc -L= default-code-class.lua code.md -M default-code-class=3D"c numberLines= "

<p>This is <code clas= s=3D"c numberLines">inline code</code>.</p>=

<pre class=3D"c number= Lines"><code>This is a code block.</code></pre>


On Fri, 20 Aug 2021 at 18:03, Cl=C3=A9ment Aubert <aubert.clement-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org<= /a>> wrote:
<= div dir=3D"ltr">
Thanks!

pandoc -v
pandoc 2= .14.1
Compiled with pandoc-types 1.22, texmath 0.12.3, skylighting 0.11,=
citeproc 0.4.1, ipynb 0.1.0.1
User data directory: /home/caubert/.lo= cal/share/pandoc

with the first line (about ut= ils), I now get

Error running filter templates/fil= ters/default-code-class.lua:
templates/filters/default-code-class.lua:1:= module 'utils' not found:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 utilsis n= ot one of pandoc's default packages
=C2=A0 =C2=A0 =C2=A0 =C2=A0 no f= ield package.preload['utils']
=C2=A0 =C2=A0 =C2=A0 =C2=A0 no fil= e '/usr/local/share/lua/5.3/utils.lua'
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 no file '/usr/local/share/lua/5.3/utils/init.lua'
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 no file '/usr/local/lib/lua/5.3/utils.lua'
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 no file '/usr/local/lib/lua/5.3/utils/init.lua= '
=C2=A0 =C2=A0 =C2=A0 =C2=A0 no file './utils.lua'
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 no file './utils/init.lua'
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 no file '/usr/local/lib/lua/5.3/utils.so'
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 no file '/usr/local/lib/lua/5.3/loadall.so'= ;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 no file './utils.so'
stack trac= eback:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 [C]: in function 'require'=C2=A0 =C2=A0 =C2=A0 =C2=A0 templates/filters/default-code-class.lua:1: in= main chunk
make: *** [Makefile:281: build/labs/If/index.html] Error 83<= /div>

without it, I get

Error r= unning filter templates/filters/default-code-class.lua:
templates/filter= s/default-code-class.lua:7: attempt to index a nil value (global 'utils= ')
stack traceback:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 templates/filters= /default-code-class.lua:7: in function 'get_default_code_class'
= make: *** [Makefile:281: build/labs/If/index.html] Error 83

<= /div>




<= div dir=3D"ltr">
Inline...

On Fri, 20 Aug 2021 at 17:06, Cl=C3=A9ment Au= bert <aube= rt.clement-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
Thanks a lot for looking into it!=
It does not seem to produce the desired effect on my end.
<= div>
Could you explain how changing
return {{Meta = =3D get_default_code_class},
=C2=A0 =C2=A0 =C2=A0 =C2=A0 {Code =3D add_d= efault_code_class},
=C2=A0 =C2=A0 =C2=A0 =C2=A0 {CodeBlock =3D add_defau= lt_code_class}}
into
return {{Meta=3Dget_default_c= ode_class}, {CodeBlock=3Dadd_default_code_class}}
(as far as I ca= n tell, this is the only modification) is supposed to achieve the desired e= ffect?

Ah, well I don't thi= nk that you included this in your original message, so I thought that was t= he problem :).

return {{Meta =3D get_default_code_= class},
=C2=A0 =C2=A0 =C2=A0 =C2=A0 {Code =3D add_default_code_class},=C2=A0 =C2=A0 =C2=A0 =C2=A0 {CodeBlock =3D add_default_code_class}}

You are correct: the only difference is that you ha= ve Code. You could combine Code and CodeBlock into a single pass, as in:

return {{Meta=3Dget_default_code_class},
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 {Code=3Dadd_default_code_class, CodeBlock=3Dadd_defaul= t_code_class}}

But it _does_ work for me! Mayb= e add some debug output? Here I'm using my own inspect-like function bu= t the standard inspect would probably be similar.

= Pandoc version? I'm using 2.14.1.

% = cat defau= lt-code-class.lua=C2=A0

utils =3D require 'utils&#= 39;


local default_code_classes =3D= {}


function get_default_code_clas= s(meta)

=C2=A0 utils.temp= ('meta', meta)

=C2=A0 if meta[&#= 39;default-code-class'] then

=C2=A0 =C2=A0 def= ault_code_classes =3D {pandoc.utils.stringify(meta['default-code-class&= #39;])}

=C2=A0 end=

end


function add_default_code_clas= s(el)

=C2=A0 utils.temp= (el.tag, el)

=C2=A0 if #(el.cl= asses) =3D=3D 0 then

=C2=A0 =C2=A0 el.= classes =3D default_code_classes

=C2=A0 =C2=A0 ret= urn el

=C2=A0 end=

end


return {{Meta=3Dget_default_co= de_class},

=C2=A0 =C2=A0 =C2=A0 =C2= =A0 {Code=3Dadd_default_code_class, CodeBlock=3Dadd_default_code_cla= ss}}


% = LUA_PATH= =3D../?.lua pandoc -L default-code-class.lua code.md -M default-code-class= =3D"c numberLines"

(#) meta {default-code-class: = "c numberLines"}

(#) Code Code {

=C2=A0 attr: Attr= {

=C2=A0 =C2=A0 att= ributes: {}

=C2=A0 =C2=A0 cla= sses: {}

=C2=A0 =C2=A0 ide= ntifier: ""

=C2=A0 }

=C2=A0 text: &quo= t;inline code"

}

(#) CodeBlock CodeBlock {

=C2=A0 attr: Attr= {

=C2=A0 =C2=A0 att= ributes: {}

=C2=A0 =C2=A0 cla= sses: {}

=C2=A0 =C2=A0 ide= ntifier: ""

=C2=A0 }

=C2=A0 text: &quo= t;This is a code block."

}

<p>This is <code clas= s=3D"c numberLines">inline code</code>.</p>=

<pre class=3D"c number= Lines"><code>This is a code block.</code></pre>


Thanks!

Le=C2=A0ven. 20 ao=C3=BBt 2021 = =C3=A0=C2=A011:57, William Lupton <wlupton-QSt+ys/nuMyEUIsrzH9SikB+6BGkLq7r@public.gmane.org> a =C3=A9cri= t=C2=A0:
I think you need a two-pass filter, one to pick up the metadata a= nd the other to use it (this is because Meta is called nearly last).
This works (I've re-ordered your functions and declared a = local variable, but this probably wasn't necessary).

% = cat defau= lt-code-class.lua=C2=A0

local default_code_classes =3D= {}


function get_default_code_clas= s(meta)

=C2=A0 if meta[&#= 39;default-code-class'] then

=C2=A0 =C2=A0 def= ault_code_classes =3D {pandoc.utils.stringify(meta['default-code-class&= #39;])}

=C2=A0 end=

end


function add_default_code_clas= s(el)

=C2=A0 if #(el.cl= asses) =3D=3D 0 then

=C2=A0 =C2=A0 el.= classes =3D default_code_classes

=C2=A0 =C2=A0 ret= urn el

=C2=A0 end=

end


return {{Meta=3Dget_default_co= de_class}, {CodeBlock=3Dadd_default_code_class}}


<= span style=3D"font-variant-ligatures:no-common-ligatures;color:rgb(128,42,2= 5)">% pandoc -L default-code-class.lua code.md -M default-code-class=3D"= c numberLines"

<pre class=3D"c number= Lines"><code></code></pre>

=

--
You received this message because you are subscribed to a topic in the Goog= le Groups "pandoc-discuss" group.
To unsubscribe from this topic, visit https://g= roups.google.com/d/topic/pandoc-discuss/NrRuAcm1otQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to p= andoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxgqyK6%2BT3= kmb7sNUckEJrS81cwm05iCvauKOA0Z3doRcg%40mail.gmail.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 pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAPGHSezmvUZSEApp0f= GCezjUNcqSJJCMBaLGTaPUc86tSoUS0A%40mail.gmail.com.

--
You received this message because you are subscribed to a topic in the Goog= le Groups "pandoc-discuss" group.
To unsubscribe from this topic, visit https://g= roups.google.com/d/topic/pandoc-discuss/NrRuAcm1otQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to p= andoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxgDzL%2BQja= r4bGfUndO7Pq-RimWPmN5tzYSV3B6BUh0Nrg%40mail.gmail.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 pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAPGHSewt%3DnK73A= HRJ4C6yMs_rdRkcXAiJXeY0MEYo1pAxX4ugQ%40mail.gmail.com.

--
You received this message because you are subscribed to a topic in the Goog= le Groups "pandoc-discuss" group.
To unsubscribe from this topic, visit https://g= roups.google.com/d/topic/pandoc-discuss/NrRuAcm1otQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to p= andoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxjF_GT3XXob= nhGizje_U6VDcODV0ubGR0dDN%3DDj_U2B3A%40mail.gmail.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://group= s.google.com/d/msgid/pandoc-discuss/CAPGHSexHuj0T1n%2B-rOFjnVe5ZLw5Y_iqQEsn= 1yjECZSdy3e9QQ%40mail.gmail.com.
--00000000000068d18b05ca01b736--