summaryrefslogtreecommitdiff
path: root/pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/Format.hs
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2023-01-18 12:19:49 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2023-01-18 08:59:53 -0800
commit3a0fc17880b286d5116e335ade986de91089b3da (patch)
tree5f65bff411fb55e17119c50d0911d6d454d8d0a1 /pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/Format.hs
parent671cfcd86916518ead37c868c039638e53c1239a (diff)
Lua: add function pandoc.format.extensions.
This simplifies the creation of custom readers and writers that are based on built-in formats.
Diffstat (limited to 'pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/Format.hs')
-rw-r--r--pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/Format.hs21
1 files changed, 18 insertions, 3 deletions
diff --git a/pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/Format.hs b/pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/Format.hs
index 3ebc4c03e..564ddd6d3 100644
--- a/pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/Format.hs
+++ b/pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/Format.hs
@@ -1,5 +1,6 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE TupleSections #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{- |
Module : Text.Pandoc.Lua.Marshaling.Format
@@ -14,6 +15,7 @@ module Text.Pandoc.Lua.Marshal.Format
( peekExtensions
, pushExtensions
, peekExtensionsConfig
+ , pushExtensionsConfig
, peekFlavoredFormat
) where
@@ -23,20 +25,25 @@ import Data.Maybe (fromMaybe)
import HsLua
import Text.Pandoc.Error (PandocError (..))
import Text.Pandoc.Extensions
- ( Extension, Extensions, extensionsFromList
- , getDefaultExtensions, readExtension )
+ ( Extension, Extensions, extensionsFromList, extensionsToList
+ , getDefaultExtensions, readExtension, showExtension )
import Text.Pandoc.Format
( ExtensionsConfig (..), ExtensionsDiff (..), FlavoredFormat (..)
, diffExtensions, parseFlavoredFormat)
import Text.Pandoc.Lua.PandocLua (PandocLua (unPandocLua))
--- | Retrieves an 'Extensions' set from the Lua stack.
+-- | Retrieves a single 'Extension' from the Lua stack.
peekExtension :: LuaError e => Peeker e Extension
peekExtension idx = do
extString <- peekString idx
return $ readExtension extString
{-# INLINE peekExtension #-}
+-- | Pushes an individual 'Extension' to the Lua stack.
+pushExtension :: LuaError e => Pusher e Extension
+pushExtension = pushText . showExtension
+{-# INLINE pushExtension #-}
+
-- | Retrieves an 'Extensions' set from the Lua stack.
peekExtensions :: LuaError e => Peeker e Extensions
peekExtensions = fmap extensionsFromList . peekList peekExtension
@@ -62,6 +69,14 @@ peekExtensionsConfig idx = do
, extsSupported = extsToEnable diff <> extsToDisable diff
}
+-- | Pushes an 'ExtensionsConfig' value as a table with that maps
+-- extensions to their default enabled/disabled status.
+pushExtensionsConfig :: LuaError e => Pusher e ExtensionsConfig
+pushExtensionsConfig (ExtensionsConfig def supported) =
+ pushKeyValuePairs pushExtension pushBool $
+ map (,False) (extensionsToList supported) ++
+ map (,True) (extensionsToList def)
+
instance Peekable ExtensionsConfig where
safepeek = peekExtensionsConfig