diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2017-10-03 15:36:23 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-10-03 15:36:23 -0400 |
| commit | 582169cdca1488ebafc2aa989d50faf1576eee7c (patch) | |
| tree | 373a9547afe8996d7d714ac71d956c99ee0f80a3 /data | |
| parent | d259e7e5b51c41b24d6ae41750a3b8d11afd1ae4 (diff) | |
| parent | 371f9b708478700992a74864985cfea0af2fd4c3 (diff) | |
| download | pandoc-582169cdca1488ebafc2aa989d50faf1576eee7c.tar.gz | |
Merge pull request #3952 from tarleb/lua-pipe-wrapper
Lua pipe wrapper
Diffstat (limited to 'data')
| -rw-r--r-- | data/pandoc.lua | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/data/pandoc.lua b/data/pandoc.lua index bce4e9326..fc83103e0 100644 --- a/data/pandoc.lua +++ b/data/pandoc.lua @@ -782,7 +782,7 @@ M.UpperAlpha = "UpperAlpha" -- assert(block.content[1].t == "Emph") function M.read(markup, format) format = format or "markdown" - local pd = pandoc.__read(format, markup) + local pd = pandoc._read(format, markup) if type(pd) == "string" then error(pd) else @@ -790,6 +790,29 @@ function M.read(markup, format) end end +--- Runs command with arguments, passing it some input, and returns the output. +-- @treturn string Output of command. +-- @usage +-- local ec, output = pandoc.pipe("sed", {"-e","s/a/b/"}, "abc") +function M.pipe (command, args, input) + local ec, output = pandoc._pipe(command, args, input) + if ec ~= 0 then + err = setmetatable( + { command = command, error_code = ec, output = output}, + { __tostring = function(e) + return "Error running " .. e.command + .. " (error code " .. e.error_code .. "): " + .. e.output + end + } + ) + -- TODO: drop the wrapping call to `tostring` as soon as hslua supports + -- non-string error objects. + error(tostring(err)) + end + return output +end + --- Use functions defined in the global namespace to create a pandoc filter. -- All globally defined functions which have names of pandoc elements are -- collected into a new table. |
