From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/28628 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Bastien DUMONT Newsgroups: gmane.text.pandoc Subject: Re: Fenced Div to ConTeXt Environment (was: Markdown Fenced Div to LaTeX Environment) Date: Thu, 17 Jun 2021 08:36:17 +0000 Message-ID: References: <8ba84992-d792-4333-aae0-560147ef79d4n@googlegroups.com> <87pn1uwglb.fsf@zeitkraut.de> <20210616143731.GA29446@sokrates> <5db56b4f1d8d4ca2bec612bcebb7a525@unibe.ch> <493d0aa9-47f5-ca8d-2ef5-8e63f965c529@mailbox.org> <4396a9133ab74e4fbff486f09e22d254@unibe.ch> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24096"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBDCINCES2QJRBKETVSDAMGQEK6OL6SY-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Thu Jun 17 10:36:59 2021 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-lj1-f192.google.com ([209.85.208.192]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ltnWF-00066f-6o for gtp-pandoc-discuss@m.gmane-mx.org; Thu, 17 Jun 2021 10:36:59 +0200 Original-Received: by mail-lj1-f192.google.com with SMTP id c20-20020a2ea7940000b029013767626146sf2381039ljf.15 for ; Thu, 17 Jun 2021 01:36:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1623919018; cv=pass; d=google.com; s=arc-20160816; b=osq945bwqhVZ6n837pLHdKDyeDP1c4+5cHzIeceDHPp9jp8bLp6568Uf8FeOQ61JO9 grPMxiaeGuW/kCQkJmKEfM57vqFoflntKag3Gz7ogO/7lIk5hlgjZEgJajLyleyirvHI UT7PsQekTUaUli7LEML7wHyYZv/AoR8JzY8AwY2mMwSPP3GYVuruijY6aYIcSlGPjG1S /kptUPlUEYGfrcrRhTxgOYAFuXuWvjV98d7VgD6kMX0oUjoPRRJbjHKlsxzWEzfeLbE6 XSzaizZGBLfko/dr2vca8Y6MYdzZ8T/wxf3Ua70a0nprmtkkzNgB7il6kkeAJmS9Q185 EqCg== 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:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:to:from:date:sender:dkim-signature; bh=HF0bQW+Gd+AOY9sRYkLXoXm7fa4TqI1J0jpZNT+bc4E=; b=w/rkYmmDRKrxxuIEV8vCh59tGeEmGYf0MU/mikQyaKQa4yP79TZWcHOP9BWClO7m+K kZsakK7tuujQhMF+cOnKsmkXM1P6i5F4lRGGUqG1/bPqgoYvZ0gaRLauLzMg8G+0e3gv 5xmgLrm1ZPZsG3MkSFU8kQqDiE3NNeO0vh3CNSw/LSjUvGmUmTM980kb94Wjx1qFBwyE g2v5BFjBCFTvNhLcv92SZ8qEF9ZmfAVXXH68eUEk39jsB9cCwK1MKY7RaFe4C9HS5AnW dRNgGENDJiPL5MSJGKc+FJPDWyw8T9uwToXztk9lq31bMo+sk+nHdnTIVwU8tHswCw+x KENg== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=m3gF8KmN; spf=pass (google.com: domain of bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org designates 185.67.36.65 as permitted sender) smtp.mailfrom=bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:date:from:to:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-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=HF0bQW+Gd+AOY9sRYkLXoXm7fa4TqI1J0jpZNT+bc4E=; b=s4aL0jBXDGeWEftIEs3blzNtoRNo0CgbSNfoeaYxT8nfhE4P8SAHKT0xz0c9ARRwws KweZjqKEURNvReFtZ7/4E0wGlVdI7rV+FCy97gPpS73kdXZOXoJ2NZoPiLZHwyLzLZcO aNQ4K2hAJWxSbApvZ5LUG4qybmOb0oX6/av2RGZt5/t/gzqNzZeJtURKV7wlSerBr40y eeDi7afqWdDqc9zF5jFBSvZSQzuZ7+2BymiBOi/NlPWRBpmZv+1RT+RnlASy1s2B5lQu sXeSG93qXgH1V9mpBgq10qv/GuQR0fgdjh9+lcy5k9yfOnzYXgNo1hL3EgV1R74JblBg nOrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:date:from:to:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-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=HF0bQW+Gd+AOY9sRYkLXoXm7fa4TqI1J0jpZNT+bc4E=; b=qckENlbnl5xX8joEN8xKTzu/dohWal7bCNjkmIunXqlQD5DsuplT7t9OCREY/rBPZR WunF6NCKwftnAIRYgbHpfo4ZoDbpwCEXh7aGujZkDrHFxJ0rl3BwtSNea4HAPSuKRMrH n5WHbgzPUbSF0cHaI51iP+lg7DXASi0ZK2r680X6NA/A7RE2GIyBZQ8aN/EqUAFziFTF 8HG0sLCskfBTZPknl2I8XmJeLsOupoLw2+TzdVmrTsgPpGOLMMQfAt6Y33FoX/GmNvw0 q+y1p8xxWiMwkArW2qQST60Ts4+nptuNpm/aLTAHdOYb Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM532WJGqjVCUIwXuhdAA85aP5H2qrWVxxINfvN2KAcF5rjg41QwfE YwdnjwabmEkcz3XDTYwdo4E= X-Google-Smtp-Source: ABdhPJyI8rOcpx2a0KCccokDonUmmMvJS7iT5XrvtL6XK0FHo7HXsosr4tZKLNWXSlgqi+lTfwe36A== X-Received: by 2002:ac2:54a7:: with SMTP id w7mr3317695lfk.415.1623919018772; Thu, 17 Jun 2021 01:36:58 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a2e:9a95:: with SMTP id p21ls1173873lji.8.gmail; Thu, 17 Jun 2021 01:36:56 -0700 (PDT) X-Received: by 2002:a2e:b01a:: with SMTP id y26mr3692046ljk.278.1623919016113; Thu, 17 Jun 2021 01:36:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623919016; cv=none; d=google.com; s=arc-20160816; b=0XWWxbAPsyDZKnEFkV90uG4AMB5eUjRuB51lfAvp85zI1+SkuM9F16NO1vhdqAY8eX D6mRoigZBEXihjZZveBO9kbuIi7X137DCRt4c1hb7G8mT1ceVUi9AF4kse3i+e9Oqjhd HafPYhlQYDV1WwYRkPBODXR5bVcY+K7A2OmWcQ+3XYASx6XJ2xwVW20GJy9nR0Wc9diY irVNRYWRON/WWiTo2gOxD+6PGYTfzM861y4wOd/eeOCpLRFA+XlKkDHg5m04NQHL+nOh 2ju0uBWM7cW0E6elB50zrdpgB50wWemrInTRitvkWxziQsK/Et44D0tG9MMTxkiTIosg cpBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:to:from:date :dkim-signature; bh=AXLLi6PWBWNFYG1X3dtYUEZBhb/CUQlwvRk2KSswwPI=; b=VoE2Lrht2fsvBTXzvxEHM1Mrodpa9q4D7x9g6TIAzYperUcsWTXenR0oo42LFtZprb l7hNi5NhSXw6LuXAqwIxbgW4MaW5PDoCSmLzxPNocvZL6bZW37YF4BhzH6Y4K13MXGVW IX+2ntCIg/3sOn6WjynQU86XUcGEcKv8y+VGFmZsaYuPBGnPB4FYEE0NSnDzDSu/3bsG e3Mrd6792HC3NIGLdV/m7HgBhgetM/tIF55tPdiegpfTMO3a4dcvFvQhfnT3j9iL/pFb asvsQZsMxLxQfOVBUwvFuwZ/UR07C2JR6BYXg2sqFkB6t0rAbOVb6sevTSJzTGWPzY9S hu9A== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=m3gF8KmN; spf=pass (google.com: domain of bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org designates 185.67.36.65 as permitted sender) smtp.mailfrom=bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net Original-Received: from mout01.posteo.de (mout01.posteo.de. [185.67.36.65]) by gmr-mx.google.com with ESMTPS id o13si89749ljp.0.2021.06.17.01.36.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 01:36:55 -0700 (PDT) Received-SPF: pass (google.com: domain of bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org designates 185.67.36.65 as permitted sender) client-ip=185.67.36.65; Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 3858C24002D for ; Thu, 17 Jun 2021 10:36:55 +0200 (CEST) Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4G5Flp5jZVz9rxB for ; Thu, 17 Jun 2021 10:36:54 +0200 (CEST) Content-Disposition: inline In-Reply-To: <4396a9133ab74e4fbff486f09e22d254-NSENcxR/0n0@public.gmane.org> X-Original-Sender: bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=m3gF8KmN; spf=pass (google.com: domain of bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org designates 185.67.36.65 as permitted sender) smtp.mailfrom=bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net 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:28628 Archived-At: One possible solution: ```lua ENV_CLASSES =3D { 'intro', 'question', 'solution' } local function context(s) return pandoc.RawBlock('context', s) end local function get_env_class(elem) if elem.classes then for i =3D 1, #elem.classes do for j =3D 1, #ENV_CLASSES do if elem.classes[i] =3D=3D ENV_CLASSES[j] then return ENV_CLASSES[j] e= nd end end else error('function has_class used on an element of type ' .. elem.t .. ' that cannot have classes.') end end function Div(el) local env_class =3D get_env_class(el) -- nil if there is none if env_class then -- false if env_class is nil return { context('\\start'.. env_class), el, context('\\stop'.. env_cla= ss) } end end ``` Notice that the intro, question or solution class need not be the first one= , so that this would be recognized: ::: {.my-class .intro} blabla ::: Le Thursday 17 June 2021 =C3=A0 08:12:06AM, denis.maier-NSENcxR/0n0@public.gmane.org a =C3=A9cr= it : > Yep, this is also what I was getting.=20 >=20 > But this minimal shows how to make it work: >=20 > ```lua -- works > function Div(el) > return {pandoc.RawBlock('context', "\\start"), el, pandoc.RawBlock('c= ontext', "\\stop")} > end > ``` >=20 > vs. >=20 > ```lua -- does not work! > function Div(el) > return {pandoc.RawBlock('context', "\\start"), el.content, pandoc.Raw= Block('context', "\\stop")} > end > ``` >=20 > So, this here works: >=20 > ```lua > function context(s) > return pandoc.RawBlock('context', s) > end >=20 > function Div(el) > if el.classes[1] =3D=3D 'intro' then > return { context('\\startintro'), el, context('\\stopintro') } > end > end > ``` >=20 > Maybe this should be a bit more generic though? >=20 > ``` > function context(s) > return pandoc.RawBlock('context', s) > end >=20 > function Div(el) > if el.classes[1] =3D=3D 'intro' or 'question' or 'solution' then > return { context('\\start'..el.classes[1]), el, context('\\stop'..el.cl= asses[1]) } > end > end > ``` >=20 > As my lua skills are far below mediocre I bet there ways to make this nic= er, e.g. by putting the relevant classes into a table and referring to that= . And you may also want to pass arguments from your divs to the context \st= art...\stop construct. Think of this: >=20 > \startquestion[difficulty=3Deasy] >=20 > How to build pandoc filters using lua? >=20 > \stopquestion? >=20 > Denis >=20 > > -----Urspr=C3=BCngliche Nachricht----- > > Von: 'juh' via pandoc-discuss > > Gesendet: Donnerstag, 17. Juni 2021 09:56 > > An: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > Betreff: Re: Fenced Div to ConTeXt Environment (was: Markdown Fenced Di= v > > to LaTeX Environment) > >=20 > >=20 > > Am 17.06.21 um 08:54 schrieb BPJ: > > > --filter/-F is for JSON filters. Lua filters need --lua-filter/-L > >=20 > > Thanks a lot! Now the error message is much more informative. > >=20 > > This is my filter: > >=20 > > function context(s) > > return pandoc.RawBlock('context', s) > > end > >=20 > > function Div(el) > > if el.classes[1] =3D=3D 'intro' then > > return { context('\\startparagraph{intro}'), el.content, > > context('\\stopparagraph') } > > end > > end > >=20 > >=20 > > This is the error message > >=20 > > Error running filter filter.lua: > > Could not read list: Could not get Block value: untagged value > >=20 > > Any hints? > > juh > >=20 > > -- > > 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-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To view this discussion on the web visit > > https://groups.google.com/d/msgid/pandoc-discuss/dc8ef20b-4a8b-c385- > > 704c-28c85a5b6820%40mailbox.org. >=20 > --=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-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit https://groups.google.com/d/msgi= d/pandoc-discuss/4396a9133ab74e4fbff486f09e22d254%40unibe.ch. --=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/YMsJgXv77qqiw7au%40localhost.