From 1175b0a008bbd35dd424dc82fc05dcc665a3a75f Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Mon, 2 Nov 2020 14:37:02 +0100 Subject: T.P.Filter: allow shorter YAML representation of Citeproc The map-based YAML representation of filters expects `type` and `path` fields. The path field had to be present for all filter types, but is not used for citeproc filters. The field can now be omitted when type is "citeproc", as described in the MANUAL. --- src/Text/Pandoc/Filter.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Filter.hs b/src/Text/Pandoc/Filter.hs index f5c1a4f76..6d4846f98 100644 --- a/src/Text/Pandoc/Filter.hs +++ b/src/Text/Pandoc/Filter.hs @@ -47,11 +47,13 @@ instance FromYAML Filter where parseYAML node = (withMap "Filter" $ \m -> do ty <- m .: "type" - fp <- m .: "path" + fp <- m .:? "path" + let missingPath = fail $ "Expected 'path' for filter of type " ++ show ty + let filterWithPath constr = maybe missingPath (return . constr . T.unpack) case ty of "citeproc" -> return CiteprocFilter - "lua" -> return $ LuaFilter $ T.unpack fp - "json" -> return $ JSONFilter $ T.unpack fp + "lua" -> filterWithPath LuaFilter fp + "json" -> filterWithPath JSONFilter fp _ -> fail $ "Unknown filter type " ++ show (ty :: T.Text)) node <|> (withStr "Filter" $ \t -> do -- cgit v1.2.3