public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Confused about filters, new style and classic style writers
@ 2022-06-17 11:23 A A
       [not found] ` <CAMwawgMV52MstXs800EgkT_K99tzRn0GaOsjauT2HkZrEckN5A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: A A @ 2022-06-17 11:23 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- 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 --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* AW: Confused about filters, new style and classic style writers
       [not found] ` <CAMwawgMV52MstXs800EgkT_K99tzRn0GaOsjauT2HkZrEckN5A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2022-06-22 15:40   ` denis.maier-NSENcxR/0n0
  0 siblings, 0 replies; 2+ messages in thread
From: denis.maier-NSENcxR/0n0 @ 2022-06-22 15:40 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- 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 --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-22 15:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-17 11:23 Confused about filters, new style and classic style writers A A
     [not found] ` <CAMwawgMV52MstXs800EgkT_K99tzRn0GaOsjauT2HkZrEckN5A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-06-22 15:40   ` AW: " denis.maier-NSENcxR/0n0

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).