From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/26086 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Henrik Klang Newsgroups: gmane.text.pandoc Subject: Re: Pandoc Lua script to filter specific markdown sub sections during PDF generation Date: Wed, 9 Sep 2020 04:24:39 -0700 (PDT) Message-ID: References: <4e07ae0a-dcb1-4f89-8b91-ba787b7bea1cn@googlegroups.com> <92ac8df6-b88a-b047-b9f0-1fe62873b710@mailbox.org> <87d035yh4n.fsf@zeitkraut.de> <667487b4-f213-45c7-94fd-c0237d8b6592n@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_3034_566310247.1599650679383" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7241"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBD5OJP6RVQGRB6HW4L5AKGQEIXI3OZI-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Wed Sep 09 13:24:44 2020 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oi1-f186.google.com ([209.85.167.186]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kFyDU-0001nQ-6a for gtp-pandoc-discuss@m.gmane-mx.org; Wed, 09 Sep 2020 13:24:44 +0200 Original-Received: by mail-oi1-f186.google.com with SMTP id l77sf808984oig.2 for ; Wed, 09 Sep 2020 04:24:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; 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=OhBEXWJRpEdJHfWETLsucfOYgqak68VmAEtTbYDkOF4=; b=DnsmRZMFpcRTT8yqt7LVKyJ+lXAKwcAIaFEKCxzPkAObGtZp86ND49qhy42s1r8EkB ennIW1xK6Mm2EK+tWpahOfKwhFrdbwP1mmjHAem9/4RFsftTz7lQLLPal0N77KSvXQwW 1GpDQU81lKVbOlZODXTq00CPgRprvFH86/Zst7RKv0FSMO4Y7j/WIF7nDqBJg8n/Z2qm aoXzyXtAIlQTHxJ6YU3LEbQqlgWhr0nSHtmKa8NngeZeULrnAIgkgUXYHK6QAgko/5qN oPyz/Lt09uR6h31t5eAMVobC/6nXWs/5SH3qf2QNk+ZsIlcxoEnSJRCdJyaP3pYZbXT3 YrJQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; 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=OhBEXWJRpEdJHfWETLsucfOYgqak68VmAEtTbYDkOF4=; b=IeoxjvvLrW1q7SY+0YEEizRmcaGZ3fhnZ2UVyP8zW4Nfbb6AzyqqtQn1vGBPOc+CoC wAw503oCMdGTBl2LFFPIksDE2KNOoxFqV0cmGlNbUv7lvB2jo4f+FtPgJgiFtBzhjQce OemBa6ZeyGNy9i9KT7YjSREUmdesNxx/1CRuFTLldf2vcbtkO1VDuBJZmU40UXfRrazt 68N4tgIMGbu/LSZzFqH1vdGGMzbMz67OPIZ3d75E98G0NWPZPe1qabWill35M2y65YLA YCQT9O2Ki5eYacQdwgYmpggWh2rfCuVOMCFShejkdS80k/OoiIkzVNMWUj0VYY/7jO24 k2qg== 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: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=OhBEXWJRpEdJHfWETLsucfOYgqak68VmAEtTbYDkOF4=; b=qRun5ytkKFKaMLOe6987uJaFdvgAVaVR9Wj+BEhF/ZjjUyc6RkuEjG9jpNQZ+9fIF4 p93ESEtYyw5BixMFbUiqcdHbbM9jr0g7P8m6JjL9X6PwDC9xPR9gzdsBsvzCCcXJf9Zu kjSUyOTRQ0ZHYgDEPIm/aBM+uUnYVMztce7osz3H+gXy+apIFP7LwWMVO+UHngP9pS1K WE/dUSsl4oTF1bH20TY4z5xifvMo7qLb+s2JoyxXRWtIPNjln+xqUK00stZhVlPHYZ9k oku9C0JCfIN7T80vbN0IzFLAh+mG2VLKDu6Vzv6w5fGXeZrPDOLDHpPrwFvwJ4JQ4F9m lAUg== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM531aefwLl9MK7KYWCMbIaDH5j0PgHdHjSKv2k1D9TsqLbkxQI2hZ h+ZzAF0SySha2ejntLNfM1k= X-Google-Smtp-Source: ABdhPJwS3NGIE8nWBeJcQf0J6vFv+EQoSl277dw9nKIydMvLV9q+1EN1DS4UOllDQzMuAHlkZXfMSA== X-Received: by 2002:a9d:490a:: with SMTP id e10mr340284otf.325.1599650683201; Wed, 09 Sep 2020 04:24:43 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:aca:b541:: with SMTP id e62ls445896oif.2.gmail; Wed, 09 Sep 2020 04:24:40 -0700 (PDT) X-Received: by 2002:aca:ecc4:: with SMTP id k187mr280973oih.138.1599650680309; Wed, 09 Sep 2020 04:24:40 -0700 (PDT) In-Reply-To: <667487b4-f213-45c7-94fd-c0237d8b6592n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> X-Original-Sender: henrik.klang-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:26086 Archived-At: ------=_Part_3034_566310247.1599650679383 Content-Type: multipart/alternative; boundary="----=_Part_3035_1662245323.1599650679383" ------=_Part_3035_1662245323.1599650679383 Content-Type: text/plain; charset="UTF-8" Update: your suggestions worked. Thank you for excellent support. tisdag 1 september 2020 kl. 12:05:48 UTC+2 skrev Henrik Klang: > I meant the entire section with both headline and body. > > Thanks for the suggestions guys, I will try them out! > > / Henrik > > tisdag 1 september 2020 kl. 11:35:15 UTC+2 skrev Albert Krewinkel: > >> >> Denis Maier writes: >> >> > You mean like removing the sub section header? Or the whole subsection >> until the >> > start of the next section? >> > Both should be possible with a lua filter. The first is trivial, the >> second >> > more complex (at least for me ;-). But I doubt it wouldn't be possible. >> > The tricky part is possibly that pandoc's AST does not reveal the >> hierarchy >> > here: >> > >> > [Header 1 ("header-1",[],[]) [Str "Header",Space,Str "1"] >> > ,Para [Str "Text"] >> > ,Header 2 ("header-2",[],[]) [Str "Header",Space,Str "2"] >> > ,Para [Str "Text"] >> > ,Header 2 ("header-2-1",[],[]) [Str "Header",Space,Str "2"] >> > ,Para [Str "Text"] >> > ,Header 1 ("header-1-1",[],[]) [Str "Header",Space,Str "1"] >> > ,Para [Str "Text"]] >> > >> > So, I imagine you have to walk over the AST and when you encounter a >> "Header 2" >> > element, you delete this and everything else until you find the next >> "Head 1" >> > element. >> >> That's a good approach. Untested Lua: >> >> local keep_deleting = false >> function Block (b) >> if b.t == 'Header' and b.level >= 3 then >> keep_deleting = true >> return {} >> elseif b.t == 'Header' then >> keep_deleting = false >> elseif keep_deleting then >> return {} >> end >> end >> >> The alternative is to let pandoc wrap all sections in divs and to delete >> those that are undesired. See >> https://gist.github.com/tarleb/a0f41adfa7b0e5a9be441e945f843299 >> >> >> -- >> Albert Krewinkel >> GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124 >> > -- 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/dea98b71-e65b-401e-b3df-338cd80ae369n%40googlegroups.com. ------=_Part_3035_1662245323.1599650679383 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Update: your suggestions worked. Thank you for excellent support.

tisdag 1 se= ptember 2020 kl. 12:05:48 UTC+2 skrev Henrik Klang:
I meant the entire section with= both headline and body.

Thanks for the suggestion= s guys, I will try them out!

/ Henrik
tisdag 1= september 2020 kl. 11:35:15 UTC+2 skrev Albert Krewinkel:

Denis Maier writes:

> You mean like removing the sub section header? Or the whole subsec= tion until the
> start of the next section?
> Both should be possible with a lua filter. The first is trivial, = the second
> more complex (at least for me ;-). But I doubt it wouldn't be = possible.
> The tricky part is possibly that pandoc's AST does not reveal = the hierarchy
> here:
>
> [Header 1 ("header-1",[],[]) [Str "Header",Spa= ce,Str "1"]
> ,Para [Str "Text"]
> ,Header 2 ("header-2",[],[]) [Str "Header",Spa= ce,Str "2"]
> ,Para [Str "Text"]
> ,Header 2 ("header-2-1",[],[]) [Str "Header",S= pace,Str "2"]
> ,Para [Str "Text"]
> ,Header 1 ("header-1-1",[],[]) [Str "Header",S= pace,Str "1"]
> ,Para [Str "Text"]]
>
> So, I imagine you have to walk over the AST and when you encounter= a "Header 2"
> element, you delete this and everything else until you find the ne= xt "Head 1"
> element.

That's a good approach. Untested Lua:

local keep_deleting =3D false
function Block (b)
if b.t =3D=3D 'Header' and b.level >=3D 3 then
keep_deleting =3D true
return {}
elseif b.t =3D=3D 'Header' then
keep_deleting =3D false
elseif keep_deleting then
return {}
end
end

The alternative is to let pandoc wrap all sections in divs and to delet= e
those that are undesired. See
https://gist.github.com/tarleb/a0f41= adfa7b0e5a9be441e945f843299


--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124

--
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/dea98b71-e65b-401e-b3df-338cd80ae369n%40googlegroups.= com.
------=_Part_3035_1662245323.1599650679383-- ------=_Part_3034_566310247.1599650679383--