From 096cbe698746d621bfee9607b1ab826240082a10 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Fri, 26 Oct 2018 07:12:14 +0200 Subject: Lua: allow access to pandoc state (#5015) * Lua: allow access to pandoc state Lua filters and custom writers now have read-only access to most fields of pandoc's internal state via the global variable `PANDOC_STATE`. * Lua: allow iterating through fields of PANDOC_STATE * Lua filters doc: describe CommonState * Lua filters doc: mention global variable PANDOC_STATE * Lua: add access to logs Log messages can currently only be printed, but not decomposed. --- test/command/lua-pandoc-state.lua | 11 +++++++++++ test/command/lua-pandoc-state.md | 14 ++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 test/command/lua-pandoc-state.lua create mode 100644 test/command/lua-pandoc-state.md (limited to 'test') diff --git a/test/command/lua-pandoc-state.lua b/test/command/lua-pandoc-state.lua new file mode 100644 index 000000000..5282a4c29 --- /dev/null +++ b/test/command/lua-pandoc-state.lua @@ -0,0 +1,11 @@ +function report (what, value) + print(string.format('%16s: %s', what, value)) +end +report('# input files', #PANDOC_STATE.input_files) +report('output file', PANDOC_STATE.output_file) +report('# request header', #PANDOC_STATE.request_headers) +report('resource path', table.concat(PANDOC_STATE.resource_path, ', ')) +report('source URL', PANDOC_STATE.source_url) +report('user data dir', PANDOC_STATE.user_data_dir and 'defined' or 'unset') +report('trace', PANDOC_STATE.trace) +report('verbosity', PANDOC_STATE.verbosity) diff --git a/test/command/lua-pandoc-state.md b/test/command/lua-pandoc-state.md new file mode 100644 index 000000000..33045f64a --- /dev/null +++ b/test/command/lua-pandoc-state.md @@ -0,0 +1,14 @@ +``` +% pandoc --lua-filter=command/lua-pandoc-state.lua +Hello +^D + # input files: 0 + output file: nil +# request header: 0 + resource path: . + source URL: nil + user data dir: defined + trace: false + verbosity: WARNING +

Hello

+``` -- cgit v1.2.3