aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Lua.hs
AgeCommit message (Collapse)AuthorFilesLines
2017-10-27Automatic reformating by stylish-haskell.John MacFarlane1-9/+9
2017-10-05pandoc.lua: throw better error when pipe command failsAlbert Krewinkel1-3/+2
A table containing the error code, command, and command output is thrown instead of just a string error message.
2017-09-30Lua filters: make sure whole CommonState is passed through...John MacFarlane1-5/+8
to insertResource (`fetch`).
2017-09-30Text.Pandoc.Lua: add mediabag submoduleAlbert Krewinkel1-6/+30
2017-09-26Lua filters: set global FORMAT instead of args.John MacFarlane1-4/+4
This changes the type of runLuaFilter.
2017-09-26Lua: set "arg" instead of "PandocParameters".John MacFarlane1-2/+2
This is standard for lua scripts, and I see no reason to depart from the standard here. Also, "arg" is now pushed onto the stack before the script is loaded. Previously it was not, and thus "PandocParameters" was not available at the top level.
2017-09-24Allow lua filters to return lists of elementsAlbert Krewinkel1-46/+75
Closes: #3918
2017-08-23Text.Pandoc.Lua: fix fallback functions with GHC 7.8Albert Krewinkel1-2/+2
2017-08-22Text.Pandoc.Lua: support Inline and Block catch-allsAlbert Krewinkel1-6/+8
Try function `Inline`/`Block` if no other filter function of the respective type matches an element. Closes: #3859
2017-08-22Text.Pandoc.Lua: respect metatable when getting filtersAlbert Krewinkel1-52/+76
This change makes it possible to define a catch-all function using lua's metatable lookup functionality. function catch_all(el) … end return { setmetatable({}, {__index = function(_) return catch_all end}) } A further effect of this change is that the map with filter functions now only contains functions corresponding to AST element constructors.
2017-08-13Delete Text.Pandoc.Lua.SharedInstancesAlbert Krewinkel1-1/+0
Stack instances for common data types are now provides by hslua. The instance for Either was useful only for a very specific case; the function that was using the `ToLuaStack Either` instance was rewritten to work without it. Closes: #3805
2017-08-13Text.Pandoc.Lua: cleanup element walking codeAlbert Krewinkel1-28/+20
WalkM is general enough to work in any monad, not just IO. Also get rid of the LuaException type, sufficient to use the one defined in hslua.
2017-08-13Use hslua >= 0.7, update Lua codeAlbert Krewinkel1-91/+90
2017-06-29Added parameter for user data directory to runLuaFilter.John MacFarlane1-3/+3
in Text.Pandoc.Lua. Also to pushPandocModule. This change allows users to override pandoc.lua with a file in their local data directory, adding custom functions, etc. @tarleb, if you think this is a bad idea, you can revert this. But in general our data files are all overridable.
2017-06-29Text.Pandoc.Lua: more code simplification.John MacFarlane1-30/+26
Also, now we check before running walkM that the function table actually does contain something relevant. E.g. if your filter just defines Str, there's no need to run walkM for blocks, meta, or the whole document. This should help performance a bit (and it does, in my tests).
2017-06-29Lua filters: Remove special treatment of Quoted, Math.John MacFarlane1-24/+8
No more SingleQuoted, DoubleQuoted, InlineMath, DisplayMath. This makes everything uniform and predictable, though it does open up a difference btw lua filters and custom writers.
2017-06-29Text.Pandoc.Lua: refactored to remove duplicated code.John MacFarlane1-34/+25
2017-06-29Text.Pandoc.Lua: use generics to reduce boilerplate.John MacFarlane1-32/+3
I tested this with the str.lua filter on MANUAL.txt, and I could see no significant performance degradation. Doing things this way will ease maintenance, as we won't have to manually modify this module when types change. @tarleb, do we really need special cases for things like DoubleQuoted and InlineMath?
2017-06-27Text.Pandoc.Lua: catch lua errors in filter functionsAlbert Krewinkel1-11/+20
Replace lua errors with `LuaException`s.
2017-06-27Text.Pandoc.Lua: keep element unchanged if filter returns nilAlbert Krewinkel1-8/+13
This was suggested by jgm and is consistent with the behavior of other filtering libraries.
2017-06-27Text.Pandoc.Lua: simplify filter function runnerAlbert Krewinkel1-25/+11
The code still allowed to pass an arbitrary number of arguments to the filter function, as element properties were passed as function arguments at some point. Now we only pass the element as the single arg, so the code to handle multiple arguments is no longer necessary.
2017-06-20Text.Pandoc.Lua - added DeriveDataTypeable for ghc 7.8.John MacFarlane1-3/+4
2017-06-20Lua: use registry to store function referencesAlbert Krewinkel1-29/+19
Using the registry directly instead of a custom table is cleaner and more efficient. The performance improvement is especially noticable when filtering on frequent elements like Str.
2017-06-20Lua: apply hslint suggestionsAlbert Krewinkel1-33/+32
2017-06-20Text.Pandoc.Lua: throw LuaException instead of using 'error'.John MacFarlane1-5/+16
Text.Pandoc.App: trap LuaException and issue a PandocFilterError.
2017-06-03Improve code style in lua and org modulesAlbert Krewinkel1-9/+9
2017-04-30Lua filter: fall-back to global filters when none is returnedAlbert Krewinkel1-1/+12
The implicitly defined global filter (i.e. all element filtering functions defined in the global lua environment) is used if no filter is returned from a lua script. This allows to just write top-level functions in order to define a lua filter. E.g function Emph(elem) return pandoc.Strong(elem.content) end
2017-04-26Lua filter: allow filtering of meta data onlyAlbert Krewinkel1-1/+13
2017-04-18Lua: drop useless filter function type parameterAlbert Krewinkel1-28/+20
The return-type parameter for lua filter functions is removed. It only complicated the code without introducing any additional type safety.
2017-04-15Lua filter: revert to non-destructuring filtersAlbert Krewinkel1-66/+46
We want to provide an interface familiar to users of other filtering libraries.
2017-04-14Lua filter: allow shorthand functions for math and quotedAlbert Krewinkel1-3/+23
Allow to use functions named `SingleQuoted`, `DoubleQuoted`, `DisplayMath`, and `InlineMath` in filters.
2017-04-14Extract lua helper functions into Lua.Util moduleAlbert Krewinkel1-18/+2
2017-04-14Lua filter: use destructured functions for block filtersAlbert Krewinkel1-17/+23
Filtering functions take element components as arguments instead of the whole block elements. This resembles the way elements are handled in custom writers.
2017-04-14Drop dependency on hslua-aesonAlbert Krewinkel1-18/+15
Pushing values to the lua stack via custom functions is faster and more flexible.
2017-04-13Use lua constructors to push meta valuesAlbert Krewinkel1-2/+2
2017-04-12Lua filter: use destructured functions for inline filtersAlbert Krewinkel1-33/+58
Instead of taking the whole inline element, forcing users to destructure it themselves, the components of the elements are passed to the filtering functions.
2017-04-11Lua filter: use custom StackValue Inline instanceAlbert Krewinkel1-3/+5
Inline elements are no longer pushed and pulled via aeson's Value.
2017-04-04Use lua registry instead of named globalsAlbert Krewinkel1-5/+11
This is slightly cleaner while keeping performance approximately the same.
2017-04-02Lua module: add readers submoduleAlbert Krewinkel1-28/+3
Plain text readers are exposed to lua scripts via the `pandoc.reader` submodule, which is further subdivided by format. Converting e.g. a markdown string into a pandoc document is possible from within lua: doc = pandoc.reader.markdown.read_doc("Hello, World!") A `read_block` convenience function is provided for all formats, although it will still parse the whole string but return only the first block as the result. Custom reader options are not supported yet, default options are used for all parsing operations.
2017-03-20Lua filters (#3514)Albert Krewinkel1-0/+226
* Add `--lua-filter` option. This works like `--filter` but takes pathnames of special lua filters and uses the lua interpreter baked into pandoc, so that no external interpreter is needed. Note that lua filters are all applied after regular filters, regardless of their position on the command line. * Add Text.Pandoc.Lua, exporting `runLuaFilter`. Add `pandoc.lua` to data files. * Add private module Text.Pandoc.Lua.PandocModule to supply the default lua module. * Add Tests.Lua to tests. * Add data/pandoc.lua, the lua module pandoc imports when processing its lua filters. * Document in MANUAL.txt.