Replies: 2 comments
-
The conversion to a boolean would need to happen during command args parsing. The correct type is chosen if the variable is defined in a defaults file: # these will have type boolean in Lua
variables:
foo: true
bar: false I agree that it's confusing that we do the conversion for metadata but not for variables. Please open an issue for that. The But I'd reconsider my stance if the |
Beta Was this translation helpful? Give feedback.
-
A possible way around is decoding the stringified variable's value as JSON. local variables = PANDOC_WRITER_OPTIONS.variables or {}
local foo = pandoc.json.decode(tostring(variables.foo), false) I'm actually using this way around to put data structures in variables and metadata for filters and writers. |
Beta Was this translation helpful? Give feedback.
-
I guess this one is for @tarleb
I tried unsuccessfully to use a variable like
-V foo
as a boolean in Lua.Something like
-M foo
,-M foo=true
or-M foo=false
does indeed result in a boolean value for that metadata field in Lua. With-V foo
pandoc.utils.type
returns "Doc" for the value ofPANDOC_WRITER_OPTIONS.variables.foo
, but apparently that value stringifies to "true"! I find this doubly confusing as I had expected a boolean, and I would have expected a string rather than a Doc for some other value.Using a variable for a filter switch would be more convenient as it could be accessed "directly" rather than writing a Meta filter which extracts the value from metadata and assigns it to a script-wide variable before running the main filter.
Obviously I could write code which converts a Doc to a string and a string which "looks like a bool" to a bool but should that really be necessary?
Is this expected behavior or should I report it as a bug?
Beta Was this translation helpful? Give feedback.
All reactions