summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2022-08-13 16:47:16 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2022-08-13 16:47:16 -0700
commit4dfc30ca1020baa15a40d6b890be1a511747861c (patch)
tree1cf8abf445352f5172709649b6ee9db40fcd5935
parent55c524e83cda8ab90b3b202e32b79106b408efb0 (diff)
Server: add Default instance for Params.
-rw-r--r--pandoc.cabal1
-rw-r--r--server/PandocServer.hs22
2 files changed, 18 insertions, 5 deletions
diff --git a/pandoc.cabal b/pandoc.cabal
index 1e050ef42..996fc4de5 100644
--- a/pandoc.cabal
+++ b/pandoc.cabal
@@ -799,6 +799,7 @@ executable pandoc-server
pandoc,
aeson,
text,
+ data-default,
bytestring,
base64 >= 0.4,
servant-server,
diff --git a/server/PandocServer.hs b/server/PandocServer.hs
index 644cb0b92..5f6b47607 100644
--- a/server/PandocServer.hs
+++ b/server/PandocServer.hs
@@ -22,6 +22,7 @@ import Data.Maybe (fromMaybe)
import Data.Char (isAlphaNum)
import Data.ByteString.Lazy (fromStrict, toStrict)
import Data.ByteString.Base64
+import Data.Default
-- This is the data to be supplied by the JSON payload
-- of requests. Maybe values may be omitted and will be
@@ -36,6 +37,17 @@ data Params = Params
, template :: Maybe Text
} deriving (Show)
+instance Default Params where
+ def = Params
+ { text = ""
+ , from = Nothing
+ , to = Nothing
+ , wrapText = Nothing
+ , columns = Nothing
+ , standalone = Nothing
+ , template = Nothing
+ }
+
-- Automatically derive code to convert to/from JSON.
$(deriveJSON defaultOptions ''Params)
@@ -65,10 +77,9 @@ server = convert
:<|> pure pandocVersion
where
babelmark text' from' to' standalone' = do
- res <- convert Params{ text = text',
- from = from', to = to',
- standalone = Just standalone', wrapText = Nothing,
- columns = Nothing, template = Nothing }
+ res <- convert def{ text = text',
+ from = from', to = to',
+ standalone = Just standalone' }
return $ toJSON $ object [ "html" .= res, "version" .= pandocVersion ]
-- We use runPure for the pandoc conversions, which ensures that
@@ -98,7 +109,8 @@ server = convert
compileCustomTemplate toformat t
else return Nothing
let readeropts = def{ readerExtensions = readerExts
- , readerStandalone = isStandalone }
+ , readerStandalone = isStandalone
+ }
let writeropts = def{ writerExtensions = writerExts
, writerWrapText = fromMaybe WrapAuto (wrapText params)
, writerColumns = fromMaybe 72 (columns params)