diff options
author | John MacFarlane <jgm@berkeley.edu> | 2020-10-05 16:35:51 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2020-10-05 16:35:51 -0700 |
commit | 128991d4a43238cc92febd167b8babf38649f6e2 (patch) | |
tree | b652b5eb50946f34098b76ef6c9a5086f06e8a8f /src/Text/Pandoc/Citeproc | |
parent | 68454e08126e3212d3df1c8e5502e4edbb951c88 (diff) | |
download | pandoc-128991d4a43238cc92febd167b8babf38649f6e2.tar.gz |
Add filtering to metaValueToReference, and check other-ids field too.
Diffstat (limited to 'src/Text/Pandoc/Citeproc')
-rw-r--r-- | src/Text/Pandoc/Citeproc/MetaValue.hs | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Citeproc/MetaValue.hs b/src/Text/Pandoc/Citeproc/MetaValue.hs index 1b80c879a..13bba664d 100644 --- a/src/Text/Pandoc/Citeproc/MetaValue.hs +++ b/src/Text/Pandoc/Citeproc/MetaValue.hs @@ -102,18 +102,27 @@ dateToMetaValue date = | otherwise -> printf "%04d" y _ -> mempty -metaValueToReference :: MetaValue -> Maybe (Reference Inlines) -metaValueToReference (MetaMap m) = do +metaValueToReference :: (Text -> Bool) -- ^ predicate on IDs to include + -> MetaValue + -> Maybe (Reference Inlines) +metaValueToReference idpred (MetaMap m) = do let m' = M.mapKeys normalizeKey m id' <- M.lookup "id" m' >>= metaValueToText - type' <- (M.lookup "type" m' >>= metaValueToText) <|> pure "" - let m'' = M.delete "id" $ M.delete "type" m' - let vars = M.mapKeys toVariable $ M.mapWithKey metaValueToVal m'' - return $ Reference { referenceId = ItemId id' - , referenceType = type' - , referenceDisambiguation = Nothing - , referenceVariables = vars } -metaValueToReference _ = Nothing + let mbotherids = + case M.lookup "other-ids" m' of + Just (MetaList xs) -> map metaValueToText xs + _ -> [] + if idpred id' || any (maybe False idpred) mbotherids + then do + type' <- (M.lookup "type" m' >>= metaValueToText) <|> pure "" + let m'' = M.delete "id" $ M.delete "type" m' + let vars = M.mapKeys toVariable $ M.mapWithKey metaValueToVal m'' + return $ Reference { referenceId = ItemId id' + , referenceType = type' + , referenceDisambiguation = Nothing + , referenceVariables = vars } + else Nothing +metaValueToReference _ _ = Nothing metaValueToVal :: Text -> MetaValue -> Val Inlines metaValueToVal k v |