From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/27477 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Peter Matulis Newsgroups: gmane.text.pandoc Subject: Re: Lua filter to convert Markdown comment Date: Thu, 14 Jan 2021 22:38:09 -0500 Message-ID: References: Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000009313ea05b8e81a3a" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22829"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCUL3CX4YUARBLU4QSAAMGQEIDBAWUQ-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Fri Jan 15 04:38:25 2021 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-lj1-f186.google.com ([209.85.208.186]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1l0FwP-0005rm-7N for gtp-pandoc-discuss@m.gmane-mx.org; Fri, 15 Jan 2021 04:38:25 +0100 Original-Received: by mail-lj1-f186.google.com with SMTP id z22sf2679300ljj.5 for ; Thu, 14 Jan 2021 19:38:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1610681904; cv=pass; d=google.com; s=arc-20160816; b=Yo4OIrW+OqPY35QZErMNvAKdlnoYcfPvQOySdfX7sDnChiahK86YCGNlDl3Y96E4Jq FraaTjz6A5WrAoZLBXi7JylI6nqR+NdpK1U0aQpuUelMfRMpYnfqwr26rmLILSiPsFJQ AUiPf74yyKkBdoX6qauo0ibz9cPRNNT4yA0xv3ZNfKTVL9zi9y7YUpmLJd4SqXsYmxmq zFFzGPSXK7PYNqU28Cf+elDpmAfTwua1VQR44DgM76XzJJwgLXgRdIBu2cBZ6FJ8UuTR scGPSLdmbsPa3vsB/sdpf6AeIZero3r2OVya29NqofosvEB/MAYe/vi4DQ0/u6k/+e1R vhiA== 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=86Vrgxn9UV0qMUg/zhuxNtaIuSQg9oDyupjJpchFWcA=; b=lgkm0VB39jW8TVd2kA5HqfrUb7875euFDMl8MD3h6FwBEPXIzHin2I/upVMSnGnufm Wus7vJn5IGQmhpCdrwgPi/HOkoyrxcvjocZlzHPs9YOhC+CKQ5iHQG7rKKI/SsOx7tGM c8vyWlXtmr1Emuxkq199wSAq6WEEUF8MLJdz0zUWG/gH6afix28yfZwZS/6t1JLV4vHJ erWmK+rX0sz5D0BalHUzhDQAZSPyWhCzB28UtnvMCtow/EHmI/pknZsNbV4ZNCmox6bS 4UNUaovIUrrNnKm8CQ6DR5MgZ6AkkBHgXxNDOsAzSTiT8vd250ZIItQF6kgd2rNx9qTi FvHg== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ltko0+hb; spf=pass (google.com: domain of pmatulis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::62e as permitted sender) smtp.mailfrom=pmatulis-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=20161025; 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=86Vrgxn9UV0qMUg/zhuxNtaIuSQg9oDyupjJpchFWcA=; b=K0Qj9pfsPTpEJgo7D4ROZjM9aEUtUcamXtGsQi3hp7hI8nGVBK6VIrUmbL8UCG8OJ4 uHATmGaQHRmzE6UKa8ZPObY2rARqmYex0KEBbrKDTQr46PMCSKsFHJC/X96Tb2vVhBPY sX1btgJXkYM5oqpzqz/J8XD9lxvxMHMGN1vOQOSFf2ArUbmTe+8VhHnF1wHdiWaOPpWw IFb7ivhWsYfwzE2thnoseLVOtsM0MT3B8ZhEMqEgzEfR5SiVyZ2nPjWI7Ji9cCItSz0S 1nYeNiw/7iYHT8jCR+AlJH5d+dOAFLQfWPxf5WQj7dFc1GFI03V8gMDS3T+2mR/QatrN YJpg== 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=86Vrgxn9UV0qMUg/zhuxNtaIuSQg9oDyupjJpchFWcA=; b=sqSgfSXZgfCUQ/PB0EF+9eVRlTgcVDU3MmjKV1otCAI54ZPbPwpJ6FpqUftFptIvZK bVQAiYRgec5XeuWRcXYmhuJwzT0tXYHa5g4XtWt9ZUKUEsWllmC53vMja7OfECqqd6uV s8qzdRiPfCQZvcYnzruM4m+Pe8xcbhsmsgKVOFdXmMXiSqo6ko4QHFOwNHecdAOE4c6/ iRlQaYFYLJRjXFf462ugCyYuMEde1EcsMyzUoY/y94OiuZ0a7gQV8XKeSHSx5vBmIoiR K7VlOTdqGy3tucJ1MrUZfQdzbT7vrUrPU+OHnsEzq+naBKF8Q9ZJ1u/yQeYmLHjJcPVT mO/g== 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=86Vrgxn9UV0qMUg/zhuxNtaIuSQg9oDyupjJpchFWcA=; b=fXP7tMo6jr7MB3jCOayIjlMCQecXHFf6OPIhxyKM8M1ricyEXi4w9CAdI+uhmCggJJ o6i08liptn85mD2h89UtbS4sUTjGMndpV8+lLx0gHdDv6K297nALQ6MR9X9+8RgoQvkU tMdaiDna3LadFyxdx2ns2oFrJ46jVxQz8QYoERp8xZiGsQh3ocE77FdQTvmYnGfWWnwo SBODglvSF4Ttl36HuXUAIaWf1sa1sACN2NkjtJbXY9WWNjdhRqooRNe9FftG4fvi9q2p OwHOgRxTgSHYwcZ6I1+dPnGSDCY+Lo/dGcmO7jpJXvC5LbDVsdNwfXtBRzy0Q28NSstp 9gmQ== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM530mPCUNo4tS+wojOT2b6BA01wH19X9uK1s6nzH2twVfW+XdsV8R IsNyLabCGVtToY1qizGkm/M= X-Google-Smtp-Source: ABdhPJzxL/HOe8ybvtcXXy4GwbXq1dEPnnrbAi7weHt6wBWNZrbQC2wd/fZNmXuRPlhDGXv9mu8RwQ== X-Received: by 2002:a2e:95d5:: with SMTP id y21mr4672881ljh.477.1610681904713; Thu, 14 Jan 2021 19:38:24 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a2e:b549:: with SMTP id a9ls1301305ljn.1.gmail; Thu, 14 Jan 2021 19:38:21 -0800 (PST) X-Received: by 2002:a2e:9605:: with SMTP id v5mr4482405ljh.81.1610681901732; Thu, 14 Jan 2021 19:38:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610681901; cv=none; d=google.com; s=arc-20160816; b=I47AxQHdAkW6vRYNhevgilYQJakcySKXIlLLviir/1WEMf2S0bw5o4gemWji5lfJfH 8aVRNt8oO9Z57g3Se1IzE6X35LYlS1jKyine48l6ZwsLmrc7rqa/GhDWMc+dbQjuJnBM WrhElpYwTmZVMJcER9dSpJTbLxEkDqdtKRIbDpP0J4hUXbUZCF2ro018b8xDpOF4NE1p PRhU5CwixOBG4/a5nJCCZzZEN3ndME9w1HGRTONb3sgnaHzDQ9fvWoNsISeeczKdS5ER ++BFFHzZ2Ebpxd2DOtBA7FX+CxnzBZOBsXDwnaqmw3Zgugiht0h1uQ/mbcLH8NZKObb3 r/IA== 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=0yPZfU1X1nFI0zcgCqlQUeArr+2Jkio17XahPbJWOXI=; b=U0tVqJUGR+foat41Q4l96OGn1QqrnTWlnG9PZ92DWASX+bTZst6WTIr73zTIt2pg8K 76gdZ6pxriZ2CzEXdU0f6czuw2KPjgUnU3HFkva/jYCghcIyfLwm2lj/D4qpSSxkq680 p2ZQzManXneLk1T8kxrtVE6rTYthe/62NRhN2k4C6Bg/yMtKOuef506AiM+eGCNFaqLv SnT46Li80z+jBwOxHfR+/yI4knmLOFGJ4l6EVZarvB+UzXiAQVFZfoXh7YpwgMRaZO+J 6khnhmehCXLIOIVhIBtHH9RViOfFVquWxDhE2Ig25aFuMjoaOTW66KXctSiscaE/po3G KP7A== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ltko0+hb; spf=pass (google.com: domain of pmatulis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::62e as permitted sender) smtp.mailfrom=pmatulis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Original-Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com. [2a00:1450:4864:20::62e]) by gmr-mx.google.com with ESMTPS id c24si305187ljk.7.2021.01.14.19.38.21 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Jan 2021 19:38:21 -0800 (PST) Received-SPF: pass (google.com: domain of pmatulis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::62e as permitted sender) client-ip=2a00:1450:4864:20::62e; Original-Received: by mail-ej1-x62e.google.com with SMTP id 6so11369659ejz.5 for ; Thu, 14 Jan 2021 19:38:21 -0800 (PST) X-Received: by 2002:a17:906:174f:: with SMTP id d15mr7442776eje.52.1610681901322; Thu, 14 Jan 2021 19:38:21 -0800 (PST) In-Reply-To: X-Original-Sender: pmatulis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ltko0+hb; spf=pass (google.com: domain of pmatulis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::62e as permitted sender) smtp.mailfrom=pmatulis-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:27477 Archived-At: --0000000000009313ea05b8e81a3a Content-Type: text/plain; charset="UTF-8" So I now have this: function RawBlock(el) if el.text:match("%<%!%-%- foo %-%-%>") then content = "foo" return pandoc.Header(2, content) end end There are actually about a dozen such known Markdown comments (e.g. 'foo', 'bar'). Instead of creating multiple files I'd like to have just one that uses a regex and capture group: if el.text:match("%<%!%-%- (%a+) %-%-%>") then I'm just unsure how to refer to the capture in a conditional statement (i.e. "if 'foo' is captured then 'content' = "foo", elsif 'bar' is captured then 'content' = "bar"). On Thu, 14 Jan 2021 at 15:57, Peter Matulis wrote: > Gratitude. This got me going. > > On Thu, 14 Jan 2021 at 13:52, John MacFarlane wrote: > >> >> What you want to do is match on a RawBlock element. >> Something like >> >> function RawBlock(el) >> if el.text:match(" >> > >> > I simply want to convert this into an actual (second-level) MD header: >> > >> > ## blah >> > >> > From what I've read, I would ideally specify an "element" that will be >> > acted upon, but what is a comment considered? Anyway, I think I can >> specify >> > `Pandoc` to mean "check the entire document", and that's what I've done >> > here (I will eventually be iterating through multiple MD files so I >> should >> > really not be doing it like this; please advise!): >> > >> > function Pandoc (value) >> > comment = "" >> > comment = comment:gsub("%<%!%-%- blah %-%-%>", "## blah") >> > return value >> > end >> > >> > I've run the main logic through Lua on the terminal and it works: >> > >> > $ lua >> > Lua 5.3.3 Copyright (C) 1994-2016 Lua.org, PUC-Rio >> >> comment = "" >> >> comment = comment:gsub("%<%!%-%- blah %-%-%>", "## blah") >> >> print (comment) >> > ## blah >> > >> > But I'm failing to integrate it with Pandoc (no change is registered in >> > file.html). It's probably due to my misunderstanding of functions (not a >> > programmer!). >> > >> > TIA. >> > >> > /pm >> > >> > -- >> > 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/CAMxYqzEvRHcFQ1BYsFODC-Bd36%3DLfO-UKcVYPNzR8i8rDZorXw%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/CAMxYqzHK6BvhbzE__4__Po%2Bwizq_4b3CZT9q%3D9ZQ1iF9JR-VSg%40mail.gmail.com. --0000000000009313ea05b8e81a3a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
So I now have this:

function RawBlock(el)
=C2=A0 if el.text:= match("%<%!%-%- foo %-%-%>") then
=C2=A0 =C2=A0 content = =3D "foo"
=C2=A0 =C2=A0 return pandoc.Header(2, content)
= =C2=A0 end
end

<= font face=3D"monospace">
There are actually about a dozen s= uch known Markdown comments (e.g. 'foo', 'bar').
I'd like to have just one that uses a regex and ca= pture group:

=
=C2=A0 if el.text:match("%<%!%-%- (%a+) %-%-%>= ;") then

I&= #39;m just unsure how to refer to the=C2=A0capture in a conditional statement
(i.e. "if 'foo' is captured then 'content' =3D &= quot;foo", elsif 'bar' is captured then 'content' =3D = "bar").


<= div dir=3D"ltr" class=3D"gmail_attr">On Thu, 14 Jan 2021 at 15:57, Peter Ma= tulis <pmatulis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> = wrote:
Gratitude. This got me going.

On Thu, 14 Jan 2021 at 13:52, John M= acFarlane <jgm@ber= keley.edu> wrote:

What you want to do is match on a RawBlock element.
Something like

function RawBlock(el)
=C2=A0 if el.text:match("<!--") then
=C2=A0 =C2=A0 content =3D -- fill this in based on el.text
=C2=A0 =C2=A0 return pandoc.Header(2, content)
=C2=A0 end
end


Peter Matulis <p= matulis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> Hi. I'm new to Pandoc & Lua but my present issue is straightfo= rward. I am
> converting a Markdown file to HTML with pandoc like this:
>
> pandoc -L filter.lua -f gfm -t html -o file.html file.md
>
> Where file.md contains a line with this MD comment (the MD file was > obtained by converting from RST where I had to seed that file with an = RST
> comment to use as a placeholder for what I'm doing here):
>
> <!-- blah -->
>
> I simply want to convert this into an actual (second-level) MD header:=
>
> ## blah
>
> From what I've read, I would ideally specify an "element"= ; that will be
> acted upon, but what is a comment considered? Anyway, I think I can sp= ecify
> `Pandoc` to mean "check the entire document", and that's= what I've done
> here (I will eventually be iterating through multiple MD files so I sh= ould
> really not be doing it like this; please advise!):
>
> function Pandoc (value)
>=C2=A0 =C2=A0comment =3D "<!-- blah -->"
>=C2=A0 =C2=A0comment =3D comment:gsub("%<%!%-%- blah %-%-%>&= quot;, "## blah")
>=C2=A0 =C2=A0return value
> end
>
> I've run the main logic through Lua on the terminal and it works:<= br> >
> $ lua
> Lua 5.3.3=C2=A0 Copyright (C) 1994-2016 Lua.org, PUC-Rio
>> comment =3D "<!-- blah -->"
>> comment =3D comment:gsub("%<%!%-%- blah %-%-%>", &= quot;## blah")
>> print (comment)
> ## blah
>
> But I'm failing to integrate it with Pandoc (no change is register= ed in
> file.html). It's probably due to my misunderstanding of functions = (not a
> programmer!).
>
> TIA.
>
> /pm
>
> --
> You received this message because you are subscribed to the Google Gro= ups "pandoc-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send= an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
> To view this discussion on the web visit https://gr= oups.google.com/d/msgid/pandoc-discuss/CAMxYqzEvRHcFQ1BYsFODC-Bd36%3DLfO-UK= cVYPNzR8i8rDZorXw%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://gro= ups.google.com/d/msgid/pandoc-discuss/CAMxYqzHK6BvhbzE__4__Po%2Bwizq_4b3CZT= 9q%3D9ZQ1iF9JR-VSg%40mail.gmail.com.
--0000000000009313ea05b8e81a3a--