aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2012-10-15 19:11:01 -0700
committerJohn MacFarlane <fiddlosopher@gmail.com>2012-10-15 19:53:57 -0700
commit7499499b68934ae6f3418940328c7fc2bd9fcadd (patch)
tree191f56880bb1758623aa44f48e60811ec06021ed /src/Text
parentb28630f577fd149580b18a300252cd0e1f173574 (diff)
downloadpandoc-7499499b68934ae6f3418940328c7fc2bd9fcadd.tar.gz
LaTeX reader: Use new suppressParens option for footnote citations.
Also changed Biblio, Markdown reader, and LaTeX reader tests because of new citationSuppressParens field in Citation.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Biblio.hs5
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs111
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs30
3 files changed, 75 insertions, 71 deletions
diff --git a/src/Text/Pandoc/Biblio.hs b/src/Text/Pandoc/Biblio.hs
index 934b9222e..e5b8fe197 100644
--- a/src/Text/Pandoc/Biblio.hs
+++ b/src/Text/Pandoc/Biblio.hs
@@ -111,10 +111,10 @@ getCitation i | Cite t _ <- i = [t]
| otherwise = []
setHash :: Citation -> State Int Citation
-setHash (Citation i p s cm nn _) = do
+setHash c = do
ident <- get
put $ ident + 1
- return $ Citation i p s cm nn ident
+ return c{ citationHash = ident }
toCslCite :: Citation -> CSL.Cite
toCslCite c
@@ -140,6 +140,7 @@ toCslCite c
, CSL.citeNoteNumber = show $ citationNoteNum c
, CSL.authorInText = fst citMode
, CSL.suppressAuthor = snd citMode
+ , CSL.suppressParens = citationSuppressParens c
, CSL.citeHash = citationHash c
}
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index c56ca0bde..54a39f24f 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -426,65 +426,61 @@ inlineCommands = M.fromList $
pure (link url "" lab))
, ("includegraphics", skipopts *> (unescapeURL <$> braced) >>=
(\src -> pure (image src "" (str "image"))))
- , ("cite", citation "cite" AuthorInText False)
- , ("citep", citation "citep" NormalCitation False)
- , ("citep*", citation "citep*" NormalCitation False)
- , ("citeal", citation "citeal" NormalCitation False)
- , ("citealp", citation "citealp" NormalCitation False)
- , ("citealp*", citation "citealp*" NormalCitation False)
- , ("autocite", citation "autocite" NormalCitation False)
- , ("footcite", inNote <$> citation "footcite" NormalCitation False)
- , ("parencite", citation "parencite" NormalCitation False)
- , ("supercite", citation "supercite" NormalCitation False)
- , ("footcitetext", inNote <$> citation "footcitetext" NormalCitation False)
- , ("citeyearpar", citation "citeyearpar" SuppressAuthor False)
- , ("citeyear", citation "citeyear" SuppressAuthor False)
- , ("autocite*", citation "autocite*" SuppressAuthor False)
- , ("cite*", citation "cite*" SuppressAuthor False)
- , ("parencite*", citation "parencite*" SuppressAuthor False)
- , ("textcite", citation "textcite" AuthorInText False)
- , ("citet", citation "citet" AuthorInText False)
- , ("citet*", citation "citet*" AuthorInText False)
- , ("citealt", citation "citealt" AuthorInText False)
- , ("citealt*", citation "citealt*" AuthorInText False)
- , ("textcites", citation "textcites" AuthorInText True)
- , ("cites", citation "cites" NormalCitation True)
- , ("autocites", citation "autocites" NormalCitation True)
- , ("footcites", inNote <$> citation "footcites" NormalCitation True)
- , ("parencites", citation "parencites" NormalCitation True)
- , ("supercites", citation "supercites" NormalCitation True)
- , ("footcitetexts", inNote <$> citation "footcitetexts" NormalCitation True)
- , ("Autocite", citation "Autocite" NormalCitation False)
- , ("Footcite", citation "Footcite" NormalCitation False)
- , ("Parencite", citation "Parencite" NormalCitation False)
- , ("Supercite", citation "Supercite" NormalCitation False)
- , ("Footcitetext", inNote <$> citation "Footcitetext" NormalCitation False)
- , ("Citeyearpar", citation "Citeyearpar" SuppressAuthor False)
- , ("Citeyear", citation "Citeyear" SuppressAuthor False)
- , ("Autocite*", citation "Autocite*" SuppressAuthor False)
- , ("Cite*", citation "Cite*" SuppressAuthor False)
- , ("Parencite*", citation "Parencite*" SuppressAuthor False)
- , ("Textcite", citation "Textcite" AuthorInText False)
- , ("Textcites", citation "Textcites" AuthorInText True)
- , ("Cites", citation "Cites" NormalCitation True)
- , ("Autocites", citation "Autocites" NormalCitation True)
- , ("Footcites", citation "Footcites" NormalCitation True)
- , ("Parencites", citation "Parencites" NormalCitation True)
- , ("Supercites", citation "Supercites" NormalCitation True)
- , ("Footcitetexts", inNote <$> citation "Footcitetexts" NormalCitation True)
+ , ("cite", citation "cite" AuthorInText False False)
+ , ("citep", citation "citep" NormalCitation False False)
+ , ("citep*", citation "citep*" NormalCitation False False)
+ , ("citeal", citation "citeal" NormalCitation False False)
+ , ("citealp", citation "citealp" NormalCitation False False)
+ , ("citealp*", citation "citealp*" NormalCitation False False)
+ , ("autocite", citation "autocite" NormalCitation False False)
+ , ("footcite", citation "footcite" NormalCitation False True)
+ , ("parencite", citation "parencite" NormalCitation False False)
+ , ("supercite", citation "supercite" NormalCitation False False)
+ , ("footcitetext", citation "footcitetext" NormalCitation False True)
+ , ("citeyearpar", citation "citeyearpar" SuppressAuthor False False)
+ , ("citeyear", citation "citeyear" SuppressAuthor False False)
+ , ("autocite*", citation "autocite*" SuppressAuthor False False)
+ , ("cite*", citation "cite*" SuppressAuthor False False)
+ , ("parencite*", citation "parencite*" SuppressAuthor False False)
+ , ("textcite", citation "textcite" AuthorInText False False)
+ , ("citet", citation "citet" AuthorInText False False)
+ , ("citet*", citation "citet*" AuthorInText False False)
+ , ("citealt", citation "citealt" AuthorInText False False)
+ , ("citealt*", citation "citealt*" AuthorInText False False)
+ , ("textcites", citation "textcites" AuthorInText True False)
+ , ("cites", citation "cites" NormalCitation True False)
+ , ("autocites", citation "autocites" NormalCitation True False)
+ , ("footcites", citation "footcites" NormalCitation True True)
+ , ("parencites", citation "parencites" NormalCitation True False)
+ , ("supercites", citation "supercites" NormalCitation True False)
+ , ("footcitetexts", citation "footcitetexts" NormalCitation True True)
+ , ("Autocite", citation "Autocite" NormalCitation False False)
+ , ("Footcite", citation "Footcite" NormalCitation False False)
+ , ("Parencite", citation "Parencite" NormalCitation False False)
+ , ("Supercite", citation "Supercite" NormalCitation False False)
+ , ("Footcitetext", citation "Footcitetext" NormalCitation False True)
+ , ("Citeyearpar", citation "Citeyearpar" SuppressAuthor False False)
+ , ("Citeyear", citation "Citeyear" SuppressAuthor False False)
+ , ("Autocite*", citation "Autocite*" SuppressAuthor False False)
+ , ("Cite*", citation "Cite*" SuppressAuthor False False)
+ , ("Parencite*", citation "Parencite*" SuppressAuthor False False)
+ , ("Textcite", citation "Textcite" AuthorInText False False)
+ , ("Textcites", citation "Textcites" AuthorInText True False)
+ , ("Cites", citation "Cites" NormalCitation True False)
+ , ("Autocites", citation "Autocites" NormalCitation True False)
+ , ("Footcites", citation "Footcites" NormalCitation True False)
+ , ("Parencites", citation "Parencites" NormalCitation True False)
+ , ("Supercites", citation "Supercites" NormalCitation True False)
+ , ("Footcitetexts", citation "Footcitetexts" NormalCitation True True)
, ("citetext", complexNatbibCitation NormalCitation)
, ("citeauthor", (try (tok *> optional sp *> controlSeq "citetext") *>
complexNatbibCitation AuthorInText)
- <|> citation "citeauthor" AuthorInText False)
+ <|> citation "citeauthor" AuthorInText False False)
] ++ map ignoreInlines
-- these commands will be ignored unless --parse-raw is specified,
-- in which case they will appear as raw latex blocks:
[ "noindent", "index", "nocite" ]
-inNote :: Inlines -> Inlines
-inNote ils =
- note $ para $ ils <> str "."
-
unescapeURL :: String -> String
unescapeURL ('\\':x:xs) | isEscapable x = x:unescapeURL xs
where isEscapable '%' = True
@@ -899,6 +895,7 @@ simpleCiteArgs = try $ do
, citationSuffix = []
, citationMode = NormalCitation
, citationHash = 0
+ , citationSuppressParens = False
, citationNoteNum = 0
}
return $ addPrefix pre $ addSuffix suf $ map conv keys
@@ -917,10 +914,14 @@ cites mode multi = try $ do
AuthorInText -> c {citationMode = mode} : cs
_ -> map (\a -> a {citationMode = mode}) (c:cs)
-citation :: String -> CitationMode -> Bool -> LP Inlines
-citation name mode multi = do
- (c,raw) <- withRaw $ cites mode multi
- return $ cite c (rawInline "latex" $ "\\" ++ name ++ raw)
+citation :: String -> CitationMode -> Bool -> Bool -> LP Inlines
+citation name mode multi inNote = do
+ (cs,raw) <- withRaw $ cites mode multi
+ let cs' = if inNote then map (\c -> c{ citationSuppressParens = True }) cs else cs
+ let cit = cite cs' (rawInline "latex" $ "\\" ++ name ++ raw)
+ if inNote
+ then return $ note $ para $ cit <> str "."
+ else return cit
complexNatbibCitation :: CitationMode -> LP Inlines
complexNatbibCitation mode = try $ do
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index ab8069a75..1b69660e6 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -1554,12 +1554,13 @@ cite = do
textualCite :: Parser [Char] ParserState (F [Citation])
textualCite = try $ do
(_, key) <- citeKey
- let first = Citation{ citationId = key
- , citationPrefix = []
- , citationSuffix = []
- , citationMode = AuthorInText
- , citationNoteNum = 0
- , citationHash = 0
+ let first = Citation{ citationId = key
+ , citationPrefix = []
+ , citationSuffix = []
+ , citationMode = AuthorInText
+ , citationNoteNum = 0
+ , citationSuppressParens = False
+ , citationHash = 0
}
mbrest <- option Nothing $ try $ spnl >> Just <$> normalCite
case mbrest of
@@ -1624,14 +1625,15 @@ citation = try $ do
return $ do
x <- pref
y <- suff
- return $ Citation{ citationId = key
- , citationPrefix = B.toList x
- , citationSuffix = B.toList y
- , citationMode = if suppress_author
- then SuppressAuthor
- else NormalCitation
- , citationNoteNum = 0
- , citationHash = 0
+ return $ Citation{ citationId = key
+ , citationPrefix = B.toList x
+ , citationSuffix = B.toList y
+ , citationMode = if suppress_author
+ then SuppressAuthor
+ else NormalCitation
+ , citationNoteNum = 0
+ , citationSuppressParens = False
+ , citationHash = 0
}
smart :: Parser [Char] ParserState (F Inlines)