diff options
| -rw-r--r-- | doc/lua-filters.md | 26 | ||||
| -rw-r--r-- | pandoc-lua-engine/pandoc-lua-engine.cabal | 3 | ||||
| -rw-r--r-- | pandoc-lua-engine/src/Text/Pandoc/Lua/Module.hs | 5 | ||||
| -rw-r--r-- | pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Path.hs | 50 | ||||
| -rw-r--r-- | stack.yaml | 2 |
5 files changed, 81 insertions, 5 deletions
diff --git a/doc/lua-filters.md b/doc/lua-filters.md index 1f5998fb5..53d162a34 100644 --- a/doc/lua-filters.md +++ b/doc/lua-filters.md @@ -5314,6 +5314,32 @@ Returns: *Since: 2.12* +### exists {#pandoc.path.exists} + +`exists (path[, type])` + +Check whether there exists a filesystem object at the given path. +If `type` is given and either *directory* or *file*, then the +function returns `true` if and only if the file system object has +the given type, or if it's a symlink pointing to an object of that +type. Passing *symlink* as type requires the path itself to be a +symlink. Types other than those will cause an error. + +Parameters: + +`path` +: file path to check (string) + +`type` +: the required type of the filesystem object (string) + +Returns: + +- whether a filesystem object of type `type` exists at `path`. + (boolean) + +*Since: 3.7.1* + ### filename {#pandoc.path.filename} `filename (filepath)` diff --git a/pandoc-lua-engine/pandoc-lua-engine.cabal b/pandoc-lua-engine/pandoc-lua-engine.cabal index 5cd6c570b..59b9140d0 100644 --- a/pandoc-lua-engine/pandoc-lua-engine.cabal +++ b/pandoc-lua-engine/pandoc-lua-engine.cabal @@ -93,6 +93,7 @@ library , Text.Pandoc.Lua.Module.Log , Text.Pandoc.Lua.Module.MediaBag , Text.Pandoc.Lua.Module.Pandoc + , Text.Pandoc.Lua.Module.Path , Text.Pandoc.Lua.Module.Scaffolding , Text.Pandoc.Lua.Module.Structure , Text.Pandoc.Lua.Module.System @@ -119,7 +120,7 @@ library , hslua >= 2.3 && < 2.5 , hslua-module-doclayout>= 1.2 && < 1.3 , hslua-module-path >= 1.1 && < 1.2 - , hslua-module-system >= 1.2 && < 1.3 + , hslua-module-system >= 1.2.1 && < 1.3 , hslua-module-text >= 1.1 && < 1.2 , hslua-module-version >= 1.1 && < 1.2 , hslua-module-zip >= 1.1.3 && < 1.2 diff --git a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module.hs b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module.hs index 5d2e1040a..9966c4a45 100644 --- a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module.hs +++ b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module.hs @@ -23,7 +23,6 @@ import qualified Data.ByteString.Char8 as Char8 import qualified Lua.LPeg as LPeg import qualified HsLua.Aeson import qualified HsLua.Module.DocLayout as Module.Layout -import qualified HsLua.Module.Path as Module.Path import qualified HsLua.Module.Zip as Module.Zip import qualified Text.Pandoc.Lua.Module.CLI as Pandoc.CLI import qualified Text.Pandoc.Lua.Module.Format as Pandoc.Format @@ -32,6 +31,7 @@ import qualified Text.Pandoc.Lua.Module.JSON as Pandoc.JSON import qualified Text.Pandoc.Lua.Module.Log as Pandoc.Log import qualified Text.Pandoc.Lua.Module.MediaBag as Pandoc.MediaBag import qualified Text.Pandoc.Lua.Module.Pandoc as Module.Pandoc +import qualified Text.Pandoc.Lua.Module.Path as Pandoc.Path import qualified Text.Pandoc.Lua.Module.Scaffolding as Pandoc.Scaffolding import qualified Text.Pandoc.Lua.Module.Structure as Pandoc.Structure import qualified Text.Pandoc.Lua.Module.System as Pandoc.System @@ -84,6 +84,7 @@ submodules = , Pandoc.JSON.documentedModule , Pandoc.Log.documentedModule , Pandoc.MediaBag.documentedModule + , Pandoc.Path.documentedModule , Pandoc.Scaffolding.documentedModule , Pandoc.Structure.documentedModule , Pandoc.System.documentedModule @@ -95,8 +96,6 @@ submodules = `allSince` [2,18]) `functionsSince` ["bold", "italic", "underlined", "strikeout", "fg", "bg"]) [3, 4, 1] - , Module.Path.documentedModule { moduleName = "pandoc.path" } - `allSince` [2,12] , Module.Zip.documentedModule { moduleName = "pandoc.zip" } `allSince` [3,0] ] diff --git a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Path.hs b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Path.hs new file mode 100644 index 000000000..1d2169976 --- /dev/null +++ b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Path.hs @@ -0,0 +1,50 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TypeApplications #-} +{- | + Module : Text.Pandoc.Lua.Module.Path + Copyright : © 2019-2024 Albert Krewinkel + License : GNU GPL, version 2 or above + + Maintainer : Albert Krewinkel <[email protected]> + Stability : alpha + +Pandoc's system Lua module. +-} +module Text.Pandoc.Lua.Module.Path + ( documentedModule + ) where + +import Data.Version (makeVersion) +import HsLua +import qualified HsLua.Module.Path as MPath +import qualified HsLua.Module.System as MSystem + +-- | Push the pandoc.system module on the Lua stack. +documentedModule :: forall e. LuaError e => Module e +documentedModule = Module + { moduleName = "pandoc.path" + , moduleDescription = moduleDescription @e MPath.documentedModule + , moduleFields = + [ MPath.separator + , MPath.search_path_separator + ] + , moduleFunctions = + [ MPath.directory `since` v[2,12] + , MSystem.exists `since` v[3,7,1] + , MPath.filename `since` v[2,12] + , MPath.is_absolute `since` v[2,12] + , MPath.is_relative `since` v[2,12] + , MPath.join `since` v[2,12] + , MPath.make_relative `since` v[2,12] + , MPath.normalize `since` v[2,12] + , MPath.split `since` v[2,12] + , MPath.split_extension `since` v[2,12] + , MPath.split_search_path `since` v[2,12] + , MPath.treat_strings_as_paths `since` v[2,12] + ] + , moduleOperations = [] + , moduleTypeInitializers = [] + } + where + v = makeVersion diff --git a/stack.yaml b/stack.yaml index ea4ffe54f..7d0550bc1 100644 --- a/stack.yaml +++ b/stack.yaml @@ -11,7 +11,7 @@ packages: extra-deps: - hslua-2.4.0 - hslua-module-doclayout-1.2.0.1 -- hslua-module-system-1.2.0 +- hslua-module-system-1.2.1 - hslua-objectorientation-2.4.0 - hslua-packaging-2.3.2 - pandoc-lua-marshal-0.3.1 |
