aboutsummaryrefslogtreecommitdiff
path: root/test/lua
AgeCommit message (Collapse)AuthorFilesLines
2020-09-20Lua filters: add SimpleTable for backwards compatibility (#6575)Albert Krewinkel1-0/+66
A new type `SimpleTable` is made available to Lua filters. It is similar to the `Table` type in pandoc versions before 2.10; conversion functions from and to the new Table type are provided. Old filters using tables now require minimal changes and can use, e.g., if PANDOC_VERSION > {2,10,1} then pandoc.Table = pandoc.SimpleTable end and function Table (tbl) tbl = pandoc.utils.to_simple_table(tbl) … return pandoc.utils.from_simple_table(tbl) end to work with the current pandoc version.
2020-05-12Lua: fix regression in package searcherAlbert Krewinkel1-0/+2
This caused `require 'module'` to fail for third party packages. Fixes: #6361
2020-04-17API change: use PandocError for exceptions in Lua subsystemAlbert Krewinkel1-4/+3
The PandocError type is used throughout the Lua subsystem, all Lua functions throw an exception of this type if an error occurs. The `LuaException` type is removed and no longer exported from `Text.Pandoc.Lua`. In its place, a new constructor `PandocLuaError` is added to PandocError.
2020-01-15Lua filters: allow filtering of element lists (#6040)Albert Krewinkel3-0/+33
Lists of Inline and Block elements can now be filtered via `Inlines` and `Blocks` functions, respectively. This is helpful if a filter conversion depends on the order of elements rather than a single element. For example, the following filter can be used to remove all spaces before a citation: function isSpaceBeforeCite (spc, cite) return spc and spc.t == 'Space' and cite and cite.t == 'Cite' end function Inlines (inlines) for i = #inlines-1,1,-1 do if isSpaceBeforeCite(inlines[i], inlines[i+1]) then inlines:remove(i) end end return inlines end Closes: #6038
2020-01-11Lua: add methods `insert`, `remove`, and `sort` to pandoc.ListAlbert Krewinkel1-40/+80
The functions `table.insert`, `table.remove`, and `table.sort` are added to pandoc.List elements. They can be used as methods, e.g. local numbers = pandoc.List {2, 3, 1} numbers:sort() -- numbers is now {1, 2, 3}
2020-01-11pandoc.List.lua: make `pandoc.List` a callable constructorAlbert Krewinkel1-0/+9
It is now possible to construct a new List via `pandoc.List()` instead of `pandoc.List:new()`.
2020-01-11Add tests for pandoc.List moduleAlbert Krewinkel1-0/+111
2019-09-15Lua filters: allow passing of HTML-like tables instead of Attr (#5750)Albert Krewinkel1-0/+41
Attr values can now be given as normal Lua tables; this can be used as a convenient alternative to define Attr values, instead of constructing values with `pandoc.Attr`. Identifiers are taken from the *id* field, classes must be given as space separated words in the *class* field. All remaining fields are included as misc attributes. With this change, the following lines now create equal elements: pandoc.Span('test', {id = 'test', class = 'a b', check = 1}) pandoc.Span('test', pandoc.Attr('test', {'a','b'}, {check = 1})) This also works when using the *attr* setter: local span = pandoc.Span 'text' span.attr = {id = 'test', class = 'a b', check = 1} Furthermore, the *attributes* field of AST elements can now be a plain key-value table even when using the `attributes` accessor: local span = pandoc.Span 'test' span.attributes = {check = 1} -- works as expected now Closes: #5744
2019-09-08Replace Element and makeHierarchical with makeSections.John MacFarlane1-8/+5
Text.Pandoc.Shared: + Remove `Element` type [API change] + Remove `makeHierarchicalize` [API change] + Add `makeSections` [API change] + Export `deLink` [API change] Now that we have Divs, we can use them to represent the structure of sections, and we don't need a special Element type. `makeSections` reorganizes a block list, adding Divs with class `section` around sections, and adding numbering if needed. This change also fixes some longstanding issues recognizing section structure when the document contains Divs. Closes #3057, see also #997. All writers have been changed to use `makeSections`. Note that in the process we have reverted the change c1d058aeb1c6a331a2cc22786ffaab17f7118ccd made in response to #5168, which I'm not completely sure was a good idea. Lua modules have also been adjusted accordingly. Existing lua filters that use `hierarchicalize` will need to be rewritten to use `make_sections`.
2019-08-16Lua: traverse nested blocks and inlines in correct orderAlbert Krewinkel1-0/+38
Traversal methods are updated to use the new Walk module such that sequences with nested Inline (or Block) elements are traversed in the order in which they appear in the linearized document. Fixes: #5667
2019-06-12Lua: add a `clone()` method to all AST elements (#5572)Albert Krewinkel1-0/+38
Closes: #5568
2019-06-11test/lua/module/pandoc.lua: fix non-determinism in testAlbert Krewinkel1-4/+11
2019-06-11data/pandoc.lua: fix deletion of nonexistent attributesAlbert Krewinkel1-0/+6
Fixes: #5569
2019-06-11Lua pandoc module: better tests for Attr and AttributeListAlbert Krewinkel1-0/+65
2019-05-30Lua modules: test pandoc.mediabagAlbert Krewinkel1-0/+72
2019-05-29Lua Version type: shorten "version too old" messageAlbert Krewinkel1-1/+1
2019-05-29Lua: add Version type to simplify comparisonsAlbert Krewinkel2-0/+112
Version specifiers like `PANDOC_VERSION` and `PANDOC_API_VERSION` are turned into `Version` objects. The objects simplify version-appropriate comparisons while maintaining backward-compatibility. A function `pandoc.types.Version` is added as part of the newly introduced module `pandoc.types`, allowing users to create version objects in scripts.
2019-05-20Improve output of Lua tests (#5499)Albert Krewinkel3-138/+154
This makes use of tasty-lua, a package to write tests in Lua and integrate the results into Tasty output. Test output becomes more informative: individual tests and test groups become visible in test output. Failures are reported with helpful error messages.
2019-01-13data/pandoc.lua: auto-fix nested constructor argumentsAlbert Krewinkel1-0/+10
Incorrect types to pandoc element constructors are automatically converted to the correct types when possible. This was already done for most constructors, but conversions are now also done for nested types (like lists of lists).
2018-07-30Lua Utils module: add function blocks_to_inlines (#4799)Albert Krewinkel1-0/+15
Exposes a function converting which flattenes a list of blocks into a list of inlines. An example use case would be the conversion of Note elements into other inlines.
2018-05-08Another try at test-pandoc-utils.lua on windows.John MacFarlane1-3/+2
2018-05-08test-pandoc-utils.lua - add diagnostic for windows test.John MacFarlane1-0/+1
2018-05-08More adjustments to test-pandoc-utils.lua.John MacFarlane1-5/+4
We need to find something that will work on windows.
2018-05-08test-pandoc-utils.lua - use tr instead of sed.John MacFarlane1-1/+1
It should be installed on all *nix systems.
2018-05-08test-pandoc-utils.lua: workaround some local differences in 'echo'.John MacFarlane1-2/+2
2018-05-08test-pandoc-utils.lua: remove problems with missing `/bin/false`.John MacFarlane1-13/+22
Previously it was assumed that the system would have `/bin/false` and `/bin/sed`, and these tests were skipped otherwise. On MacOS, these utilities are located in `/usr/bin`. Fixed by just using `sed` and `false` -- these should always be in the path. Removed the "skipping" behavior, replaced with a check for Windows. On Windowns, we use `echo` and `cd`, which should always exist. Not yet checked on Windows.
2018-04-29Test Lua filter converting display math to inline mathAlexander Krotov1-0/+10
2018-02-24Lua: register script name in global variableAlbert Krewinkel1-0/+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
2017-12-23Lua modules: add function pandoc.utils.hierarchicalizeAlbert Krewinkel1-0/+16
Convert list of Pandoc blocks into (hierarchical) list of Elements.
2017-12-23Lua modules: add function pandoc.utils.normalize_dateAlbert Krewinkel1-1/+9
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-0/+9
The function allows conversion of numbers below 4000 into roman numerals.
2017-12-22Lua modules: add stringify function to pandoc.utilsAlbert Krewinkel1-3/+16
The new function `pandoc.utils.stringify` converts any AST element to a string with formatting removed.
2017-12-20Test more pandoc Lua module functionsAlbert Krewinkel1-0/+69
The functions `sha1`, `read`, and `pipe` are now tested. Change: minor
2017-11-20data/pandoc.lua: enable table-like behavior of attributes (#4080)Albert Krewinkel1-0/+6
Attribute lists are represented as associative lists in Lua. Pure associative lists are awkward to work with. A metatable is attached to attribute lists, allowing to access and use the associative list as if the attributes were stored in as normal key-value pair in table. Note that this changes the way `pairs` works on attribute lists. Instead of producing integer keys and two-element tables, the resulting iterator function now returns the key and value of those pairs. Use `ipairs` to get the old behavior. Warning: the new iteration mechanism only works if pandoc has been compiled with Lua 5.2 or later (current default: 5.3). The `pandoc.Attr` function is altered to allow passing attributes as key-values in a normal table. This is more convenient than having to construct the associative list which is used internally. Closes #4071
2017-11-18Lua filters: preload text module (#4077)Albert Krewinkel1-0/+9
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-09-24Allow lua filters to return lists of elementsAlbert Krewinkel1-0/+3
Closes: #3918
2017-08-22Text.Pandoc.Lua: support Inline and Block catch-allsAlbert Krewinkel1-0/+11
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-0/+20
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-06-29data/pandoc.lua: regularize constructors.John MacFarlane2-3/+3
We now use Pandoc instead of Doc (though Doc remains a deprecated Synonym), and we deprecate DoubleQuoted, SingleQuoted, InlineMath, and DisplayMath.
2017-06-29Lua filters: Remove special treatment of Quoted, Math.John MacFarlane1-2/+4
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-04-30Lua filter: fall-back to global filters when none is returnedAlbert Krewinkel1-0/+6
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 module: provide simple `read` format parserAlbert Krewinkel1-1/+2
A single `read` function parsing pandoc-supported formats is added to the module. This is simpler and more convenient than the previous method of exposing all reader functions individually.
2017-04-26Lua filter: allow filtering of meta data onlyAlbert Krewinkel1-0/+12
2017-04-15Lua filter: revert to non-destructuring filtersAlbert Krewinkel4-11/+12
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-0/+7
Allow to use functions named `SingleQuoted`, `DoubleQuoted`, `DisplayMath`, and `InlineMath` in filters.
2017-04-14Lua filter: use destructured functions for block filtersAlbert Krewinkel2-4/+3
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-12Lua filter: use destructured functions for inline filtersAlbert Krewinkel1-4/+5
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-02Lua module: add readers submoduleAlbert Krewinkel1-0/+12
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 Krewinkel3-0/+26
* 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.