From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/30869 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: BPJ Newsgroups: gmane.text.pandoc Subject: Re: Converting filter to custom writer Date: Wed, 29 Jun 2022 18:23:00 +0200 Message-ID: References: Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000bf238705e29891f6" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9974"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCWMVYEK54FRB4PY6GKQMGQEDSH22HI-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Wed Jun 29 18:23:18 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-lf1-f56.google.com ([209.85.167.56]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1o6aTG-0002NW-6U for gtp-pandoc-discuss@m.gmane-mx.org; Wed, 29 Jun 2022 18:23:18 +0200 Original-Received: by mail-lf1-f56.google.com with SMTP id o7-20020a056512230700b004810a865709sf5557479lfu.3 for ; Wed, 29 Jun 2022 09:23:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1656519797; cv=pass; d=google.com; s=arc-20160816; b=J1/GIJksFmSd8wujJw+c8z/ry5WQqDJf//6WpMnvEykDprX42lMEXrRPnUciHLGye9 AP/BogoHszb9AofjBbuFoxCAfXj4NRnwGDvgNkr5GoKA2HFwqqDKHR2+isTpiI0AuRyd lgcVOXDoSnPUMCrXZvL9AKkotB9Tw5kEW0RyeBepMbaBtzBrTG0SgBj/eUhQTF/IizCa WeoEQoy1gX0PwNdwoILM+7CzAdUevnWoGz/S9KlSYfjKezYzu0L/KMgCL8f3K3KKvJKN V3Ws0x5T+1SpF8ypQETLZeeXfgWZ3D/6BgVC8BUiZi8y3OXcMiCyLO+E41obnyaoE5B6 4RGA== 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=ZE3WCSVezy7Wd0Q4F8qO4upnnthpuspbcYdPV0BU+/M=; b=V4PzDXpKMSMo3hygEE6c74O2Zrv1kpZWLdocPiEahKLE+xAKDWaAEPnl5K8p7YtIzm t7nN+3RuGRhZWtaFaH85GDf34TA6XmBNhHYowK+edatMAkkBxFww0MxuePeQbRwwAG5g okC3haALLOgXOH/OBemsBSM4oWONkcvm1jpPPj+R2Se3GtCLKO4Yu7Ff6GfM6HNJjt8j aE2kJn+k4GUgYIxsNYfnKJzSlp4wL9AWVArwC3BNhuTB9+es3uusxLkaZQIsh9luQ9Yt IMOolx8JB2pydYaKv2PeanQngg1lx/85jHj+7c0VspYuDwsdYyVcp6oCFNGw+K6+R7Oc y1gQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PKc+0NOt; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::534 as permitted sender) smtp.mailfrom=melroch-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=20210112; 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=ZE3WCSVezy7Wd0Q4F8qO4upnnthpuspbcYdPV0BU+/M=; b=LORCJmn9ackyGAve788jccCFP/gFAhTY89rNJO6Bd060mGefIH7CcS87O0CKSybTaB oJa2NxXzM/bbwaNuqXGXFiRoFPBUCT5xPWHrk0vwLPTpJKXwBqcv6RB2WKpFkBy8xzln CVSSEMDgXWf3+Y+kHTkxWdu2IoVOsDRcqQQLJ7LyHkH8aD4UOaM1TLYcW0MSbx3Dy/02 jmJK53mtDmp3u5GZ6CTRYXV6NbzV/CMuj7c5j9FwGsVeHdGA96sygXduPr0R0Ji4uf9U xxUWjtNr/9X24MnVgfx8F9SLPfHk/Y3V2omXTV9pSmnrVa22gn3ZY3etYnBa0Q4TWNb8 G5tQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=ZE3WCSVezy7Wd0Q4F8qO4upnnthpuspbcYdPV0BU+/M=; b=Qql4wbRafnxACgP3E2uWx218VILiZ3agzkeR8xOBWc5gGMP9+rSOwVoor5imm2UPti WqJpji9iQ6Kp/nkOJ16oaaFNrabeOuCfvTu6SDCJVyxtGxRbfjROTk/G8eJuphxSbbQv RgwL1DD4BJ+LrtZEmWWihIzEbGznLrnz1vXvuIwatjvDx/bmam+sRUsgbCU2JUU+t37T nCOEm7vgDbEs/VOCMyJ37XwSM87rwRNFF8UqcBIf1BSNMR31LKcS1POwT4tsFzinbZVK gyx8uSTpaTzSUC47n9VlEQzi+dhptylOG5dOeayeJ+iflr5ozHL1mAZL6fOtBW4CY6dU 8gaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=ZE3WCSVezy7Wd0Q4F8qO4upnnthpuspbcYdPV0BU+/M=; b=cmsY561CeUjNkbIY90KOxQQaI48tU8s3UL7b6YPRDnkM8GCdIE8aSkYdqutkJb96ZU uicLeyY+jdjHubhdTNVHVmfJZUAVMtCVto0HUYAEE/AbbgiKP1iJiuAG3KXGEua11wwv G0q+eSMGvaCCT5VByryV1UuH9yC1MvvSDXyKnG0jkBa014neg726QJrHHqWtENEX5A25 hVRE5YPKe83Z61IPkkCRgkqsqorMz8Cpi3m3jVqLg/DAIZARwPPgClgxD5g1dUv8u8zU DoixCXidVPwoISDeEvKXdMeawWuGMdd9OJaqiuO8GO1ofYvE0kBBas6A5/QANZTLiOwr 6fUw== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AJIora98O6YESYCwXvn0jqCzZcG3/GlhOnkeEkWNGWOv1JR2OWD5W5g2 k7aeJ+nrjqzxLuyuEeI+EI4= X-Google-Smtp-Source: AGRyM1vz8gljYi8l7H3XPdt8sy514oQAD6aIUh6kf5BzMaIwbatlbrzimD2FAa5hPTHr/WPj0Fxa7w== X-Received: by 2002:a2e:8515:0:b0:25a:7653:9fe4 with SMTP id j21-20020a2e8515000000b0025a76539fe4mr2269005lji.149.1656519797684; Wed, 29 Jun 2022 09:23:17 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6512:238e:b0:481:2fa:2826 with SMTP id c14-20020a056512238e00b0048102fa2826ls398304lfv.0.gmail; Wed, 29 Jun 2022 09:23:12 -0700 (PDT) X-Received: by 2002:a05:6512:22d4:b0:47f:706b:23b5 with SMTP id g20-20020a05651222d400b0047f706b23b5mr2673308lfu.44.1656519792548; Wed, 29 Jun 2022 09:23:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656519792; cv=none; d=google.com; s=arc-20160816; b=pLx2WoB3yhfS1e+fc3/tUGHKWOho6YlRNOmXpXEd/tkYYhSD+ORb86xOt84BZlq+cZ dxTUl7dGU/pO6jBvrSv5+G+iZWvhTn+Bq9rBWERIowd0Sm7/zhMNKnMc5wXD36BK7Klq 1PlBy+0kGdjwNkfrrwQdciZ2nbtIuFr4wMnl2rU/GaGX8816j17KotAZ3DncSKrN++fn xH6Ron+JEKVbXMYhfFF3YkgBZXUeySZDsQ4vuOMXZa7P6nzh/nkdYyZIhaQhV5uHuQTw z15TTeQVyO6lFtHtyOAEcDDquI4BKwWbqkG/SnQTGX3MbQpuGVIR2903WAiOQ5QUJrDv p5Yg== 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=kxMbZ4lnx13Yo7d0bqKuecKbOADWUHQ8CusLcNdy+CM=; b=D/cmXwzH7T/JXp8XZX0HK3T+9cTA5h9NkqBR/BOheAXaXi3u0xFqlEVZXfHNgGq9KQ rN+98lP/I25jK21HzO+SvdYembeEYoFGJnaCWH50DXXWVSoMX520oQBqsCVuNr+Edhsy N1GuUdmd8FBrEh2LLCf8Axq0PEgaQmY6WDilM9mKyGbpFniKEl3smGvIcrh6EUYXN3lI clbBydIa0Tt687R5KGNlV2IdojFT2JDElBahL9tH1RNI6ewp8svP5vN8gAy8iBaBGnLt LBUxHChUYnctKGYKIj+WPkIYgGmsHHkQ+EMkcNqxwyqbptRL8/XkgF+yiemCXp4B7hYb hJ6A== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PKc+0NOt; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::534 as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Original-Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com. [2a00:1450:4864:20::534]) by gmr-mx.google.com with ESMTPS id p15-20020a2eb98f000000b0025a8d717b7dsi807771ljp.5.2022.06.29.09.23.12 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Jun 2022 09:23:12 -0700 (PDT) Received-SPF: pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::534 as permitted sender) client-ip=2a00:1450:4864:20::534; Original-Received: by mail-ed1-x534.google.com with SMTP id k20so1531234edj.13 for ; Wed, 29 Jun 2022 09:23:12 -0700 (PDT) X-Received: by 2002:a50:fb13:0:b0:435:90d1:19ca with SMTP id d19-20020a50fb13000000b0043590d119camr5391559edq.159.1656519791681; Wed, 29 Jun 2022 09:23:11 -0700 (PDT) In-Reply-To: X-Original-Sender: melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PKc+0NOt; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::534 as permitted sender) smtp.mailfrom=melroch-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:30869 Archived-At: --000000000000bf238705e29891f6 Content-Type: text/plain; charset="UTF-8" I saw no answer to this one. Hopefully it just got lost. Apologies to anyone who already got it. Den fre 24 juni 2022 16:09BPJ <> skrev: > I have a not-so-old "pseudo-writer" implemented as a filter which mostly > injects tons of raw markup into the document tree so that the output of > the plain writer looks like my target format, returning a table of filters > at the end like this > > ``````lua > return { > { > Meta = get_config > }, > { > SmallCaps = SmallCaps, > Str = Str > }, > note_filter, > main_filter > } > `````` > > where `get_config` just extracts some info from the metadata and populates > a table declared at the top of the script which the functions in the other > filters refer to. > > Am I right that I in principle could convert this into a new style custom > writer by removing the Meta filter, replacing `return {}` above > with `local filters = {}` and adding the following at the bottom > of the script? > > ``````lua > function Writer (doc, opts) > get_config(doc.meta) > for _,filter in ipairs(filters) do > doc = doc:walk(filter) > end > doc.blocks = blocks > return pandoc.write(doc, 'plain', opts) > `````` > > (This got me thinking: what if `walk` accepted one more argument which > will be passed as an extra argument to the functions in the filters, which > could be used to pass config and/or maintain state? It somehow feels more > intuitive than defining a table outside the metadata handler which all > handlers close around.) > > (BTW the main reason that the `note_filter` is separate is that it needs > to be topdown because it counts and collects the notes, while `main_filter` > needs to be bottomup because it sometimes relies on the content of elements > already having been processed. I was very happy when I realized that this > would work!) > > -- 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/CADAJKhBPpu1%3DFnxP0byMDWGEBF-7XAV7mVc%2BTzDSPX2t2GXN%3Dg%40mail.gmail.com. --000000000000bf238705e29891f6 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I saw no answer to this one. Hopefully it just got l= ost.
Apologies to anyone who already got it.

=
Den fre 24 juni 2022 16:09BPJ <> skrev:
I have a not-so-old "= ;pseudo-writer" implemented as a filter which mostly injects=C2=A0 ton= s of raw markup into the document tree so that the output of the plain writ= er looks like my target format, returning a table of filters at the end lik= e this

``````lua
return {
=C2=A0 {
=C2=A0 =C2=A0 Meta =3D get_config
=C2=A0 },
=C2=A0 {
=C2=A0 =C2=A0 SmallCaps= =3D SmallCaps,
=C2=A0 =C2=A0 Str =3D Str
=C2=A0 },
=C2=A0 note_filter,
=C2=A0 main_filter
}
``````

where `get_= config` just extracts some info from the metadata and populates a table dec= lared at the top of the script which the functions in the other filters ref= er to.

Am I right that I= in principle could convert this into a new style custom writer by removing= the Meta filter, replacing `return {<filters>}` above with `local fi= lters =3D {<filters>}` and adding the following at the bottom of the = script?

``````lua
<= div dir=3D"auto">function Writer (doc, opts)
=C2=A0 = get_config(doc.meta)
=C2=A0 for _,filter in ipairs(f= ilters) do
=C2=A0 =C2=A0 doc =3D doc:walk(filter)
=C2=A0 end
=C2=A0 doc.blocks = =3D blocks
=C2=A0 return pandoc.write(doc, 'plai= n', opts)
``````

(This got me thinking: what if `walk` accepted one more= argument which will be passed as an extra argument to the functions in the= filters, which could be used to pass config and/or maintain state? It some= how feels more intuitive than defining a table outside the metadata handler= which all handlers close around.)

(BTW the main reason that the `note_filter` is separate is that = it needs to be topdown because it counts and collects the notes, while `mai= n_filter` needs to be bottomup because it sometimes relies on the content o= f elements already having been processed. I was very happy when I realized = that this would work!)

--
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://g= roups.google.com/d/msgid/pandoc-discuss/CADAJKhBPpu1%3DFnxP0byMDWGEBF-7XAV7= mVc%2BTzDSPX2t2GXN%3Dg%40mail.gmail.com.
--000000000000bf238705e29891f6--