From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/26030 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Albert Krewinkel Newsgroups: gmane.text.pandoc Subject: Re: Pandoc Lua script to filter specific markdown sub sections during PDF generation Date: Tue, 01 Sep 2020 11:35:04 +0200 Message-ID: <87d035yh4n.fsf@zeitkraut.de> References: <4e07ae0a-dcb1-4f89-8b91-ba787b7bea1cn@googlegroups.com> <92ac8df6-b88a-b047-b9f0-1fe62873b710@mailbox.org> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17009"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBCZJF7XJTILRBUFLXD5AKGQELAOK4WI-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Tue Sep 01 11:35:15 2020 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-qv1-f58.google.com ([209.85.219.58]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kD2h9-0004Gm-75 for gtp-pandoc-discuss@m.gmane-mx.org; Tue, 01 Sep 2020 11:35:15 +0200 Original-Received: by mail-qv1-f58.google.com with SMTP id p20sf539023qvl.4 for ; Tue, 01 Sep 2020 02:35:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1598952914; cv=pass; d=google.com; s=arc-20160816; b=phFTMhhXuVbNG28Zn7FQGIUDyhBeuhk8aDDhHrP6tRwtISKIaewnqozoKlrFkCB1Zn BvWwLBcqaAEckPAyFrChGpIgYwMFLSUANwtCwXg8E4+K1ev9Bld3QQCVqRC2opczVo5Y KkfIAd6mJU2L0gacUDv9AUz0GxZFwIW2EJP+yUdcAHJnxsZwK0vAj9ck2v939nSFdjax slpTYWzqN2cJ9GY25ONoX0++sOcCfbvYAaDoCtuI97G153sp3xFLF6nPCEhFDfK/56gt /dI8Xee0CFvpBB5JFe3P/HOc3HiCmFuYelju0veoWfe/SVhlREgSu4mQEEE41LgmDHOw J5Fg== 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:mime-version:message-id :date:in-reply-to:subject:to:from:references:sender:dkim-signature; bh=rkodwuTCQaW4M+rbGuj6ahPa20k2zwqzFBhLWeou+ws=; b=bcau6/9UuzFzcN+P7/yaUpvCzSBznrPU06+hZkA9NBM3K4ogIirB0dZEXadAlcBxQF 2e1hSoJAg6BWfrQnIT/gmhBDKKbzX5J/IJMdf6+7Tlf3GhlhKLIt+7G7zH+jGGk+Jb/J bH8b7GiNXl0DH5BkvqzuNVes/OPD7R4eSjXOtxOxDSEAysl2B551L5XTtCBJa7RBFg4Y 1LKeLZhy71yCxCMTP3zeC0K4XBrxwaDKR+qzjVQVQrUFTs9lwtdOgWR40BR1/5QsFteL cVwAzZzMktUAqUw8nWZD1noVBJKUWwMFwcD+b+KPcAmPUCVCmB+0zUDq8DsLOn3Dt2M1 tfFw== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 80.241.56.172 as permitted sender) smtp.mailfrom=albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:references:from:to:subject:in-reply-to:date:message-id :mime-version: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=rkodwuTCQaW4M+rbGuj6ahPa20k2zwqzFBhLWeou+ws=; b=Wp05+NMI7KANX3OCSxW8xZdqj/7vQdmOx/glUSEZZcV+GPzX4YcUhT+TWzh+3nfim8 A7qqUyP2yfTxkMelKCHXUSj+CS7yOxHesFKvmuac2yHCgCQz+YvKc5w/PY2zrsXTSY9a HPF0Prpz37S1ddeJMOpYDRzTB/UYTL8kxJvCA2PHClci3TEEd+JUqO8aCesB5M2nqWBD 3jlpMUJr4fUtEELmXuS/XHV6BqgqW9DxzSqIHyHh6/8DKiE/kqzy32YJIsE/t4C0na9T a2vLNQQQnCaD9MmFVpu3PeJxyKooRQmNG6ycCIHI9sEpl5kdONQNgbi6Y8FltEX00BKx yJeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:references:from:to:subject:in-reply-to :date:message-id:mime-version: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=rkodwuTCQaW4M+rbGuj6ahPa20k2zwqzFBhLWeou+ws=; b=g8geZP7YPR3WKD7ft3r8265UGQ3i0yaG6K8b758r/QIpt98pUD5X36pIkwY8/SGqoY Lik5CZKkPRZeSZ3k9cQ5WfIw17r4EiQHUJ8pkegMCMYDC+wqg9ihyT6k59uILH4YlUOz aiPhK99N0kZ/IywpjnQsz9zAyPTUwXT3o42p4c0UScpw3fP52nR82BhTrz0kQXotaf4G xKnYl1wgh4MFB7nM40VcGOd3emLFEgMq5Qfbui22N9w8tILDxGShG8DSKWibOEObCox8 EkSBv6F4VVYl9YA2fXO+zw8WZI+KUh9rL/O2rNicxcbqB2mIZCmvUW5XU+JlFKU/wcBP AZuw== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM532bhcdSmej2IM8nORLvzOxrwKU0YUEmWcoivD7gEgwnLxuY3Gof 6LDRvuYQE2WRCzKT4oMsXQI= X-Google-Smtp-Source: ABdhPJxdktV1Zv/CFlKTCNwNYiR2++DQTNeFT19v78Ma+WM3TLO8+UgH3yfUlGnUbwRojsEmeuBgGg== X-Received: by 2002:ae9:dc86:: with SMTP id q128mr904734qkf.451.1598952914282; Tue, 01 Sep 2020 02:35:14 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:620a:131a:: with SMTP id o26ls279309qkj.10.gmail; Tue, 01 Sep 2020 02:35:12 -0700 (PDT) X-Received: by 2002:a37:9b82:: with SMTP id d124mr961236qke.8.1598952911976; Tue, 01 Sep 2020 02:35:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598952911; cv=none; d=google.com; s=arc-20160816; b=GeuNExVuIvM5W3NRTl7ziW7RYnSafuFBFatwYBm9vvWxIYU9CY97A9gcahX0YRZnOq +XH+p2deS9dFusFriCq3yLN2KhGmS7Shq9IBiN63wZNOcYPLgMlGQCKY6P9nkRVtONEJ eI1zTGRJRbx+cDJ2oPuiedFxmlRHALI7DvbDvsho+UZwbHd5frceZx26J7hXDhk+ekiI y9DOopCc+RuXmjyDSC5x5NWr4YwU/HyI1M1kLm90P0VZ/x7SsPPsq9yeaPb2BGa+9sFi bM2MPUhSI3ihGZ0abT2YNWk/1qcbbpHwYJzVjjNl686htey6aXylbWgvlAeT0wRk6z62 vbGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:message-id:date:in-reply-to:subject:to:from:references; bh=cIeUqi4G298rhtiPnVqgp8seQ55M4/OvJlcN9oC1ack=; b=WkWHte2cw+JZvocF/SM9VV/Q8a3c65MnP28WA2GCTPz3it1MqNMLHI3XYxqCqbcnPO x7oHsvRwqoJoO6SiMQu72ginohSrqQr1dkc0M+wVoSHFeuYufJ7tPcPTTpdyn05X22lN wYJTiGxUyTsVo0CcFQx2OCEUUoxXy7hyy6INzW2pWBmhj7vdCAJMiPrmXCPzCJ84bnJz wHDugNYA+XyzU55b7LIB8f88wxuI3x81hROTkwkMXjeiSxGpeHHUmlcQBqvHOALPut+3 Mw3PkZQ6Q08SuVHM99TzbQZgKRVg/4N2IrfQ8j2OVMXtjbLNAswJI4QngWd+FbD9nQIF p35w== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 80.241.56.172 as permitted sender) smtp.mailfrom=albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org Original-Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org. [80.241.56.172]) by gmr-mx.google.com with ESMTPS id k6si39793qkg.6.2020.09.01.02.35.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 02:35:11 -0700 (PDT) Received-SPF: pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 80.241.56.172 as permitted sender) client-ip=80.241.56.172; Original-Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4BghkP5RKQzQkjT for ; Tue, 1 Sep 2020 11:35:09 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Original-Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id I7QhwtKHw2F9 for ; Tue, 1 Sep 2020 11:35:05 +0200 (CEST) In-reply-to: <92ac8df6-b88a-b047-b9f0-1fe62873b710-cl+VPiYnx/1AfugRpC6u6w@public.gmane.org> X-Rspamd-Score: -5.80 / 15.00 / 15.00 X-Rspamd-Queue-Id: 6BF677A7 X-Rspamd-UID: db7b83 X-Original-Sender: albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 80.241.56.172 as permitted sender) smtp.mailfrom=albert+pandoc-9EawChwDxG8hFhg+JK9F0w@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:26030 Archived-At: 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