aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Lua/Module
AgeCommit message (Collapse)AuthorFilesLines
2021-12-21Lua: add new library function `pandoc.utils.type`.Albert Krewinkel1-0/+12
The function behaves like the default `type` function from Lua's standard library, but is aware of pandoc userdata types. A typical use-case would be to determine the type of a metadata value.
2021-12-21Lua: fix return types of `blocks_to_inlines`, `make_sections`Albert Krewinkel1-2/+2
Ensures the returned lists have the correct type (`Inlines` and `Blocks`, respectively).
2021-12-19Lua: fixup, should have been part of previous commitAlbert Krewinkel1-0/+3
2021-12-17Lua: add function `pandoc.utils.references`Albert Krewinkel1-0/+14
List with all cited references of a document. Closes: #7752
2021-12-10Switch to released pandoc-lua-marshal-0.1.2Albert Krewinkel1-0/+1
Cell values are now marshaled as userdata objects; a constructor function for table cells is provided as `pandoc.Cell`.
2021-12-09Lua: update to latest pandoc-lua-marshal (0.1.1)Albert Krewinkel1-18/+10
- `walk` methods are added to `Block` and `Inline` values; the methods are similar to `pandoc.utils.walk_block` and `pandoc.utils.walk_inline`, but apply to filter also to the element itself, and therefore return a list of element instead of a single element. - Functions of name `Doc` are no longer accepted as alternatives for `Pandoc` filter functions. This functionality was undocumented.
2021-11-29Lua: remove `pandoc.utils.text` (#7720)Albert Krewinkel1-8/+0
The new `pandoc.Inlines` function behaves identical on string input, but allows other Inlines-like arguments as well. The `pandoc.utils.text` function could be written as function pandoc.utils.text (x) assert(type(x) == 'string') return pandoc.Inlines(x) end
2021-11-28Lua: add constructors `pandoc.Blocks` and `pandoc.Inlines`Albert Krewinkel1-0/+2
The functions convert their argument into a list of Block and Inline values, respectively.
2021-11-27Lua: use package pandoc-lua-marshal (#7719)Albert Krewinkel4-286/+18
The marshaling functions for pandoc's AST are extracted into a separate package. The package comes with a number of changes: - Pandoc's List module was rewritten in C, thereby improving error messages. - Lists of `Block` and `Inline` elements are marshaled using the new list types `Blocks` and `Inlines`, respectively. These types currently behave identical to the generic List type, but give better error messages. This also opens up the possibility of adding element-specific methods to these lists in the future. - Elements of type `MetaValue` are no longer pushed as values which have `.t` and `.tag` properties. This was already true for `MetaString` and `MetaBool` values, which are still marshaled as Lua strings and booleans, respectively. Affected values: + `MetaBlocks` values are marshaled as a `Blocks` list; + `MetaInlines` values are marshaled as a `Inlines` list; + `MetaList` values are marshaled as a generic pandoc `List`s. + `MetaMap` values are marshaled as plain tables and no longer given any metatable. - The test suite for marshaled objects and their constructors has been extended and improved. - A bug in Citation objects, where setting a citation's suffix modified it's prefix, has been fixed.
2021-11-23Lua: add function `pandoc.utils.text` (#7710)Albert Krewinkel1-2/+10
The function converts a string to `Inlines`, treating interword spaces as `Space`s or `SoftBreak`s. If you want a `Str` with literal spaces, use `pandoc.Str`. Closes: #7709
2021-11-09Lua: fix argument order in constructor `pandoc.Cite`.Albert Krewinkel1-2/+2
This restores the old behavior; argument order had been switched accidentally in pandoc 2.15.
2021-11-06Lua: allow to pass custom reader options to `pandoc.read`Albert Krewinkel1-2/+14
Reader options can now be passed as an optional third argument to `pandoc.read`. The object can either be a table or a ReaderOptions value like `PANDOC_READER_OPTIONS`. Creating new ReaderOptions objects is possible through the new constructor `pandoc.ReaderOptions`. Closes: #7656
2021-11-02Lua: fix typo in SoftBreak constructorAlbert Krewinkel1-1/+1
2021-11-02Lua: allow omitting the 2nd parameter in pandoc.Code constructorAlbert Krewinkel1-2/+2
Fixes a regression introduced in 2.15 which required users to always specify an Attr value when constructing a Code element.
2021-10-29Lua: use hslua module abstraction where possibleAlbert Krewinkel5-231/+313
This will make it easier to generate module documentation in the future.
2021-10-27Lua: fix `pandoc.utils.stringify` regressionAlbert Krewinkel1-1/+1
The `pandoc.utils.stringify` function returned empty strings when called with a string argument.
2021-10-26Lua: marshal SimpleTable values as userdata objectsAlbert Krewinkel1-0/+2
2021-10-26Lua: generate constants in module pandoc programmaticallyAlbert Krewinkel1-0/+17
2021-10-26Lua: marshal ListAttributes values as userdata objectsAlbert Krewinkel3-2/+6
2021-10-26Lua: marshal Block values as userdata objectsAlbert Krewinkel2-31/+141
Properties of Block values are marshalled lazily, which generally improves performance considerably. Script users may also notice the following differences: - Block element properties can no longer be accessed by numerical indexing of the `.c` field. The `.c` property now serves as an alias for `.content`, so some filter that used this undocumented method for property access may continue to work, while others will need to be updated and use proper property names. - The marshalled Block elements now have a `show` method, and a `__tostring` metamethod. Both return the Haskell string representation of the element. - Block values now have the Lua type `userdata` instead of `table`.
2021-10-25Lua: marshal Citation values as userdata objectsAlbert Krewinkel2-1/+23
2021-10-23Lua: convert IOErrors to PandocErrors in pandoc.pipe functionAlbert Krewinkel1-0/+2
Fixes: #7523
2021-10-22Lua: marshal Version values as userdataAlbert Krewinkel2-4/+4
2021-10-22Lua: marshal Inline elements as userdataAlbert Krewinkel1-2/+108
This includes the following user-facing changes: - Deprecated inline constructors are removed. These are `DoubleQuoted`, `SingleQuoted`, `DisplayMath`, and `InlineMath`. - Attr values are no longer normalized when assigned to an Inline element property. - It's no longer possible to access parts of Inline elements via numerical indexes. E.g., `pandoc.Span('test')[2]` used to give `pandoc.Str 'test'`, but yields `nil` now. This was undocumented behavior not intended to be used in user scripts. Use named properties instead. - Accessing `.c` to get a JSON-like tuple of all components no longer works. This was undocumented behavior. - Only known properties can be set on an element value. Trying to set a different property will now raise an error.
2021-10-22Lua: marshal Attr values as userdataAlbert Krewinkel1-0/+3
- Adds a new `pandoc.AttributeList()` constructor, which creates the associative attribute list that is used as the third component of `Attr` values. Values of this type can often be passed to constructors instead of `Attr` values. - `AttributeList` values can no longer be indexed numerically.
2021-10-22Lua: marshal Pandoc values as userdataAlbert Krewinkel1-1/+13
2021-10-22Switch to hslua-2.0Albert Krewinkel5-184/+254
The new HsLua version takes a somewhat different approach to marshalling and unmarshalling, relying less on typeclasses and more on specialized types. This allows for better performance and improved error messages. Furthermore, new abstractions allow to document the code and exposed functions.
2021-06-10Lua utils: fix handling of table headers in `from_simple_table`Albert Krewinkel1-1/+1
Passing an empty list of header cells now results in an empty table header. Fixes: #7369
2021-05-24MediaBag improvements.John MacFarlane1-3/+3
In the current dev version, we will sometimes add a version of an image with a hashed name, keeping the original version with the original name, which would leave to undesirable duplication. This change separates the media's filename from the media's canonical name (which is the path of the link in the document itself). Filenames are based on SHA1 hashes and assigned automatically. In Text.Pandoc.MediaBag: - Export MediaItem type [API change]. - Change MediaBag type to a map from Text to MediaItem [API change]. - `lookupMedia` now returns a `MediaItem` [API change]. - Change `insertMedia` so it sets the `mediaPath` to a filename based on the SHA1 hash of the contents. This will be used when contents are extracted. In Text.Pandoc.Class.PandocMonad: - Remove `fetchMediaResource` [API change]. Lua MediaBag module has been changed minimally. In the future it would be better, probably, to give Lua access to the full MediaItem type.
2021-04-08Lua filter: respect Inlines/Blocks filter functions in pandoc.walk_*Albert Krewinkel1-3/+8
2021-02-04Lua filters: use same function names in Haskell and LuaAlbert Krewinkel2-28/+30
2021-01-26Lua: always load built-in Lua scripts from default data-dirAlbert Krewinkel1-4/+4
The Lua modules `pandoc` and `pandoc.List` are now always loaded from the system's default data directory. Loading from a different directory by overriding the default path, e.g. via `--data-dir`, is no longer supported to avoid unexpected behavior and to address security concerns.
2021-01-08Update copyright notices for 2021 (#7012)Albert Krewinkel5-5/+5
2020-09-20Lua filters: add SimpleTable for backwards compatibility (#6575)Albert Krewinkel1-5/+44
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-13Fix hlint suggestions, update hlint.yaml (#6680)Christian Despres1-3/+2
* Fix hlint suggestions, update hlint.yaml Most suggestions were redundant brackets. Some required LambdaCase. The .hlint.yaml file had a small typo, and didn't ignore camelCase suggestions in certain modules.
2020-04-17API change: use new type PandocLua for all pandoc Lua operationsAlbert Krewinkel3-89/+58
The new type `PandocLua` is an instance of the `PandocMonad` typeclass and can thus be used in a way similar to `PandocIO`.
2020-04-17API change: use PandocError for exceptions in Lua subsystemAlbert Krewinkel1-8/+11
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-03-29Clean up some fmaps (#6226)Joseph C. Sible1-1/+1
* Avoid fmapping when we're just binding right after anyway * Clean up unnecessary fmaps in the LaTeX reader
2020-03-22Finer grained imports of Text.Pandoc.Class submodules (#6203)Albert Krewinkel3-4/+6
This should speed-up recompilation after changes in `Text.Pandoc.Class`, as the number of modules affected by a change will be smaller in general. It also offers faster insights into the parts of `T.P.Class` used within a module.
2020-03-15Use implicit Prelude (#6187)Albert Krewinkel5-8/+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 Krewinkel5-5/+5
* Update copyright year * Copyright: add notes for Lua and Jira modules
2020-02-07Resolve HLint warningsAlbert Krewinkel1-1/+1
All warnings are either fixed or, if more appropriate, HLint is configured to ignore them. HLint suggestions remain. * Ignore "Use camelCase" warnings in Lua and legacy code * Fix or ignore remaining HLint warnings * Remove redundant brackets * Remove redundant `return`s * Remove redundant as-pattern * Fuse mapM_/map * Use `.` to shorten code * Remove redundant `fmap` * Remove unused LANGUAGE pragmas * Hoist `not` in Text.Pandoc.App * Use fewer imports for `Text.DocTemplates` * Remove redundant `do`s * Remove redundant `$`s * Jira reader: remove unnecessary parentheses
2020-01-04Add type annotations to assist ghci.John MacFarlane1-3/+4
2019-11-12Switch to new pandoc-types and use Text instead of String [API change].despresc3-21/+22
PR #5884. + Use pandoc-types 1.20 and texmath 0.12. + Text is now used instead of String, with a few exceptions. + In the MediaBag module, some of the types using Strings were switched to use FilePath instead (not Text). + In the Parsing module, new parsers `manyChar`, `many1Char`, `manyTillChar`, `many1TillChar`, `many1Till`, `manyUntil`, `mantyUntilChar` have been added: these are like their unsuffixed counterparts but pack some or all of their output. + `glob` in Text.Pandoc.Class still takes String since it seems to be intended as an interface to Glob, which uses strings. It seems to be used only once in the package, in the EPUB writer, so that is not hard to change.
2019-09-29Raise error on unsupported extensions. Closes #4338.John MacFarlane1-10/+15
+ An error is now raised if you try to specify (enable or disable) an extension that does not affect the given format, e.g. `docx+pipe_tables`. + The `--list-extensions[=FORMAT]` option now lists only extensions that affect the given FORMAT. + Text.Pandoc.Error: Add constructors `PandocUnknownReaderError`, `PandocUnknownWriterError`, `PandocUnsupportedExtensionError`. [API change] + Text.Pandoc.Extensions now exports `getAllExtensions`, which returns the extensions that affect a given format (whether enabled by default or not). [API change] + Text.Pandoc.Extensions: change type of `parseFormatSpec` from `Either ParseError (String, Extensions -> Extensions)` to `Either ParseError (String, [Extension], [Extension])` [API change]. + Text.Pandoc.Readers: change type of `getReader` so it returns a value in the PandocMonad instance rather than an Either [API change]. Exceptions for unknown formats and unsupported extensions are now raised by this function and need not be handled by the calling function. + Text.Pandoc.Writers: change type of `getWriter` so it returns a value in the PandocMonad instance rather than an Either [API change]. Exceptions for unknown formats and unsupported extensions are now raised by this function and need not be handled by the calling function.
2019-09-08Replace Element and makeHierarchical with makeSections.John MacFarlane2-9/+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-2/+3
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-07-02Fix redundant constraint warnings. (#5625)Pete Ryland1-1/+1
2019-06-23Update Lua function names in pandoc.systemniszet1-2/+2
Fixed function names of pandoc.system.get_working_directory() and pandoc.system.with_temporary_directory() which are written in the manual of lua filter.
2019-06-12Lua: add a `clone()` method to all AST elements (#5572)Albert Krewinkel1-0/+46
Closes: #5568