From a8220679039f214b0642e598fab1d3b470383eb4 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 26 Sep 2020 14:26:06 -0700 Subject: Fix short-title. We were getting null short-titles generated, and that was creating wrong citations in some cases. Close #6702. --- src/Text/Pandoc/Citeproc/BibTeX.hs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/Text/Pandoc/Citeproc') diff --git a/src/Text/Pandoc/Citeproc/BibTeX.hs b/src/Text/Pandoc/Citeproc/BibTeX.hs index 5919fee77..607442adb 100644 --- a/src/Text/Pandoc/Citeproc/BibTeX.hs +++ b/src/Text/Pandoc/Citeproc/BibTeX.hs @@ -263,13 +263,12 @@ itemToReference locale variant item = do B.toList . resolveKey lang <$> getTitle "series") <|> return Nothing - shortTitle' <- Just <$> - ((guard (not hasMaintitle || isChapterlike) >> - getTitle "shorttitle") - <|> if (subtitle' /= mempty || titleaddon' /= mempty) && - not hasMaintitle - then getShortTitle False "title" - else getShortTitle True "title") + shortTitle' <- (Just <$> (guard (not hasMaintitle || isChapterlike) >> + getTitle "shorttitle")) + <|> (if (subtitle' /= mempty || titleaddon' /= mempty) && + not hasMaintitle + then getShortTitle False "title" + else getShortTitle True "title") <|> return Nothing eventTitle' <- Just <$> getTitle "eventtitle" <|> return Nothing @@ -747,12 +746,12 @@ getTitle f = do let processTitle = if utc then unTitlecase (Just lang) else id return $ processTitle ils -getShortTitle :: Bool -> Text -> Bib Inlines +getShortTitle :: Bool -> Text -> Bib (Maybe Inlines) getShortTitle requireColon f = do ils <- splitStrWhen (==':') . B.toList <$> getTitle f if not requireColon || containsColon ils - then return $ B.fromList $ upToColon ils - else return mempty + then return $ Just $ B.fromList $ upToColon ils + else return Nothing containsColon :: [Inline] -> Bool containsColon xs = Str ":" `elem` xs -- cgit v1.2.3