aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Lua.hs
AgeCommit message (Collapse)AuthorFilesLines
2020-03-15Use implicit Prelude (#6187)Albert Krewinkel1-1/+0
* Use implicit Prelude The previous behavior was introduced as a fix for #4464. It seems that this change alone did not fix the issue, and `stack ghci` and `cabal repl` only work with GHC 8.4.1 or newer, as no custom Prelude is loaded for these versions. Given this, it seems cleaner to revert to the implicit Prelude. * PandocMonad: remove outdated check for base version Only base versions 4.9 and later are supported, the check for `MIN_VERSION_base(4,8,0)` is therefore unnecessary. * Always use custom prelude Previously, the custom prelude was used only with older GHC versions, as a workaround for problems with ghci. The ghci problems are resolved by replacing package `base` with `base-noprelude`, allowing for consistent use of the custom prelude across all GHC versions.
2020-03-13Update copyright year (#6186)Albert Krewinkel1-1/+1
* Update copyright year * Copyright: add notes for Lua and Jira modules
2020-02-07Apply linter suggestions. Add fix_spacing to lint target in Makefile.John MacFarlane1-1/+0
2019-03-01Remove license boilerplate.John MacFarlane1-17/+0
The haddock module header contains essentially the same information, so the boilerplate is redundant and just one more thing to get out of sync.
2019-02-16T.P.Lua: split StackInstances into smaller Marshaling modulesAlbert Krewinkel1-1/+1
2019-02-04Add missing copyright notices and remove license boilerplate (#5112)Albert Krewinkel1-2/+2
Quite a few modules were missing copyright notices. This commit adds copyright notices everywhere via haddock module headers. The old license boilerplate comment is redundant with this and has been removed. Update copyright years to 2019. Closes #4592.
2018-10-28T.P.Lua: expose more useful internals (API change)Albert Krewinkel1-3/+11
Newly exported from Text.Pandoc.Lua: - `runFilterFile` to run a Lua filter from file; - data type `Global` and its constructors; and - `setGlobals` to add globals to a Lua environment. This module also contains `Pushable` and `Peekable` instances required to get pandoc's data types to and from Lua. Low-level Lua operation remain hidden in Text.Pandoc.Lua.
2018-10-28T.P.Lua: rename `runPandocLua` to `runLua` (API change)Albert Krewinkel1-2/+2
2018-10-28T.P.Lua: merge runLuaFilter into T.P.Filter.Lua (API change)Albert Krewinkel1-40/+0
The function `runLuaFilter` was only used in Text.Pandoc.Filter.Lua, use apply from the that module instead.
2018-10-26Text.Pandoc.Lua: move globals handling to separate moduleAlbert Krewinkel1-18/+10
2018-10-01Lua filters: report traceback when an error occursAlbert Krewinkel1-1/+2
A proper Lua traceback is added if either loading of a file or execution of a filter function fails. This should be of help to authors of Lua filters who need to debug their code.
2018-09-24Use hslua v1.0.0Albert Krewinkel1-6/+5
2018-08-12Lua: cleanup Lua utils, remove unused functions.Albert Krewinkel1-9/+7
2018-03-18Use NoImplicitPrelude and explicitly import Prelude.John MacFarlane1-0/+2
This seems to be necessary if we are to use our custom Prelude with ghci. Closes #4464.
2018-02-24Lua: register script name in global variableAlbert Krewinkel1-2/+3
The name of the Lua script which is executed is made available in the global Lua variable `PANDOC_SCRIPT_FILE`, both for Lua filters and custom writers. Closes: #4393
2018-01-19hlint code improvements.John MacFarlane1-1/+1
2018-01-12Lua filters: make PANDOC_READER_OPTIONS availableAlbert Krewinkel1-6/+11
The options which were used to read the document are made available to Lua filters via the `PANDOC_READER_OPTIONS` global.
2018-01-05Update copyright notices to include 2018Albert Krewinkel1-2/+2
2017-12-29Lua filters: stop exporting pushPandocModuleAlbert Krewinkel1-6/+0
The function `pushPandocModule` was exported by Text.Pandoc.Lua to enable simpler testing. The introduction of `runPandocLua` renders direct use of this function obsolete. (API change)
2017-12-29data/pandoc.lua: drop function pandoc.global_filterAlbert Krewinkel1-11/+7
The function `global_filter` was used internally to get the implicitly defined global filter. It was of little value to end-users, but caused unnecessary code duplication in pandoc. The function has hence been dropped. Internally, the global filter is now received by interpreting the global table as lua filter. This is a Lua API change.
2017-12-21Lua modules: move to dedicated submoduleAlbert Krewinkel1-1/+5
The Haskell module defining the Lua `pandoc` module is moved to Text.Pandoc.Lua.Module.Pandoc. Change: minor
2017-12-13Custom writer: use init file to setup Lua interpreterAlbert Krewinkel1-42/+13
The same init file (`data/init`) that is used to setup the Lua interpreter for Lua filters is also used to setup the interpreter of custom writers.lua.
2017-12-13Lua filters: drop unused code, language extensionsAlbert Krewinkel1-11/+1
2017-12-06Lua filters: use script to initialize the interpreterAlbert Krewinkel1-10/+5
The file `init.lua` is used to initialize the Lua interpreter which is used in Lua filters. This gives users the option to require libraries which they want to use in all of their filters, and to extend default modules.
2017-12-02Lua filters: refactor lua module handlingAlbert Krewinkel1-23/+42
The integration with Lua's package/module system is improved: A pandoc-specific package searcher is prepended to the searchers in `package.searchers`. The modules `pandoc` and `pandoc.mediabag` can now be loaded via `require`.
2017-11-18Lua filters: preload text module (#4077)Albert Krewinkel1-0/+2
The `text` module is preloaded in lua. The module contains some UTF-8 aware string functions, implemented in Haskell. The module is loaded on request only, e.g.: text = require 'text' function Str (s) s.text = text.upper(s.text) return s end
2017-11-11Add lua filter functions to walk inline and block elements.John MacFarlane1-147/+3
Refactored some code from Text.Pandoc.Lua.PandocModule into new internal module Text.Pandoc.Lua.Filter. Add `walk_inline` and `walk_block` in pandoc lua module.
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.