From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/30842 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: BPJ Newsgroups: gmane.text.pandoc Subject: Converting filter to custom writer Date: Fri, 24 Jun 2022 16:09:08 +0200 Message-ID: Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000b7084d05e2321dfb" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9324"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCWMVYEK54FRBEEL26KQMGQE23ZXPJI-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Fri Jun 24 16:09:25 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-lj1-f189.google.com ([209.85.208.189]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1o4jzx-0002Cc-3A for gtp-pandoc-discuss@m.gmane-mx.org; Fri, 24 Jun 2022 16:09:25 +0200 Original-Received: by mail-lj1-f189.google.com with SMTP id x7-20020a05651c024700b002594efe50f0sf293620ljn.21 for ; Fri, 24 Jun 2022 07:09:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1656079764; cv=pass; d=google.com; s=arc-20160816; b=x59sPcTT/A4WVYYzSzODl1TaSuwZNwe56e9HasioVRG4i07F4nWjjmnv09EFHh23E0 MOXtUmPadzFKPTie47ryrp8yNFTjVVjPSdsOnHoSmxWWsGChZ3evRnapaxMaEDnN6gWC NVjx+U7fFpWACwVdHJsswSnIcJCAjk6XlOpgi46BrF8+zvKvbcyeOKgESxe8feUfwGYB OT1Lp2zDc6DzMNmOn9EDDbAKlMUo762CwFjL8i16OgTMy4zZeTtNjDszWivKCmayxf+D 68k2bSR+rRm4ZCZ+b3YJPvQtelhWssKp8/2BzCjhXAcAffPJmAG/2GeK076EaDn4Wobr 08Jg== 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:mime-version:sender:dkim-signature:dkim-signature; bh=jXnXtt6qRqq7cRvwUypeO33CtUTJ6YtwfC7f8RIynUc=; b=KP1H8uEfBVChZl///5sNt+U648yXvqkmfu/lnhakMxeTc+DGoHYGAnEctm9L7EtkCu 4S771CuFnDbfzL3/Bng7LcF/n/+aQVOUKfoPGKzfZMUeVnVf681vRoagqFv+1WFGFXvQ tRh3yMVIHu43Dmjyy76HcvAnRssXcTXNDPLEhNbwANyPFJ09E6l6wVxQ5Xa3gcAHVn4K U10w9nVUGLcBXbjLUyBzYdBD8GrTIct5aIViLFlamAu9PisheIVTjUe24csT+ThXfgrW LCnmNIEzbaVoOXLWWWu+r7wKTEIomuo1FVjUlvqrA6ADE6M1JyIHZ8Fxk5kFZ3fWfPc5 ThhQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=JXcco7Wd; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::629 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: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=jXnXtt6qRqq7cRvwUypeO33CtUTJ6YtwfC7f8RIynUc=; b=jE49gAmJwrAdSNTU3zl6aaLgFD3PcI7stVKEkHldFpsvHxXvI5Q9oQymJMkXdqUjWa euLmywX6W9hCqVr2UOJRvPR7rs8XTbmKW6Er/0jWpVtNTuKGuujfLW4y+q+OtM4Hi9vS jrmqn8vmLxcE8++hXSyy0wiRJchOl0SewxqD6+TtmbpRBQQp8MCY/9EXEfH9RlR2nLBx Quaz+bzwuDP+QCCIVuZoU6s/INDLFXTEvRQcl36xbQJSFkhFLvowOf40tqXSgRMVi8BM D0v5DifS0Hb91f99YXcEEbJpsYpdFAfG7g6keEbvFou7Vp0j5Opn3bnlSN6JVYtbWkdu xadw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version: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=jXnXtt6qRqq7cRvwUypeO33CtUTJ6YtwfC7f8RIynUc=; b=UUzY2WXWRtnaBjNsORbN5SZKTbT3/Q1DDjXHn5PoM5jhcAtZBg2e8/WNH9z0fgzNEe hGbrTXIeHW0VFEsWufIW0xjZb/gAORttsNsM/bOdVu5v1DLk1MXiqFo8RR852EFWpfMe C1nEkRxGyhki4tmhWMHlADWb1UDE7IHjY5WMUbnuRl42V8+LXjmb0bQs9edAqvg+L/HJ HNbUz2UYGYaHbRGkckjFyni0oBZsV20RAkm+q3ceXR1RcI5I2MwpL+2xZEGsto7Gq5WW w1aHqirU/lnUaNz1GimLa2ugno04yNhhPKE6ONQlD4DYQFbIL0wcAx0M1A9ESY55CLW6 28Zw== 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: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=jXnXtt6qRqq7cRvwUypeO33CtUTJ6YtwfC7f8RIynUc=; b=yB8w04tRRDD27FDB6mMqdHI2NBYFIst8efGmbum4nc9a64orhB7Vlh1FQ3N/et0+C2 wBwZzhUa4lwpz4M83j97TnWVhQdblY+XRmQmqjU/HHhCiUcXLhqoQUdNDZFORqHBF7VZ udOMIZcGDQi5a603h5QkIecafRlOqVHPrO7rf9RzcRabQhJG9ir8tjcvGLHoyiuQ7etK yVFaU5DYrbHidWuOfRDWGHxJungj1Yquoo7glCML+mvs4kwAxtw3PR+clcV6owfGyOlj vqtsCFgGNmKad3ovpt3NnfNtjS/H5+5AsQ0gIhID/IbfuvUjBRt9czAeRvTeIW1+LJLu p+8w== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AJIora8ecblLY791yiRYV4jNgGfzYsnFVA1239Cprr1cni1fH2E8W2vj 6TOXKeplWVoMbgjWl5j5ihQ= X-Google-Smtp-Source: AGRyM1vzeOAhrk23fSh6jtO+aMNYg+1zRQF1j84b//+v1JpzBflpOBxsWK8EBLNNMe/7ZT+fIZy7jA== X-Received: by 2002:a05:651c:10b8:b0:25a:9bc0:2110 with SMTP id k24-20020a05651c10b800b0025a9bc02110mr3053403ljn.234.1656079764602; Fri, 24 Jun 2022 07:09:24 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6512:b9f:b0:47f:a2ed:7ada with SMTP id b31-20020a0565120b9f00b0047fa2ed7adals12674lfv.0.gmail; Fri, 24 Jun 2022 07:09:19 -0700 (PDT) X-Received: by 2002:a05:6512:2241:b0:479:6426:15af with SMTP id i1-20020a056512224100b00479642615afmr8903487lfu.631.1656079759649; Fri, 24 Jun 2022 07:09:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656079759; cv=none; d=google.com; s=arc-20160816; b=fkX+xZpRNXc946YScLe2XynvnZaP682ilN3Dq3q0kuhTUi8J4/X9L1E251YvB03OW6 FN5Ea+aN4AKxxT6bu7sCpP2qxYFGFdPtVIMBMOLLEtJiuE9vVFv/cr7gXYRxSCm5sKk0 grGUy/NJO34AEVywmMNh7PZQ3xlfvyY0V81Da5kd0VAkC1P0UqTnRuwKWnnUZAH6T4NT D8Dg4icLLvfob43QYwcWchAjxX65i2e80GHXvzaK4TKSgQDvtWDkMVx94Y+ak+DIoOTu 8qTL2RJ9TDLF9PZkMYXkt0DvDRIJ0KvxmtpqwKH8I4RNQkUYYF/titMt6di6epBONclz 18dA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:mime-version:dkim-signature; bh=htQWQ/RWl3uxyF3qPGbabnQFpqt/OXpIqy3K41heYPs=; b=rqdV/5zGd/V4MNRxZSE4+p1l/7vdAsyX7xMaMkJzI9AzNduyHi+ymaec+3f5VM1Itz 0TDbvSH5yH8FGxhmbEuJHKYxI4fnnZ2N/lgt2aDG90b02pF3UI43y7JSvRUH+iExuse3 GkhVNSYLwR7f4J/lyDOQWYmyvLtZ5p6F25di2FLDxk4wbTozqgtoFmmFhb2PtWFrQktT ZhgHwwSGcUf0MjZFqyHVU4YL/HFdJLs0czgJGKpJdBrcNQ5YIEdsM1rOJUfbz3d2aRjV qcKzniS2ueNo2UTeX48uLh+mwK+unSNS0+PQT69RRvSnDxZUm4O45wMtC0O2NIXprG4g +Vbw== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=JXcco7Wd; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::629 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-ej1-x629.google.com (mail-ej1-x629.google.com. [2a00:1450:4864:20::629]) by gmr-mx.google.com with ESMTPS id c19-20020a056512105300b0047fa121613csi110864lfb.1.2022.06.24.07.09.19 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Jun 2022 07:09:19 -0700 (PDT) Received-SPF: pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::629 as permitted sender) client-ip=2a00:1450:4864:20::629; Original-Received: by mail-ej1-x629.google.com with SMTP id u15so4910875ejc.10 for ; Fri, 24 Jun 2022 07:09:19 -0700 (PDT) X-Received: by 2002:a17:907:7283:b0:722:e541:f157 with SMTP id dt3-20020a170907728300b00722e541f157mr13601473ejc.269.1656079758324; Fri, 24 Jun 2022 07:09:18 -0700 (PDT) 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=JXcco7Wd; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::629 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:30842 Archived-At: --000000000000b7084d05e2321dfb Content-Type: text/plain; charset="UTF-8" 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/CADAJKhAyQY_deNGV4SN61jodEM4sLUBSa4zpdxRdXg8%2BLLMzTA%40mail.gmail.com. --000000000000b7084d05e2321dfb Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I have a not-so-old "pseudo-writer= " implemented as a filter which mostly injects=C2=A0 tons of raw marku= p 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 {
=C2=A0 {
=C2=A0 = =C2=A0 Meta =3D get_config
=C2=A0 },
=C2=A0 {
=C2=A0 =C2=A0 SmallCaps =3D Small= Caps,
=C2=A0 =C2=A0 Str =3D Str
=C2=A0 },
=C2=A0 note_filter,
=C2=A0 main_filter
}
````= ``

where `get_config` ju= st extracts some info from the metadata and populates a table declared at t= he top of the script which the functions in the other filters refer to.

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

``````lua
function Writer (doc, opts)
=C2=A0 get_config= (doc.meta)
=C2=A0 for _,filter in ipairs(filters) 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, '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 t= o 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 &= 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://group= s.google.com/d/msgid/pandoc-discuss/CADAJKhAyQY_deNGV4SN61jodEM4sLUBSa4zpdx= RdXg8%2BLLMzTA%40mail.gmail.com.
--000000000000b7084d05e2321dfb--