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.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAMwawgMV52MstXs800EgkT_K99tzRn0GaOsjauT2HkZrEckN5A%40mail.gmail.com.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/869e16a421e04fc18e8d5dcc5d0ff811%40unibe.ch.