Just edit one block of default writer using pandoc.scaffolding.Writer

35 Views Asked by At

On my Odyssee understanding Pandoc Lua writers I just wanted to test the pandoc.scaffolding.Writer to alter the Figure Block.

I have the following MWE in Markdown:

![caption to an image](counter_plot_new_periods.png)

and the following Lua writer:

Writer = pandoc.scaffolding.Writer

Writer.Block.Figure = function(fig)
   return '\\test\n' .. Writer.Blocks(fig.content) .. '\n\\test\n'
end

Writer.Pandoc = function (doc)
  return Writer.Blocks(doc.blocks)
end

The docs state that "Writer.Pandoc renders the document’s blocks." And this website says that the Pandoc constructor represents the whole document.

But if I run the writer from the command line to convert the .txt file to Latex with

$ pandoc -t test-writer.lua ast-test.txt -o ast-test.tex

I get the error:

No render function for Block value 'Header';
define a function `Writer.Block.Header` that returns a string or Doc.
stack traceback:
    test-writer.lua:66: in function 'pandoc.scaffolding.Writer.Pandoc'
    while rendering Pandoc

So Pandoc asks me to define every Block element for the writer on my own (If I define a custom Writer.Block.Header, it asks me for Image, Plain or other missing Blocks).

Is it possible to use the pandoc.scaffolding.Writer to edit only one Block and let all others untouched so they are rendered using the default settings of the particular writer (in my case latex)?

0

There are 0 best solutions below