aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Filter.hs
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2020-11-02 14:37:02 +0100
committerAlbert Krewinkel <albert@zeitkraut.de>2020-11-02 15:14:19 +0100
commit1175b0a008bbd35dd424dc82fc05dcc665a3a75f (patch)
tree93b9705aba7a6d2f073b88d6a93742f650b134b8 /src/Text/Pandoc/Filter.hs
parentea458373726e7e3424617160aafcb3f7eacfd4e7 (diff)
downloadpandoc-1175b0a008bbd35dd424dc82fc05dcc665a3a75f.tar.gz
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.
Diffstat (limited to 'src/Text/Pandoc/Filter.hs')
-rw-r--r--src/Text/Pandoc/Filter.hs8
1 files changed, 5 insertions, 3 deletions
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