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.
This commit is contained in:
Albert Krewinkel
2020-11-02 15:14:19 +01:00
parent ea45837372
commit 1175b0a008
+5 -3
View File
@@ -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