From eb96defcc680047cbf02c32b3b09b94e0992c210 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 21 Aug 2022 21:33:52 -0700 Subject: [PATCH] pandoc-server: handle `citeproc` parameter as documented. Closes #8235. --- src/Text/Pandoc/Server.hs | 14 ++++++-------- trypandoc/trypandoc.js | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Text/Pandoc/Server.hs b/src/Text/Pandoc/Server.hs index a7c46f93f..7dfde3aa3 100644 --- a/src/Text/Pandoc/Server.hs +++ b/src/Text/Pandoc/Server.hs @@ -38,7 +38,6 @@ import qualified Control.Exception as E import Text.Pandoc.Shared (safeStrRead, headerShift, filterIpynbOutput, eastAsianLineBreakFilter, stripEmptyParagraphs) import Text.Pandoc.App.Opt ( IpynbOutput (..), Opt(..), defaultOpts ) -import Text.Pandoc.Filter (Filter(..)) import Text.Pandoc.Builder (setMeta) import Text.Pandoc.SelfContained (makeSelfContained) import System.Exit @@ -122,6 +121,7 @@ data Params = Params { options :: Opt , text :: Text , files :: Maybe (M.Map FilePath Blob) + , citeproc :: Maybe Bool } deriving (Show) instance Default Params where @@ -129,6 +129,7 @@ instance Default Params where { options = defaultOpts , text = mempty , files = Nothing + , citeproc = Nothing } -- Automatically derive code to convert to/from JSON. @@ -138,6 +139,7 @@ instance FromJSON Params where <$> parseJSON (Object o) <*> o .: "text" <*> o .:? "files" + <*> o .:? "citeproc" -- This is the API. The "/convert" endpoint takes a request body @@ -327,15 +329,11 @@ server = convert let addMetadata m' (Pandoc m bs) = Pandoc (m <> m') bs - let hasCiteprocFilter [] = False - hasCiteprocFilter (CiteprocFilter:_) = True - hasCiteprocFilter (_:xs) = hasCiteprocFilter xs - reader (text params) >>= return . transforms . addMetadata meta >>= - (if hasCiteprocFilter (optFilters opts) - then processCitations - else return) >>= + (case citeproc params of + Just True -> processCitations + _ -> return) >>= writer htmlFormat :: Maybe Text -> Bool diff --git a/trypandoc/trypandoc.js b/trypandoc/trypandoc.js index e129c251e..063a5bca7 100644 --- a/trypandoc/trypandoc.js +++ b/trypandoc/trypandoc.js @@ -83,7 +83,7 @@ function convert() { to: params.to, text: params.text, standalone: params.standalone, - filters: params.citeproc ? ["citeproc"] : [] }) + citeproc: params.citeproc }) }) .then(handleErrors) .then(response => response.text())