@@ -30,7 +30,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3030module Text.Pandoc.Biblio ( processBiblio ) where
3131
3232import Control.Monad ( when )
33−import Data.Char ( toUpper )
3433import Data.List
3534import Data.Unique
3635import Text.CSL hiding ( Cite(..), Citation(..) )
@@ -52,9 +51,9 @@ processBiblio cf r p
5251 ncits = map (queryWith getCite) $ queryWith getNote p'
5352 needNt = cits \\ concat ncits
5453 in (,) needNt $ getNoteCitations needNt p'
55− result = citeproc' csl r (setNearNote csl $ map (map toCslCite) grps)
54+ result = citeproc csl r (setNearNote csl $ map (map toCslCite) grps)
5655 cits_map = zip grps (citations result)
57− biblioList = map (read . renderPandoc' csl) (bibliography result)
56+ biblioList = map (renderPandoc' csl) (bibliography result)
5857 Pandoc m b = processWith (processCite csl cits_map) p'
5958 return . generateNotes nts . Pandoc m $ b ++ biblioList
6059
@@ -65,7 +64,7 @@ processCite s cs il
6564 | otherwise = il
6665 where
6766 process t = case lookup t cs of
68− Just i -> read $ renderPandoc s i
67+ Just i -> renderPandoc s i
6968 Nothing -> [Str ("Error processing " ++ show t)]
7069
7170-- | Retrieve all citations from a 'Pandoc' docuument. To be used with
@@ -91,8 +90,8 @@ getNoteCitations needNote
9190 in queryWith getCitation . getCits
9291
9392setHash :: Citation -> IO Citation
94−setHash (Citation i p l nn ao na _)
95− = hashUnique `fmap` newUnique >>= return . Citation i p l nn ao na
93+setHash (Citation i p l cm nn _)
94+ = hashUnique `fmap` newUnique >>= return . Citation i p l cm nn
9695
9796generateNotes :: [Inline] -> Pandoc -> Pandoc
9897generateNotes needNote = processWith (mvCiteInNote needNote)
@@ -109,12 +108,12 @@ mvCiteInNote is = procInlines mvCite
109108 where
110109 mvCite :: [Inline] -> [Inline]
111110 mvCite inls
112− | x:i:xs <- inls, startWPt xs
113− , x == Space, i `elem_` is = split i xs ++ mvCite (tailInline xs)
111+ | x:i:xs <- inls, startWithPunct xs
112+ , x == Space, i `elem_` is = split i xs ++ mvCite (tailFirstInlineStr xs)
114113 | x:i:xs <- inls
115114 , x == Space, i `elem_` is = mvInNote i : mvCite xs
116115 | i:xs <- inls, i `elem_` is
117− , startWPt xs = split i xs ++ mvCite (tailInline xs)
116+ , startWithPunct xs = split i xs ++ mvCite (tailFirstInlineStr xs)
118117 | i:xs <- inls, Note _ <- i = checkNt i : mvCite xs
119118 | i:xs <- inls = i : mvCite xs
120119 | otherwise = []
@@ -124,91 +123,17 @@ mvCiteInNote is = procInlines mvCite
124123 | Cite t o <- i = Note [Para [Cite t $ sanitize o]]
125124 | otherwise = Note [Para [i ]]
126125 sanitize i
127− | endWPt i = toCapital i
128− | otherwise = toCapital (i ++ [Str "."])
126+ | endWithPunct i = toCapital i
127+ | otherwise = toCapital (i ++ [Str "."])
129128
130129 checkPt i
131130 | Cite c o : xs <- i
132− , endWPt o, startWPt xs
133− , endWPt o = Cite c (initInline o) : checkPt xs
134− | x:xs <- i = x : checkPt xs
135− | otherwise = []
136− endWPt = and . map (`elem` ".,;:!?") . lastInline
137− startWPt = and . map (`elem` ".,;:!?") . headInline
131+ , endWithPunct o, startWithPunct xs
132+ , endWithPunct o = Cite c (initInline o) : checkPt xs
133+ | x:xs <- i = x : checkPt xs
134+ | otherwise = []
138135 checkNt = processWith $ procInlines checkPt
139136
140−headInline :: [Inline] -> String
141−headInline [] = []
142−headInline (i:_)
143− | Str s <- i = head' s
144− | Space <- i = " "
145− | otherwise = headInline $ getInline i
146− where
147− head' s = if s /= [] then [head s] else []
148−
149−lastInline :: [Inline] -> String
150−lastInline [] = []
151−lastInline (i:[])
152− | Str s <- i = last' s
153− | Space <- i = " "
154− | otherwise = lastInline $ getInline i
155− where
156− last' s = if s /= [] then [last s] else []
157−lastInline (_:xs) = lastInline xs
158−
159−initInline :: [Inline] -> [Inline]
160−initInline [] = []
161−initInline (i:[])
162− | Str s <- i = return $ Str (init' s)
163− | Emph is <- i = return $ Emph (initInline is)
164− | Strong is <- i = return $ Strong (initInline is)
165− | Strikeout is <- i = return $ Strikeout (initInline is)
166− | Superscript is <- i = return $ Superscript (initInline is)
167− | Subscript is <- i = return $ Subscript (initInline is)
168− | Quoted q is <- i = return $ Quoted q (initInline is)
169− | SmallCaps is <- i = return $ SmallCaps (initInline is)
170− | Link is t <- i = return $ Link (initInline is) t
171− | otherwise = []
172− where
173− init' s = if s /= [] then init s else []
174−initInline (i:xs) = i : initInline xs
175−
176−tailInline :: [Inline] -> [Inline]
177−tailInline = mapHeadInline tail'
178− where
179− tail' s = if s /= [] then tail s else []
180−
181−toCapital :: [Inline] -> [Inline]
182−toCapital = mapHeadInline toCap
183− where
184− toCap s = if s /= [] then toUpper (head s) : tail s else []
185−
186−mapHeadInline :: (String -> String) -> [Inline] -> [Inline]
187−mapHeadInline _ [] = []
188−mapHeadInline f (i:xs)
189− | Str s <- i = Str (f s) : xs
190− | Emph is <- i = Emph (mapHeadInline f is) : xs
191− | Strong is <- i = Strong (mapHeadInline f is) : xs
192− | Strikeout is <- i = Strikeout (mapHeadInline f is) : xs
193− | Superscript is <- i = Superscript (mapHeadInline f is) : xs
194− | Subscript is <- i = Subscript (mapHeadInline f is) : xs
195− | Quoted q is <- i = Quoted q (mapHeadInline f is) : xs
196− | SmallCaps is <- i = SmallCaps (mapHeadInline f is) : xs
197− | Link is t <- i = Link (mapHeadInline f is) t : xs
198− | otherwise = []
199−
200−getInline :: Inline -> [Inline]
201−getInline i
202− | Emph is <- i = is
203− | Strong is <- i = is
204− | Strikeout is <- i = is
205− | Superscript is <- i = is
206− | Subscript is <- i = is
207− | Quoted _ is <- i = is
208− | SmallCaps is <- i = is
209− | Link is _ <- i = is
210− | otherwise = []
211−
212137setCiteNoteNum :: [Inline] -> Int -> [Inline]
213138setCiteNoteNum ((Cite cs o):xs) n = Cite (setCitationNoteNum n cs) o : setCiteNoteNum xs n
214139setCiteNoteNum _ _ = []
@@ -217,13 +142,17 @@ setCitationNoteNum :: Int -> [Citation] -> [Citation]
217142setCitationNoteNum i = map $ \c -> c { citationNoteNum = i}
218143
219144toCslCite :: Citation -> CSL.Cite
220−toCslCite (Citation i p l nn ao na _)
145+toCslCite (Citation i p l cm nn _)
221146 = let (la,lo) = parseLocator l
147+ citMode = case cm of
148+ AuthorOnly -> (True, False)
149+ SuppressAuthor -> (False,True )
150+ NormalCitation -> (False,False)
222151 in emptyCite { CSL.citeId = i
223152 , CSL.citePrefix = p
224153 , CSL.citeLabel = la
225154 , CSL.citeLocator = lo
226155 , CSL.citeNoteNumber = show nn
227− , CSL.authorOnly = ao
228− , CSL.suppressAuthor = na
156+ , CSL.authorOnly = fst citMode
157+ , CSL.suppressAuthor = snd citMode
229158 }