aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Lua
AgeCommit message (Collapse)AuthorFilesLines
2018-01-05data/pandoc.lua: fix attribute names of CitationAlbert Krewinkel1-6/+6
The fields were named like the Haskell fields, not like the documented, shorter version. The names are changed to match the documentation and Citations are given a shared metatable to enable simple extensibility. Fixes: #4222
2018-01-04Use hslua utils where possibleAlbert Krewinkel4-33/+16
Some helper functions and types have been moved to hslua. Change: minor
2018-01-01Lua.Module.Utils: make stringify work on MetaValues.John MacFarlane1-1/+4
I'm sure this was intended in the first place, but currently only Meta is supported.
2017-12-29data/pandoc.lua: drop function pandoc.global_filterAlbert Krewinkel2-2/+1
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-23Lua modules: add function pandoc.utils.hierarchicalizeAlbert Krewinkel2-8/+39
Convert list of Pandoc blocks into (hierarchical) list of Elements.
2017-12-23Lua modules: add function pandoc.utils.normalize_dateAlbert Krewinkel2-2/+14
The function parses a date and converts it (if possible) to "YYYY-MM-DD" format.
2017-12-23Lua modules: add function pandoc.utils.to_roman_numeralAlbert Krewinkel1-1/+9
The function allows conversion of numbers below 4000 into roman numerals.
2017-12-22Lua modules: add stringify function to pandoc.utilsAlbert Krewinkel1-6/+35
The new function `pandoc.utils.stringify` converts any AST element to a string with formatting removed.
2017-12-22Lua.Util: avoid altering the stack if peeking failsAlbert Krewinkel1-4/+12
The stack now remains unaltered if `getRawInt` or `getTable` fail. This is important when those functions are used in an operation that is part of an Alternative. Change: minor
2017-12-21Lua modules: added pandoc.utils moduleAlbert Krewinkel3-8/+52
A new module `pandoc.utils` has been created. It holds utility functions like `sha1`, which was moved from the main `pandoc` module.
2017-12-21Lua modules: make a Haskell module for each Lua moduleAlbert Krewinkel3-74/+112
Definitions for the `pandoc.mediabag` modules are moved to a separate Haskell module. Change: minor
2017-12-21Lua modules: move to dedicated submoduleAlbert Krewinkel3-33/+32
The Haskell module defining the Lua `pandoc` module is moved to Text.Pandoc.Lua.Module.Pandoc. Change: minor
2017-12-20Lua modules: turn pipe, read into full Haskell functionsAlbert Krewinkel2-31/+77
The `pipe` and `read` utility functions are converted from hybrid lua/haskell functions into full Haskell functions. This avoids the need for intermediate `_pipe`/`_read` helper functions, which have dropped.
2017-12-18Lua filters: perform minor code clean-upAlbert Krewinkel2-11/+8
Change: minor
2017-12-13Custom writer: use init file to setup Lua interpreterAlbert Krewinkel1-0/+79
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-10Lua filters: fix package loading for Lua 5.1Albert Krewinkel1-1/+4
The list of package searchers is named `package.loaders` in Lua 5.1 and LuaJIT, and `package.searchers` in Lua 5.2 and later.
2017-12-06Lua filters: use script to initialize the interpreterAlbert Krewinkel1-3/+4
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 Krewinkel3-33/+148
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-12-01Lua/StackInstances: push Pandoc and Meta via constructorAlbert Krewinkel1-7/+5
Pandoc and Meta elements are now pushed by calling the respective constructor functions of the pandoc Lua module. This makes serialization consistent with the way blocks and inlines are pushed to lua and allows to use List methods with the `blocks` value.
2017-12-01List.lua: add missing fixes as discussed in #4099Albert Krewinkel1-1/+1
The changes were missing due to an error while using git.
2017-11-28Add basic lua List module (#4099)Albert Krewinkel1-5/+23
The List module is automatically loaded, but not assigned to a global variable. It can be included in filters by calling `List = require 'List'`. Lists of blocks, lists of inlines, and lists of classes are now given `List` as a metatable, making working with them more convenient. E.g., it is now possible to concatenate lists of inlines using Lua's concatenation operator `..` (requires at least one of the operants to have `List` as a metatable): function Emph (emph) local s = {pandoc.Space(), pandoc.Str 'emphasized'} return pandoc.Span(emph.content .. s) end Closes: #4081
2017-11-11Functor instance to fix ghc 7.8 warning.John MacFarlane1-1/+1
2017-11-11Add lua filter functions to walk inline and block elements.John MacFarlane2-1/+189
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-27hlint suggestions.John MacFarlane1-10/+10
2017-10-27Automatic reformating by stylish-haskell.John MacFarlane3-16/+17
2017-10-26update years in copyrightKolen Cheung1-1/+1
2017-10-05Use hslua v0.9.0Albert Krewinkel1-12/+1
2017-10-03pandoc.lua: use wrapper funciton for pipe commandAlbert Krewinkel1-1/+1
The pipe command is wrapped in a lua function, throwing a lua error if the command returns with an error. A wrapper is needed as Haskell functions exposed to lua may not throw lua errors due to limitations of hslua. The error handling is written such that a table can be returned as an error object in the future. This is potentially useful when finer control is required while catching the error in lua code. Current limitations of hslua require error objects to be strings.
2017-10-03Lua.PandocModule: promote addFunction to top levelAlbert Krewinkel1-14/+10
This reduces some boilerplate.
2017-10-01Lua: added 'pipe', which encapsulates Text.Pandoc.Process.pipeProcess.John MacFarlane1-0/+17
This is hard to do in lua, so it's helpful to provide this.
2017-10-01Lua: move sha1 from pandoc.mediabag to pandoc.John MacFarlane1-1/+3
2017-09-30Lua: use sha1 instead of hashname.John MacFarlane1-13/+5
Better to leave control over the extension to the user.
2017-09-30Lua: make fetch return mime type first and then content.John MacFarlane1-1/+1
2017-09-30Lua: simply mediabag module.John MacFarlane1-15/+31
Now 'fetch' simply fetches content and mime type. A new 'hashname' function is provided to get a filename based on the sha1 hash of the contents and the mime type.
2017-09-30Lua: make lua.mediabag.fetch return filename and mime type.John MacFarlane1-0/+4
This is necessary because you may need to insert the filename into an image or link element.
2017-09-30Lua filters: make sure whole CommonState is passed through...John MacFarlane1-9/+14
to insertResource (`fetch`).
2017-09-30Removed writerSourceURL, add source URL to common state.John MacFarlane1-4/+2
Removed `writerSourceURL` from `WriterOptions` (API change). Added `stSourceURL` to `CommonState`. It is set automatically by `setInputFiles`. Text.Pandoc.Class now exports `setInputFiles`, `setOutputFile`. The type of `getInputFiles` has changed; it now returns `[FilePath]` instead of `Maybe [FilePath]`. Functions in Class that formerly took the source URL as a parameter now have one fewer parameter (`fetchItem`, `downloadOrRead`, `setMediaResource`, `fillMediaBag`). Removed `WriterOptions` parameter from `makeSelfContained` in `SelfContained`.
2017-09-30Text.Pandoc.Lua: add mediabag submoduleAlbert Krewinkel1-14/+111
2017-09-24Allow lua filters to return lists of elementsAlbert Krewinkel1-15/+15
Closes: #3918
2017-08-16Update to hslua-0.8.0Albert Krewinkel1-2/+12
hslua no longer provides lua stack instances for Int and Double, the necessary instances are added to the Custom writer and the lua filtering system.
2017-08-13Delete Text.Pandoc.Lua.SharedInstancesAlbert Krewinkel3-56/+11
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: Optimize performance by using raw table accessAlbert Krewinkel2-17/+27
Raw table accessing functions never call back into haskell, which allows the compiler to use more aggressive optimizations. This improves lua filter performance considerably (⪆5% speedup).
2017-08-13Use hslua >= 0.7, update Lua codeAlbert Krewinkel5-395/+260
2017-08-11Added support for translations (localization) (see #3559).John MacFarlane1-3/+3
* readDataFile, readDefaultDataFile, getReferenceDocx, getReferenceODT have been removed from Shared and moved into Class. They are now defined in terms of PandocMonad primitives, rather than being primitve methods of the class. * toLang has been moved from BCP47 to Class. * NoTranslation and CouldNotLoudTranslations have been added to LogMessage. * New module, Text.Pandoc.Translations, exporting Term, Translations, readTranslations. * New functions in Class: translateTerm, setTranslations. Note that nothing is loaded from data files until translateTerm is used; setTranslation just sets the language to be used. * Added two translation data files in data/translations. * LaTeX reader: Support `\setmainlanguage` or `\setdefaultlanguage` (polyglossia) and `\figurename`.
2017-06-29Added parameter for user data directory to runLuaFilter.John MacFarlane1-5/+5
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-24Readers.getReader, Writers.getWriter API change.John MacFarlane1-2/+3
Now these functions return a pair of a reader/writer and an Extensions, instead of building the extensions into the reader/writer. The calling code must explicitly set readerExtensions or writerExtensions using the Extensions returned. The point of the change is to make it possible for the calling code to determine what extensions are being used. See #3659.
2017-06-10Changed all readers to take Text instead of String.John MacFarlane1-2/+3
Readers: Renamed StringReader -> TextReader. Updated tests. API change.
2017-06-03Improve code style in lua and org modulesAlbert Krewinkel5-32/+28
2017-05-13Update dates in copyright noticesAlbert Krewinkel3-4/+4
This follows the suggestions given by the FSF for GPL licensed software. <https://www.gnu.org/prep/maintain/html_node/Copyright-Notices.html>
2017-04-30Lua module: simplify Attributes, rename to AttrAlbert Krewinkel1-1/+1
Attributes was written to behave much like a normal table, in order to simplify working with it. However, all Attr containing elements were changed to provide panflute-like accessors to Attr components, rendering the previous approach unnecessary.