git.iko.soy/typeable/pandoc
on master help sign in
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.

commit1175b0a008bbd35dd424dc82fc05dcc665a3a75f authorAlbert Krewinkel <albert@zeitkraut.de> dateMon 2 Nov 2020, 14:37 (6 years ago) parentea45837
1 file changed+5−3
src/Text/Pandoc/Filter.hs+5−3
src/Text/Pandoc/Filter.hs+5−3
@@ -47,11 +47,13 @@ instance FromYAML Filter where
4747 parseYAML node =
4848 (withMap "Filter" $ \m -> do
4949 ty <- m .: "type"
50− fp <- m .: "path"
50+ fp <- m .:? "path"
51+ let missingPath = fail $ "Expected 'path' for filter of type " ++ show ty
52+ let filterWithPath constr = maybe missingPath (return . constr . T.unpack)
5153 case ty of
5254 "citeproc" -> return CiteprocFilter
53− "lua" -> return $ LuaFilter $ T.unpack fp
54− "json" -> return $ JSONFilter $ T.unpack fp
55+ "lua" -> filterWithPath LuaFilter fp
56+ "json" -> filterWithPath JSONFilter fp
5557 _ -> fail $ "Unknown filter type " ++ show (ty :: T.Text)) node
5658 <|>
5759 (withStr "Filter" $ \t -> do