aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Krewinkel <[email protected]>2022-09-03 22:54:45 +0200
committerJohn MacFarlane <[email protected]>2022-10-20 09:11:57 -0700
commitf711c7f2aa87d0a23866a07d04d29681208b91c3 (patch)
tree2a3b4106ab962f751f2e43f37d061502c5c1a1e8
parent5d71276ecadf9201b9548d82bb908077d28ad27d (diff)
Lua: add new module `pandoc.zip`
Allows to handle docx and epub files.
-rw-r--r--doc/lua-filters.md145
-rw-r--r--pandoc-lua-engine/pandoc-lua-engine.cabal1
-rw-r--r--pandoc-lua-engine/src/Text/Pandoc/Lua/Init.hs2
-rw-r--r--stack.yaml2
4 files changed, 150 insertions, 0 deletions
diff --git a/doc/lua-filters.md b/doc/lua-filters.md
index 0c88433ae..90daa1365 100644
--- a/doc/lua-filters.md
+++ b/doc/lua-filters.md
@@ -5281,3 +5281,148 @@ Parameters:
Returns:
- A new [Version] object.
+
+# Module pandoc.zip
+
+Functions to create, modify, and extract files from zip archives.
+
+The module can be called as a function, in which case it behaves
+like the `zip` function described below.
+
+Zip options are optional; when defined, they must be a table with
+any of the following keys:
+
+ - `recursive`: recurse directories when set to `true`;
+ - `verbose`: print info messages to stdout;
+ - `destination`: the value specifies the directory in which to
+ extract;
+ - `location`: value is used as path name, defining where files
+ are placed.
+ - `preserve_symlinks`: Boolean value, controlling whether
+ symbolic links are preserved as such. This option is ignored
+ on Windows.
+
+## Functions
+
+### Archive {#pandoc.zip.Archive}
+
+`Archive (bytestring_or_entries)`
+
+Reads an *Archive* structure from a raw zip archive or a list of
+Entry items; throws an error if the given string cannot be decoded
+into an archive.
+
+*Since: 1.0.0*
+
+Parameters:
+
+bytestring_or_entries
+: (string|{ZipEntry,...})
+
+Returns:
+
+ - (ZipArchive)
+
+### Entry {#pandoc.zip.Entry}
+
+`Entry (path, contents[, modtime])`
+
+Generates a zip Entry from a filepath, the file's uncompressed
+content, and the file's modification time.
+
+*Since: 1.0.0*
+
+Parameters:
+
+path
+: file path in archive (string)
+
+contents
+: uncompressed contents (string)
+
+modtime
+: modification time (integer)
+
+### read_entry {#pandoc.zip.read_entry}
+
+`read_entry (filepath, opts)`
+
+Generates a ZipEntry from a file or directory.
+
+*Since: 1.0.0*
+
+Parameters:
+
+filepath
+: (string)
+
+opts
+: zip options (table)
+
+Returns:
+
+ - a new zip archive entry (ZipEntry)
+
+### zip {#pandoc.zip.zip}
+
+`zip (filepaths[, options])`
+
+Package and compress the given files into a new Archive.
+
+*Since: 1.0.0*
+
+Parameters:
+
+filepaths
+: list of files from which the archive is created. ({string,...})
+
+options
+: zip options (table)
+
+Returns:
+
+ - a new archive (ZipArchive)
+
+## Types
+
+### Archive {#type-pandoc.zip.Archive}
+
+A zip archive with file entries.
+
+#### Fields
+
+`entries`
+: files in this zip archive ({Entry,...})
+
+#### Methods
+
+`extract([opts])`
+: Extract all files from this archive, creating directories as
+ needed. Note that the last-modified time is set correctly only
+ in POSIX, not in Windows. This function fails if encrypted
+ entries are present.
+
+ Use `archive:extract{destination = 'dir'}` to extract to
+ subdirectory `dir`.
+
+`bytestring()`
+: Returns the raw binary string representation of the archive.
+
+### Entry {#type-pandoc.zip.Entry}
+
+File or directory entry in a zip archive.
+
+#### Fields
+
+`path`
+: relative path, using `/` as separator
+
+`modtime`
+: modification time (seconds since unix epoch)
+
+#### Methods
+
+`contents([password])`
+: Get the uncompressed contents of a zip entry. If `password` is
+ given, then that password is used to decrypt the contents. An
+ error is throws if decrypting fails.
diff --git a/pandoc-lua-engine/pandoc-lua-engine.cabal b/pandoc-lua-engine/pandoc-lua-engine.cabal
index b20f9afc7..8ef0cca58 100644
--- a/pandoc-lua-engine/pandoc-lua-engine.cabal
+++ b/pandoc-lua-engine/pandoc-lua-engine.cabal
@@ -105,6 +105,7 @@ library
, hslua-module-system >= 1.0 && < 1.1
, hslua-module-text >= 1.0 && < 1.1
, hslua-module-version >= 1.0.3 && < 1.1
+ , hslua-module-zip >= 1.0.0 && < 1.1
, lpeg >= 1.0.1 && < 1.1
, mtl >= 2.2 && < 2.3
, pandoc >= 3.0 && < 3.1
diff --git a/pandoc-lua-engine/src/Text/Pandoc/Lua/Init.hs b/pandoc-lua-engine/src/Text/Pandoc/Lua/Init.hs
index ffe77bfde..3eeab3d7c 100644
--- a/pandoc-lua-engine/src/Text/Pandoc/Lua/Init.hs
+++ b/pandoc-lua-engine/src/Text/Pandoc/Lua/Init.hs
@@ -36,6 +36,7 @@ import qualified HsLua.Aeson
import qualified HsLua.Module.DocLayout as Module.Layout
import qualified HsLua.Module.Path as Module.Path
import qualified HsLua.Module.Text as Module.Text
+import qualified HsLua.Module.Zip as Module.Zip
import qualified Text.Pandoc.Lua.Module.Format as Pandoc.Format
import qualified Text.Pandoc.Lua.Module.MediaBag as Pandoc.MediaBag
import qualified Text.Pandoc.Lua.Module.Pandoc as Module.Pandoc
@@ -89,6 +90,7 @@ loadedModules =
, Module.Layout.documentedModule { moduleName = "pandoc.layout" }
, Module.Path.documentedModule { moduleName = "pandoc.path" }
, Module.Text.documentedModule
+ , Module.Zip.documentedModule { moduleName = "pandoc.zip" }
]
-- | Initialize the lua state with all required values
diff --git a/stack.yaml b/stack.yaml
index b1f6dd5c4..e0d795ba6 100644
--- a/stack.yaml
+++ b/stack.yaml
@@ -20,8 +20,10 @@ extra-deps:
- hslua-cli-1.2.0
- hslua-classes-2.2.0
- hslua-core-2.2.1
+- hslua-list-1.1.0
- hslua-marshalling-2.2.1
- hslua-module-version-1.0.3
+- hslua-module-zip-1.0.0
- hslua-objectorientation-2.2.1
- hslua-packaging-2.2.1
- lua-2.2.1