Commit graph

19 commits

Author SHA1 Message Date
Albert Krewinkel
6f79042502 Add tests for search_path_separator 2021-02-02 21:04:30 -08:00
Albert Krewinkel
e0bf4bfe82 Check that all documented functions are present.
Rely on tests in the module package to check the correctness of each
function.
2021-02-02 21:04:30 -08:00
Albert Krewinkel
61b108d527 Lua: add module "pandoc.path"
The module allows to work with file paths in a convenient and
platform-independent manner.

Closes: #6001
Closes: #6565
2021-02-02 21:04:30 -08:00
Albert Krewinkel
acbea6b8c6
Lua filters: add SimpleTable for backwards compatibility (#6575)
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-09-20 15:48:31 -07:00
Albert Krewinkel
fb54f3d679
API change: use PandocError for exceptions in Lua subsystem
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-04-17 21:52:48 +02:00
Albert Krewinkel
4ede11a75f
Lua: add methods insert, remove, and sort to pandoc.List
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-11 21:31:20 +01:00
Albert Krewinkel
e98921ae57
pandoc.List.lua: make pandoc.List a callable constructor
It is now possible to construct a new List via `pandoc.List()` instead of
`pandoc.List:new()`.
2020-01-11 19:38:27 +01:00
Albert Krewinkel
57637f8aae
Add tests for pandoc.List module 2020-01-11 17:42:32 +01:00
Albert Krewinkel
d0261d7387 Lua filters: allow passing of HTML-like tables instead of Attr (#5750)
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-15 12:11:58 -07:00
John MacFarlane
9f984ff26a Replace Element and makeHierarchical with makeSections.
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
c1d058aeb1
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-09-08 22:20:19 -07:00
Albert Krewinkel
2712d3e869
Lua: traverse nested blocks and inlines in correct order
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-08-16 20:52:15 +02:00
Albert Krewinkel
11bb862767 Lua: add a clone() method to all AST elements (#5572)
Closes: #5568
2019-06-12 09:58:38 -07:00
Albert Krewinkel
6704b66c33
test/lua/module/pandoc.lua: fix non-determinism in test 2019-06-11 21:17:06 +02:00
Albert Krewinkel
7f9b32e36a
data/pandoc.lua: fix deletion of nonexistent attributes
Fixes: #5569
2019-06-11 19:48:00 +02:00
Albert Krewinkel
03b9f3d5f3
Lua pandoc module: better tests for Attr and AttributeList 2019-06-11 19:48:00 +02:00
Albert Krewinkel
f7222370af
Lua modules: test pandoc.mediabag 2019-05-30 08:44:40 +02:00
Albert Krewinkel
3c3e9a12cd
Lua Version type: shorten "version too old" message 2019-05-29 22:59:45 +02:00
Albert Krewinkel
505f5bf5d9
Lua: add Version type to simplify comparisons
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-29 10:07:43 +02:00
Albert Krewinkel
6208d4e7fc Improve output of Lua tests (#5499)
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-05-20 12:52:28 -04:00