pandoc-server: handle citeproc parameter as documented.

Closes #8235.
This commit is contained in:
John MacFarlane 2022-08-21 21:33:52 -07:00
parent a0d1749162
commit eb96defcc6
2 changed files with 7 additions and 9 deletions

View file

@ -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

View file

@ -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())