From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/32403 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Bastien DUMONT Newsgroups: gmane.text.pandoc Subject: Re: Help with Lua filter for markdown to LaTeX with Pandoc Date: Sun, 26 Mar 2023 09:53:27 +0000 Message-ID: References: <79ac7814-9558-4d49-a682-cf31f970d27dn@googlegroups.com> <6a7dabf5-1fda-4825-9d21-193b63363937n@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="mT1zqEFQRLN5HcWE" Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29530"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBDCINCES2QJRBGVMQCQQMGQEKECT27Y-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Sun Mar 26 11:53:34 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-wm1-f62.google.com ([209.85.128.62]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pgN49-0007PT-W3 for gtp-pandoc-discuss@m.gmane-mx.org; Sun, 26 Mar 2023 11:53:34 +0200 Original-Received: by mail-wm1-f62.google.com with SMTP id n19-20020a05600c3b9300b003ef63ef4519sf1720836wms.3 for ; Sun, 26 Mar 2023 02:53:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1679824413; cv=pass; d=google.com; s=arc-20160816; b=xgUdpHwzlCEm86BT94dyRnJhskJDjXKfK65tOPpYCbeZJLvgsJFxHEeXDA+WcjgG/s zMOwz7r53X8AvI9/dkNx3WDdA7CYBilJ7mLBlZC9DqfJg+dyEZ8GAhTnNmw02Oq6ds39 aT7ETBiAlFBDMgZHdKt7ohqyy868Wvii3Dx4Hld9AR/PSQModQAOuuj6hzsLbY4GalDh Wct4yNRxG0RJqv4Qo+ubrTxUxVHXM5v63EQiWm1PBWDcFvIg8kuBg9jLeCHsTAT367Hd kc+UTobyIn8yBrFfw14PjxinYbjVFWAU7BE72u4UAJs8yki4C/o8gqDFr7/PiK4GNwtf 11eg== 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=Eo6mK1ECffNgIijmbCpGOu8qpgmBP8Vba8xOxmHp+Ow=; b=M29RiFRLNdNP/hmPaOB8VUFYcwQDdHtJ4AeKw1gSqeddTZ7yrLVQ+e4TO1/LZC2yGv t76ToeC/8rRQAFR9qhBHHNZY7WBYHQYf4b5cZ8zDktgWdqhxSw8bk9ipdKKTi6dTfQHk MD/MdrJ1I0cJrTXeIb0Ws9/JHPr/z7s8R2yhf9bI8E60qDVNKDgU4u3OS2LsgpI/6wo+ K7rUSDAtUrKehgDY2/rmfIx16vMrZGwSgMO6bCgfTZaEX8iL9CRYl8iRUKd4xrT9vJtE TPiQMhlcoEtIEWNyHiSJ/qP0eYI9vbAJPDyiejcIzZ2ztvuajk0TdSI9s2Lpkbh6NVwH 5VlQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=k8Hs2Txq; spf=pass (google.com: domain of bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org designates 185.67.36.66 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=20210112; t=1679824413; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to :x-original-authentication-results:x-original-sender:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:to:from:date:sender:from:to:cc :subject:date:message-id:reply-to; bh=Eo6mK1ECffNgIijmbCpGOu8qpgmBP8Vba8xOxmHp+Ow=; b=OboOJT6qngBtNstEvTGzdZh9QAhexK3U0xMigPXRAQgPwpJuwWE6uj+kic8Lmjdta1 tTUpMzvZGr9BQv1Oca6F1t73+aw/FDIp8EUV9llZks0FIkdB3D7sjcsQUZqHT0PSsS5U eF2/WaCkxSONmV5HkJuOIMIngTlUBfT3UDWONz60oNFR/iseIu3WzWbAqohwJpwRbq59 4yd9DEOzmfRM6bh3F2SHmx3DAElZgBzEZl8ETLSArWv9dDmN4WBnfZZDmVm7tONs5rw7 gZEIflXC0otrIoYECe10fIAMdb246vk X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679824413; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence:reply-to :x-original-authentication-results:x-original-sender:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:to:from:date:x-gm-message-state :sender:from:to:cc:subject:date:message-id:reply-to; bh=Eo6mK1ECffNgIijmbCpGOu8qpgmBP8Vba8xOxmHp+Ow=; b=G+FHYOUB24z6Oz8d0Qnq3YtqOrEmqfISa3GIeNSmT6I/z06ZvVh/HBDWoQSAurk347 KUQFtDmTv8uxlmvcVSUqxstsgF6NaKP6ByM9NQj5+UVwQmU77vCmH3Wqvn9uNDkVPdy7 gHC1+B8oeP0g98p9Dx15HetDKm29Bm8f2+mWo2FfPJbzyZXhHrqI7nlKUpVkTrjocpgN 7Vz5xMej+um1BymaQFLLJx3MqoMRrKoDL1vs+G2weBcLvyDgGl+VUh5r1nTbH1rh Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AAQBX9cMPCCIqw23NHv6IYjNMgTCXr31cGEB/RAw9AJkukT5yEpzQn6C eDLcAaN/5FE6FFIFcRr6WUg= X-Google-Smtp-Source: AKy350Zj5uNzzPIs7rDi34hKh+nzg5Xm0MsMMs7X5aOG0nNSTGyR9BK0PBBcz1NiHSAkYZbwEg8F4w== X-Received: by 2002:a5d:5b07:0:b0:2c5:5941:a04b with SMTP id bx7-20020a5d5b07000000b002c55941a04bmr4164342wrb.7.1679824413633; Sun, 26 Mar 2023 02:53:33 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:adf:d1cc:0:b0:2c5:5262:2e24 with SMTP id b12-20020adfd1cc000000b002c552622e24ls7747719wrd.2.-pod-prod-gmail; Sun, 26 Mar 2023 02:53:29 -0700 (PDT) X-Received: by 2002:a5d:54c9:0:b0:2d2:6a31:b868 with SMTP id x9-20020a5d54c9000000b002d26a31b868mr6505981wrv.27.1679824409058; Sun, 26 Mar 2023 02:53:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679824409; cv=none; d=google.com; s=arc-20160816; b=yPTkt79sDVWm9KzxAnsm90Um+3Berz3NgjZhekpUbNeHKno5w/ZGAPBj9++RJ3ytyL fm+yyq+3j6I5DExzMpqMuGmenehe5lyFp/JcQfXHbSgPtWqLPwK2bp6Ecr4LMIx8bTHW NdALhIvqTvRC8YoIYEDUyOVvAGjRavAfC+HnEig7ETKy5F0yyGQMkt7XvuWWJYkkSIWX 0k+XH5Py4O6DeQBS5moy2oBJGdK5tX+jfGCPt8GtPlYH71ZwXktnVWrGwpbRQrLl3ieX vDym3H3qL/MQWu8nmRKGyraIAaIfj2wUT73CrtcJlxjX+cNjUl74Y8efMFby/e2bakQo jTSA== 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=3ykY6zTp4t0rt8uD4lGFlX8abL2+PetPOxZT/V0aBy4=; b=rZQUGQPvX5r9bGb1IUaWWGl1yE9U3eJ7H8h4IFaCFn82XdPiHzI1fVocxAcbkWjZKS Sycni/6UIRzPv2cBq9bjXGNXQjb88ZEmdTyMfdXeTUJyLE+wOjHpPKuSQ4UvNQUKkICm mGMZgVTVmAWPEFHyEDUMhxF5ij51+r1Fa/wX0ED8UAZ5mp5dSTm5rfgSQH7IE/3Ix782 ADrRxMEBuzDS021rBECt7m8L0mGv0fi1igHqCEt2p+F5oAmgDC/oaqsGEXFkplHfmcNB mNTGOQM2q+yBp6bhzNxg7mMOX81h1TW4GgY1sjlCK9BqAcjV3hob9EqzqWTa6FB1BbvE r0wQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=k8Hs2Txq; spf=pass (google.com: domain of bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org designates 185.67.36.66 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 mout02.posteo.de (mout02.posteo.de. [185.67.36.66]) by gmr-mx.google.com with ESMTPS id az20-20020adfe194000000b002c59e9a3f66si1180925wrb.2.2023.03.26.02.53.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Mar 2023 02:53:29 -0700 (PDT) Received-SPF: pass (google.com: domain of bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org designates 185.67.36.66 as permitted sender) client-ip=185.67.36.66; Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 84F6E24021E for ; Sun, 26 Mar 2023 11:53:28 +0200 (CEST) Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4PkrqX0kyBz6tm9 for ; Sun, 26 Mar 2023 11:53:28 +0200 (CEST) Content-Disposition: inline In-Reply-To: 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=k8Hs2Txq; spf=pass (google.com: domain of bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org designates 185.67.36.66 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:32403 Archived-At: --mT1zqEFQRLN5HcWE Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable I attached two filters. If you run: pandoc -t latex -L highlight-red.lua -L in-red.lua <<< 'Some *=3D=3Dtext in= red=3D=3D*!' You get: Some \colorbox{lightred}{{text in red}}! Le Sunday 26 March 2023 =C3=A0 02:42:54AM, Pa Sc a =C3=A9crit : > Do you mean the two filters that are in the original post? Or what filter= do > you mean? >=20 > Bastien DUMONT schrieb am Sonntag, 26. M=C3=A4rz 2023 um 00:08:53 UTC+1: >=20 > Please share the two lua filters you use to parse `=3D=3D` as a synta= x for > highlighting and to print in red an emphasized span produced by this > filter. We can't figure out what is wrong without them. >=20 > Le Saturday 25 March 2023 =C3=A0 03:44:24PM, Pa Sc a =C3=A9crit : > > Yeah, I have a MWE here: [1]https://tex.stackexchange.com/questions= / > 680766/ > > help-with-lua-filter-for-markdown-to-latex-with-pandoc > > > > As for the command: > > ``` > > mkdir -p /home/ME/Documents/Obsidian/Output/{{title}} > > pandoc -r markdown-auto_identifiers -w latex {{file_path:absolute}}= -o / > home/ME > > /Documents/Obsidian/Output/{{title}}/{{title}}.tex --template=3D"/h= ome/ME/ > > Documents/LaTeX/My Templates/Proposal/default-proposal.tex" --lua-f= ilter=3D > /home/ > > ME/Documents/LaTeX/Filters/highlight.lua --lua-filter=3D/home/ME/Do= cuments/ > LaTeX/ > > Filters/highlight-period.lua --lua-filter=3D/home/ME/Documents/LaTe= X/ > Filters/ > > Span.lua --lua-filter=3D/home/ME/Documents/LaTeX/Filters/highlight-= red.lua > > --lua-filter=3D/home/ME/Documents/LaTeX/Filters/Span-red.lua > > ``` > > > > -- > > 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, s= end an > email > > to [1]pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To view this discussion on the web visit [2][2]https://groups.googl= e.com/ > d/msgid/ > > pandoc-discuss/6a7dabf5-1fda-4825-9d21-193b63363937n%[3] > 40googlegroups.com. > > > > References: > > > > [1] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > [2] [4]https://groups.google.com/d/msgid/pandoc-discuss/ > 6a7dabf5-1fda-4825-9d21-193b63363937n%40googlegroups.com?utm_medium= =3Demail& > utm_source=3Dfooter >=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 [5]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit [6]https://groups.google.com/d/m= sgid/ > pandoc-discuss/aded6fcf-0720-4fea-a873-af2cacfb8281n%40googlegroups.com. >=20 > References: >=20 > [1] https://tex.stackexchange.com/questions/680766/ > [2] https://groups.google.com/d/msgid/ > [3] http://40googlegroups.com/ > [4] https://groups.google.com/d/msgid/pandoc-discuss/6a7dabf5-1fda-4825-9= d21-193b63363937n%40googlegroups.com?utm_medium=3Demail&utm_source=3Dfooter > [5] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > [6] https://groups.google.com/d/msgid/pandoc-discuss/aded6fcf-0720-4fea-a= 873-af2cacfb8281n%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/ZCAWF2ex/yTJBEuH%40localhost. --mT1zqEFQRLN5HcWE Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="highlight-red.lua" Content-Transfer-Encoding: 8bit --[[ Add support for a custom inline syntax. This pandoc Lua filter allows to add a custom markup syntax extension. It is designed to be adjustable; it should not be necessary to modify the code below the separator line. The example here allows to add highlighted text by enclosing the text with `==` on each side. Pandoc supports this for HTML output out of the box. Other outputs will need additional filters. Copyright: © 2022 Albert Krewinkel License: MIT ]] -- Lua pattern matching the opening markup string. local opening = [[==]] -- Lua pattern matching the closing markup string. local closing = [[==]] -- Toggle whether the opening markup may be followed by whitespace. local nospace = true -- Function converting the enclosed inlines to their internal pandoc -- representation. local function markup_inlines (inlines) return pandoc.Span(inlines, {class="mark-red"}) end ------------------------------------------------------------------------ local function is_space (inline) return inline and (inline.t == 'Space' or inline.t == 'LineBreak' or inline.t == 'SoftBreak') end function Inlines (inlines) local result = pandoc.Inlines{} local markup = nil local start = nil for i, inline in ipairs(inlines) do if inline.tag == 'Str' then if not markup then local first = inline.text:match('^' .. opening .. '(.*)') if first then start = inline -- keep element around in case the -- markup is not closed. Check if the -- closing pattern is already in this -- string. local selfclosing = first:match('(.*)' .. closing .. '$') if selfclosing then result:insert(markup_inlines{pandoc.Str(selfclosing)}) elseif nospace and first == '' and is_space(inlines[i+1]) then -- the opening pattern is followed by a space, but the -- config disallows this. result:insert(inline) else markup = pandoc.Inlines{pandoc.Str(first)} end else result:insert(inline) end else local last = inline.text:match('(.*)' .. closing .. '$') if last then markup:insert(pandoc.Str(last)) result:insert(markup_inlines(markup)) markup = nil else markup:insert(inline) end end else local acc = markup or result acc:insert(inline) end end -- keep unterminated markup if markup then markup:remove(1) -- the stripped-down first element result:insert(start) result:extend(markup) end return result end --mT1zqEFQRLN5HcWE Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="in-red.lua" function Emph (emph) local content = emph.content if #content == 1 and content[1].t == 'Span' and content[1].classes:includes 'mark-red' then return { pandoc.RawInline('latex', '\\colorbox{lightred}{'), content[1], pandoc.RawInline('latex', '}') } end end --mT1zqEFQRLN5HcWE--