public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: A A <amine.aboufirass-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: Confused about filters, new style and classic style writers
Date: Fri, 17 Jun 2022 13:23:52 +0200	[thread overview]
Message-ID: <CAMwawgMV52MstXs800EgkT_K99tzRn0GaOsjauT2HkZrEckN5A@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2304 bytes --]

Hi all,

There’s something which I don’t quite understand in with respect to the
following:

   - lua writers
      - classic style
      - new style
   - lua filters

As far as I can tell, lua filters and classic style writers are pretty much
identical, basically defining Lua functions corresponding to node names,
and adding the code inside these functions. The only notable difference I
can think of is that classic style writers return raw output (i.e. strings)
from these functions, whereas filters typically return some other pandoc
object, or node in the AST, effectively modifying it during runtime.

Enter new style writers. The *only* example I have been able to find of
these writers is the one in the main documentation, and it is super
confusing:

function Writer (doc, opts)
  local filter = {
    CodeBlock = function (cb)
      -- only modify if code block has no attributes
      if cb.attr == pandoc.Attr() then
        local delimited = '```\n' .. cb.text .. '\n```'
        return pandoc.RawBlock('markdown', delimited)
      end
    end
  }
  return pandoc.write(doc:walk(filter), 'gfm', opts)
end

Here we have a global function called Writer which takes in doc, a
pandoc.Pandoc and then proceeds to defining a *filter* which it then
applies to this document using the walk method. It then uses the gfm writer
to actually generate the raw output. So basically, a writer within a writer.

I’m not sure if this is just a bad example, or whether I’m missing
something. It would have been more useful to rewrite the example provided
for classic style writers in the new style , in my opinion.

Are there any more down-to-earth examples for making writers in the new
style? Why are we defining filters inside these new style writers? Couldn’t
we just make a simple filter instead?

Regards,

Amine

-- 
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/CAMwawgMV52MstXs800EgkT_K99tzRn0GaOsjauT2HkZrEckN5A%40mail.gmail.com.

[-- Attachment #2: Type: text/html, Size: 8353 bytes --]

             reply	other threads:[~2022-06-17 11:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-17 11:23 A A [this message]
     [not found] ` <CAMwawgMV52MstXs800EgkT_K99tzRn0GaOsjauT2HkZrEckN5A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-06-22 15:40   ` AW: " denis.maier-NSENcxR/0n0

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMwawgMV52MstXs800EgkT_K99tzRn0GaOsjauT2HkZrEckN5A@mail.gmail.com \
    --to=amine.aboufirass-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).