From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/26031 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: Tue, 1 Sep 2020 03:05:47 -0700 (PDT) Message-ID: <667487b4-f213-45c7-94fd-c0237d8b6592n@googlegroups.com> References: <4e07ae0a-dcb1-4f89-8b91-ba787b7bea1cn@googlegroups.com> <92ac8df6-b88a-b047-b9f0-1fe62873b710@mailbox.org> <87d035yh4n.fsf@zeitkraut.de> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_118_1956936245.1598954747947" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37021"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBD5OJP6RVQGRB7NZXD5AKGQEDVZL2RA-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Tue Sep 01 12:05:54 2020 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-ot1-f60.google.com ([209.85.210.60]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kD3An-0009WU-Bw for gtp-pandoc-discuss@m.gmane-mx.org; Tue, 01 Sep 2020 12:05:53 +0200 Original-Received: by mail-ot1-f60.google.com with SMTP id z23sf268602ote.14 for ; Tue, 01 Sep 2020 03:05:53 -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=jD+73b+E27LFuF5Y5vqq7RqGnjFdSbhkIfq4jDREEN0=; b=Qhfp8wsNsryKkXjTCgOpQrb1VT0cNptYxM1dW/CVW/dufOh96XhQ4tJJvBaWDx056B bMVUa6BRpaZB16TBiR0rSOE+AGp2ux8UHH0HCry1ohpbhRSOUgj12yapEGSP4m0A+GhV jIUGyMjGt+WCguxpCRRj5Dg7nfctuWAWjXgFJM+Wx1nQAyF6jM4+3ynrae1NlWq3NFNl XDOVDLCLY2E2pdlZmYmXlLU37ErdLlOn0kjff7MXFdoYR/bStc9e4a0ed3hoSXxHUHxT +8PM8WjUMYPTMGhLE1mAokFRYI9yR3SXndU74xsKnYozoPrI9mTfI1wzRxqGo48WBdbV /ovg== 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=jD+73b+E27LFuF5Y5vqq7RqGnjFdSbhkIfq4jDREEN0=; b=vZ5aKGI9weuth9ytUN0tG+6rR3iVFhH+/JAfI+tHeSAfSB82oaYppWQ3J4rwpSFaTQ 0hFrL1/Bcz17wcW91/c2lCSlmXlkrl1YYh6UK0mC3dGZAldCf/O2TbGOOLL/6QjGuYLh KCMXKryVGmoK8BmZCOGNPmJMlnXkwRT4KjlimDEs6DOgIgeRtEUhJYPJ90/UiaX7VJwj 4nvTzfTFhkVclKuftkMUrKoNyKBrKdJU9xGfPt2hWLX72RAzWNQlEqBQeG0GZUftnYh4 A/DGhOs6dYrhQnV+AsbVJc2CsDuhEx1Yefk/cAxXTnoesDwWh2HqixW/jjQk9uacWlhK cy4w== 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=jD+73b+E27LFuF5Y5vqq7RqGnjFdSbhkIfq4jDREEN0=; b=dnOXf0OvKldT6SvL/pXKXZxzrReke+Oateuf+eKr7yMVeqDhX28GtgK3ij1yQVwTyY YNwR+lrdNlqtBsxxDd7K+J6cg7a1x39w7xglSB5vHW5+4TbUldUa/lCvOH5l5bvH3yKT ek4YtBf2TKay2BaAWpCW/rPmFdkZmbP9m3zatsmw1jQ7mFKajJpCrxxLQz9bdKdzctEt BGo6gbwaCX6eaXi2v9NdAKGmlEpV2A6JdOQLJphTkvcPxCWnI+A+kvt6wcccbUkx10tE v6CJ+lxtUS8ryeOHIVKMGWHTpLD68qZP06+5mWyg8ntW51On1yPstpM7360Tmnn38A8N gPXg== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM530GlCQwTHZtQ/kDLJqfrxGpuNfdjprHB167CzdJfex5Vj7EghUi gBWyrcdrrsYPfRGlBXzUGZQ= X-Google-Smtp-Source: ABdhPJxSUNnVbrGW3oK0tzXWyZwuz9DnYDXratjlvoBp0jez58cZicGgIiUofaFouA4MLB1QPSJKFw== X-Received: by 2002:a4a:6759:: with SMTP id j25mr12136oof.14.1598954752158; Tue, 01 Sep 2020 03:05:52 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a9d:4a97:: with SMTP id i23ls176424otf.7.gmail; Tue, 01 Sep 2020 03:05:49 -0700 (PDT) X-Received: by 2002:a9d:3407:: with SMTP id v7mr817291otb.117.1598954749401; Tue, 01 Sep 2020 03:05:49 -0700 (PDT) In-Reply-To: <87d035yh4n.fsf-9EawChwDxG8hFhg+JK9F0w@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:26031 Archived-At: ------=_Part_118_1956936245.1598954747947 Content-Type: multipart/alternative; boundary="----=_Part_119_1935419008.1598954747947" ------=_Part_119_1935419008.1598954747947 Content-Type: text/plain; charset="UTF-8" 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/667487b4-f213-45c7-94fd-c0237d8b6592n%40googlegroups.com. ------=_Part_119_1935419008.1598954747947 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
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 skre= v 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/667487b4-f213-45c7-94fd-c0237d8b6592n%40googlegroups.= com.
------=_Part_119_1935419008.1598954747947-- ------=_Part_118_1956936245.1598954747947--