aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2021-10-04 08:50:41 -0700
committerJohn MacFarlane <[email protected]>2021-10-04 08:50:41 -0700
commita553f9fa6af4008c603c97332ce9653f60b53ce4 (patch)
tree680a9e8872f5523ac5103fe90e1318723e076a82
parent883dd9f5e9f52d15fc71b3dd980103591ea26512 (diff)
Fix name splitting in bibliography to work with no space.
-rw-r--r--src/Text/Pandoc/Citeproc/BibTeX.hs26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Citeproc/BibTeX.hs b/src/Text/Pandoc/Citeproc/BibTeX.hs
index 3fc0308f8..7da39fa42 100644
--- a/src/Text/Pandoc/Citeproc/BibTeX.hs
+++ b/src/Text/Pandoc/Citeproc/BibTeX.hs
@@ -49,7 +49,7 @@ import qualified Data.Sequence as Seq
import Data.Char (isAlphaNum, isDigit, isLetter,
isUpper, toLower, toUpper,
isLower, isPunctuation)
-import Data.List (foldl', intercalate, intersperse)
+import Data.List (foldl', intersperse)
import Safe (readMay)
import Text.Printf (printf)
import Text.DocLayout (literal, hsep, nest, hang, Doc(..),
@@ -1088,22 +1088,27 @@ getLiteralList' f = do
x' <- latex' x
case x' of
[Para xs] ->
- return $ B.fromList
- $ intercalate [Str "; "]
+ return $ mconcat
+ $ intersperse (B.str "; ")
$ splitByAnd xs
[Plain xs] ->
- return $ B.fromList
- $ intercalate [Str "; "]
+ return $ mconcat
+ $ intersperse (B.str "; ")
$ splitByAnd xs
_ -> mzero
Nothing -> notFound f
-splitByAnd :: [Inline] -> [[Inline]]
-splitByAnd = splitOn [Str " and "]
+splitByAnd :: [Inline] -> [Inlines]
+splitByAnd =
+ map B.fromList . splitWhen (== Str " and ") . foldr splitOnAnd []
+ where
+ splitOnAnd (Str t) =
+ (intersperse (Str " and ") (map Str (T.splitOn " and " t)) ++)
+ splitOnAnd x = (x :)
toLiteralList :: [Block] -> Bib [Inlines]
toLiteralList [Para xs] =
- return $ map B.fromList $ splitByAnd xs
+ return $ splitByAnd xs
toLiteralList [Plain xs] = toLiteralList [Para xs]
toLiteralList _ = mzero
@@ -1132,8 +1137,9 @@ getNameList opts f = do
toNameList :: Options -> [Block] -> Bib [Name]
toNameList opts [Para xs] =
- filter (/= emptyName) <$> mapM (toName opts . addSpaceAfterPeriod)
- (splitByAnd xs)
+ filter (/= emptyName) <$>
+ mapM (toName opts . addSpaceAfterPeriod . B.toList)
+ (splitByAnd xs)
toNameList opts [Plain xs] = toNameList opts [Para xs]
toNameList _ _ = mzero