mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-24 15:44:59 +08:00
[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:
committed by
John MacFarlane
parent
3b0e700720
commit
309163f5bc
+9
-9
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user