aboutsummaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorAlbert Krewinkel <[email protected]>2022-10-02 21:00:18 +0200
committerJohn MacFarlane <[email protected]>2022-10-03 08:47:32 -0700
commit309163f5bc88884b2f021ce480537d1f8c57e068 (patch)
tree27e998c87c9f0de613850d3c6c12b3b6f60466da /data
parent3b0e70072023d519cfb97d25ab668cf0284a5e24 (diff)
[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.
Diffstat (limited to 'data')
-rw-r--r--data/sample.lua18
1 files changed, 9 insertions, 9 deletions
diff --git a/data/sample.lua b/data/sample.lua
index c0adae230..aacc0d2b6 100644
--- a/data/sample.lua
+++ b/data/sample.lua
@@ -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',