public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: <denis.maier-NSENcxR/0n0@public.gmane.org>
To: <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: AW: Confused about filters, new style and classic style writers
Date: Wed, 22 Jun 2022 15:40:07 +0000	[thread overview]
Message-ID: <869e16a421e04fc18e8d5dcc5d0ff811@unibe.ch> (raw)
In-Reply-To: <CAMwawgMV52MstXs800EgkT_K99tzRn0GaOsjauT2HkZrEckN5A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

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

Have a look at this example : https://gist.github.com/tarleb/5a9c3fbfa47b0e6d3643efd8af2994b9

Maybe that helps?

Von: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> Im Auftrag von A A
Gesendet: Freitag, 17. Juni 2022 13:24
An: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Betreff: Confused about filters, new style and classic style writers


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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAMwawgMV52MstXs800EgkT_K99tzRn0GaOsjauT2HkZrEckN5A%40mail.gmail.com<https://groups.google.com/d/msgid/pandoc-discuss/CAMwawgMV52MstXs800EgkT_K99tzRn0GaOsjauT2HkZrEckN5A%40mail.gmail.com?utm_medium=email&utm_source=footer>.

-- 
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/869e16a421e04fc18e8d5dcc5d0ff811%40unibe.ch.

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

      parent reply	other threads:[~2022-06-22 15:40 UTC|newest]

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

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=869e16a421e04fc18e8d5dcc5d0ff811@unibe.ch \
    --to=denis.maier-nsencxr/0n0@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).