@@ -30,7 +30,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30module Text.Pandoc.Biblio ( processBiblio ) where
30module Text.Pandoc.Biblio ( processBiblio ) where
32import Control.Monad ( when )
32import Control.Monad ( when )
33−import Data.Char ( toUpper )
34import Data.List
33import Data.List
35import Data.Unique
34import Data.Unique
36import Text.CSL hiding ( Cite(..), Citation(..) )
35import Text.CSL hiding ( Cite(..), Citation(..) )
@@ -52,9 +51,9 @@ processBiblio cf r p
52 ncits = map (queryWith getCite) $ queryWith getNote p'
51 ncits = map (queryWith getCite) $ queryWith getNote p'
53 needNt = cits \\ concat ncits
52 needNt = cits \\ concat ncits
54 in (,) needNt $ getNoteCitations needNt p'
53 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)
56 cits_map = zip grps (citations result)
55 cits_map = zip grps (citations result)
57− biblioList = map (read . renderPandoc' csl) (bibliography result)
56+ biblioList = map (renderPandoc' csl) (bibliography result)
58 Pandoc m b = processWith (processCite csl cits_map) p'
57 Pandoc m b = processWith (processCite csl cits_map) p'
59 return . generateNotes nts . Pandoc m $ b ++ biblioList
58 return . generateNotes nts . Pandoc m $ b ++ biblioList
@@ -65,7 +64,7 @@ processCite s cs il
65 | otherwise = il
64 | otherwise = il
67 process t = case lookup t cs of
66 process t = case lookup t cs of
68− Just i -> read $ renderPandoc s i
67+ Just i -> renderPandoc s i
69 Nothing -> [Str ("Error processing " ++ show t)]
68 Nothing -> [Str ("Error processing " ++ show t)]
71-- | Retrieve all citations from a 'Pandoc' docuument. To be used with
70-- | Retrieve all citations from a 'Pandoc' docuument. To be used with
@@ -91,8 +90,8 @@ getNoteCitations needNote
91 in queryWith getCitation . getCits
90 in queryWith getCitation . getCits
93setHash :: Citation -> IO Citation
92setHash :: Citation -> IO Citation
94−setHash (Citation i p l nn ao na _)
93+setHash (Citation i p l cm nn _)
95− = hashUnique `fmap` newUnique >>= return . Citation i p l nn ao na
94+ = hashUnique `fmap` newUnique >>= return . Citation i p l cm nn
97generateNotes :: [Inline] -> Pandoc -> Pandoc
96generateNotes :: [Inline] -> Pandoc -> Pandoc
98generateNotes needNote = processWith (mvCiteInNote needNote)
97generateNotes needNote = processWith (mvCiteInNote needNote)
@@ -109,12 +108,12 @@ mvCiteInNote is = procInlines mvCite
110 mvCite :: [Inline] -> [Inline]
109 mvCite :: [Inline] -> [Inline]
111 mvCite inls
110 mvCite inls
112− | x:i:xs <- inls, startWPt xs
111+ | x:i:xs <- inls, startWithPunct xs
113− , x == Space, i `elem_` is = split i xs ++ mvCite (tailInline xs)
112+ , x == Space, i `elem_` is = split i xs ++ mvCite (tailFirstInlineStr xs)
114 | x:i:xs <- inls
113 | x:i:xs <- inls
115 , x == Space, i `elem_` is = mvInNote i : mvCite xs
114 , x == Space, i `elem_` is = mvInNote i : mvCite xs
116 | i:xs <- inls, i `elem_` is
115 | i:xs <- inls, i `elem_` is
117− , startWPt xs = split i xs ++ mvCite (tailInline xs)
116+ , startWithPunct xs = split i xs ++ mvCite (tailFirstInlineStr xs)
118 | i:xs <- inls, Note _ <- i = checkNt i : mvCite xs
117 | i:xs <- inls, Note _ <- i = checkNt i : mvCite xs
119 | i:xs <- inls = i : mvCite xs
118 | i:xs <- inls = i : mvCite xs
120 | otherwise = []
119 | otherwise = []
@@ -124,91 +123,17 @@ mvCiteInNote is = procInlines mvCite
124 | Cite t o <- i = Note [Para [Cite t $ sanitize o]]
123 | Cite t o <- i = Note [Para [Cite t $ sanitize o]]
125 | otherwise = Note [Para [i ]]
124 | otherwise = Note [Para [i ]]
126 sanitize i
125 sanitize i
127− | endWPt i = toCapital i
126+ | endWithPunct i = toCapital i
128− | otherwise = toCapital (i ++ [Str "."])
127+ | otherwise = toCapital (i ++ [Str "."])
130 checkPt i
129 checkPt i
131 | Cite c o : xs <- i
130 | Cite c o : xs <- i
132− , endWPt o, startWPt xs
131+ , endWithPunct o, startWithPunct xs
133− , endWPt o = Cite c (initInline o) : checkPt xs
132+ , endWithPunct o = Cite c (initInline o) : checkPt xs
134− | x:xs <- i = x : checkPt xs
133+ | x:xs <- i = x : checkPt xs
135− | otherwise = []
134+ | otherwise = []
136− endWPt = and . map (`elem` ".,;:!?") . lastInline
137− startWPt = and . map (`elem` ".,;:!?") . headInline
138 checkNt = processWith $ procInlines checkPt
135 checkNt = processWith $ procInlines checkPt
140−headInline :: [Inline] -> String
143− | Str s <- i = head' s
145− | otherwise = headInline $ getInline i
147− head' s = if s /= [] then [head s] else []
149−lastInline :: [Inline] -> String
152− | Str s <- i = last' s
154− | otherwise = lastInline $ getInline i
156− last' s = if s /= [] then [last s] else []
157−lastInline (_:xs) = lastInline xs
159−initInline :: [Inline] -> [Inline]
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
173− init' s = if s /= [] then init s else []
174−initInline (i:xs) = i : initInline xs
176−tailInline :: [Inline] -> [Inline]
177−tailInline = mapHeadInline tail'
179− tail' s = if s /= [] then tail s else []
181−toCapital :: [Inline] -> [Inline]
182−toCapital = mapHeadInline toCap
184− toCap s = if s /= [] then toUpper (head s) : tail s else []
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
200−getInline :: Inline -> [Inline]
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
212setCiteNoteNum :: [Inline] -> Int -> [Inline]
137setCiteNoteNum :: [Inline] -> Int -> [Inline]
213setCiteNoteNum ((Cite cs o):xs) n = Cite (setCitationNoteNum n cs) o : setCiteNoteNum xs n
138setCiteNoteNum ((Cite cs o):xs) n = Cite (setCitationNoteNum n cs) o : setCiteNoteNum xs n
214setCiteNoteNum _ _ = []
139setCiteNoteNum _ _ = []
@@ -217,13 +142,17 @@ setCitationNoteNum :: Int -> [Citation] -> [Citation]
217setCitationNoteNum i = map $ \c -> c { citationNoteNum = i}
142setCitationNoteNum i = map $ \c -> c { citationNoteNum = i}
219toCslCite :: Citation -> CSL.Cite
144toCslCite :: Citation -> CSL.Cite
220−toCslCite (Citation i p l nn ao na _)
145+toCslCite (Citation i p l cm nn _)
221 = let (la,lo) = parseLocator l
146 = let (la,lo) = parseLocator l
147+ citMode = case cm of
148+ AuthorOnly -> (True, False)
149+ SuppressAuthor -> (False,True )
150+ NormalCitation -> (False,False)
222 in emptyCite { CSL.citeId = i
151 in emptyCite { CSL.citeId = i
223 , CSL.citePrefix = p
152 , CSL.citePrefix = p
224 , CSL.citeLabel = la
153 , CSL.citeLabel = la
225 , CSL.citeLocator = lo
154 , CSL.citeLocator = lo
226 , CSL.citeNoteNumber = show nn
155 , CSL.citeNoteNumber = show nn
227− , CSL.authorOnly = ao
156+ , CSL.authorOnly = fst citMode
228− , CSL.suppressAuthor = na
157+ , CSL.suppressAuthor = snd citMode