[API Change] Base custom writers on Writer type.

The `T.P.Lua.writeCustom` function changed to allow either a TextWriter
or ByteStringWriter to be returned. The global variables
`PANDOC_DOCUMENT` and `PANDOC_WRITER_OPTIONS` are no longer set when the
writer script is loaded. Both variables are still set in classic writers
before the conversion is started, so they can be used when they are
wrapped in functions.
This commit is contained in:
Albert Krewinkel
2022-10-03 08:47:32 -07:00
committed by John MacFarlane
parent 3b0e700720
commit 309163f5bc
6 changed files with 69 additions and 48 deletions
+9 -9
View File
@@ -13,19 +13,19 @@
-- produce informative error messages if your code contains
-- syntax errors.
function Writer (doc, opts)
PANDOC_DOCUMENT = doc
PANDOC_WRITER_OPTIONS = opts
loadfile(PANDOC_SCRIPT_FILE)()
return pandoc.write_classic(doc, opts)
end
local pipe = pandoc.pipe
local stringify = (require 'pandoc.utils').stringify
-- The global variable PANDOC_DOCUMENT contains the full AST of
-- the document which is going to be written. It can be used to
-- configure the writer.
local meta = PANDOC_DOCUMENT.meta
-- Choose the image format based on the value of the
-- `image_format` meta value.
local image_format = meta.image_format
and stringify(meta.image_format)
or 'png'
-- `image_format` environment variable.
local image_format = os.getenv 'image_format' or 'png'
local image_mime_type = ({
jpeg = 'image/jpeg',
jpg = 'image/jpeg',