aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers
diff options
context:
space:
mode:
authorBrian Leung <bkleung89@gmail.com>2018-09-25 20:49:13 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2018-09-25 20:49:13 -0700
commit72363cd2fc3941d921eea892d48ef5e9a4654888 (patch)
tree109cf2881a1c1ab20fe82c7aad5e9a689363f4cf /src/Text/Pandoc/Readers
parent881a1e014582b590236474e32a22aad0a57650db (diff)
downloadpandoc-72363cd2fc3941d921eea892d48ef5e9a4654888.tar.gz
Add support for multiprenote and multipostnote arguments in LaTeX. (#4930)
* Add support for multiprenote and multipostnote arguments. The multiprenotes occur before the first prefix of a multicite, and the multipostnotes follow the last suffix. * Add test for multiprenote and multipostnote.
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index 7346e9398..4a7f2f978 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -662,6 +662,11 @@ bracketed parser = try $ do
symbol '['
mconcat <$> manyTill parser (symbol ']')
+parenWrapped :: PandocMonad m => Monoid a => LP m a -> LP m a
+parenWrapped parser = try $ do
+ symbol '('
+ mconcat <$> manyTill parser (symbol ')')
+
dimenarg :: PandocMonad m => LP m Text
dimenarg = try $ do
ch <- option False $ True <$ symbol '='
@@ -1470,7 +1475,21 @@ citationLabel = do
cites :: PandocMonad m => CitationMode -> Bool -> LP m [Citation]
cites mode multi = try $ do
cits <- if multi
- then many1 simpleCiteArgs
+ then do
+ multiprenote <- optionMaybe $ toList <$> paropt
+ multipostnote <- optionMaybe $ toList <$> paropt
+ let (pre, suf) = case (multiprenote, multipostnote) of
+ (Just s , Nothing) -> (mempty, s)
+ (Nothing , Just t) -> (mempty, t)
+ (Just s , Just t ) -> (s, t)
+ _ -> (mempty, mempty)
+ tempCits <- many1 simpleCiteArgs
+ case tempCits of
+ (k:ks) -> case ks of
+ (_:_) -> return $ ((addMprenote pre k):init ks) ++
+ [addMpostnote suf (last ks)]
+ _ -> return [addMprenote pre (addMpostnote suf k)]
+ _ -> return [[]]
else count 1 simpleCiteArgs
let cs = concat cits
return $ case mode of
@@ -1478,6 +1497,17 @@ cites mode multi = try $ do
(c:rest) -> c {citationMode = mode} : rest
[] -> []
_ -> map (\a -> a {citationMode = mode}) cs
+ where mprenote (k:ks) = (k:ks) ++ [Space]
+ mprenote _ = mempty
+ mpostnote (k:ks) = [Str ",", Space] ++ (k:ks)
+ mpostnote _ = mempty
+ addMprenote mpn (k:ks) =
+ let mpnfinal = case citationPrefix k of
+ (_:_) -> mprenote mpn
+ _ -> mpn
+ in addPrefix mpnfinal (k:ks)
+ addMprenote _ _ = []
+ addMpostnote = addSuffix . mpostnote
citation :: PandocMonad m => String -> CitationMode -> Bool -> LP m Inlines
citation name mode multi = do
@@ -1548,6 +1578,9 @@ singleChar = try $ do
opt :: PandocMonad m => LP m Inlines
opt = bracketed inline <|> (str . T.unpack <$> rawopt)
+paropt :: PandocMonad m => LP m Inlines
+paropt = parenWrapped inline
+
rawopt :: PandocMonad m => LP m Text
rawopt = do
inner <- untokenize <$> bracketedToks