git.iko.soy/typeable/pandoc
on master help sign in
Added support for textual citations (but not yet markdown syntax).
36d4e64John MacFarlane
src/Text/Pandoc/Biblio.hs+27−18
@@ -54,19 +54,27 @@ processBiblio cf r p
54 result = citeproc csl r (setNearNote csl $ map (map toCslCite) grps)
54 result = citeproc csl r (setNearNote csl $ map (map toCslCite) grps)
55 cits_map = zip grps (citations result)
55 cits_map = zip grps (citations result)
56 biblioList = map (renderPandoc' csl) (bibliography result)
56 biblioList = map (renderPandoc' csl) (bibliography result)
57− Pandoc m b = processWith (processCite csl cits_map) p'
57+ Pandoc m b = processWith (procInlines $ processCite csl cits_map) p'
58 return . generateNotes nts . Pandoc m $ b ++ biblioList
58 return . generateNotes nts . Pandoc m $ b ++ biblioList
59
59
60-- | Substitute 'Cite' elements with formatted citations.
60-- | Substitute 'Cite' elements with formatted citations.
61−processCite :: Style -> [([Citation],[FormattedOutput])] -> Inline -> Inline
61+processCite :: Style -> [([Citation],[FormattedOutput])] -> [Inline] -> [Inline]
62+processCite _ _ [] = []
62−processCite s cs il
63+processCite s cs (i:is)
63− | Cite t _ <- il = Cite t (process t)
64+ | Cite t _ <- i = process t ++ processCite s cs is
64− | otherwise = il
65+ | otherwise = i : processCite s cs is
65 where
66 where
66 process t = case lookup t cs of
67 process t = case lookup t cs of
68+ Just x -> if isTextualCitation t && x /= []
69+ then renderPandoc s [head x] ++ [Space] ++
67− Just i -> renderPandoc s i
70+ [Cite t $ renderPandoc s $ tail x]
71+ else [Cite t $ renderPandoc s x]
68 Nothing -> [Str ("Error processing " ++ show t)]
72 Nothing -> [Str ("Error processing " ++ show t)]
69
73
74+isTextualCitation :: [Citation] -> Bool
75+isTextualCitation (c:_) = citationMode c == AuthorInText
76+isTextualCitation _ = False
77+
70-- | Retrieve all citations from a 'Pandoc' docuument. To be used with
78-- | Retrieve all citations from a 'Pandoc' docuument. To be used with
71-- 'queryWith'.
79-- 'queryWith'.
72getCitation :: Inline -> [[Citation]]
80getCitation :: Inline -> [[Citation]]
@@ -109,22 +117,22 @@ mvCiteInNote is = procInlines mvCite
109 mvCite :: [Inline] -> [Inline]
117 mvCite :: [Inline] -> [Inline]
110 mvCite inls
118 mvCite inls
111 | x:i:xs <- inls, startWithPunct xs
119 | x:i:xs <- inls, startWithPunct xs
112− , x == Space, i `elem_` is = split i xs ++ mvCite (tailFirstInlineStr xs)
120+ , x == Space, i `elem_` is = switch i xs ++ mvCite (tailFirstInlineStr xs)
113 | x:i:xs <- inls
121 | x:i:xs <- inls
114− , x == Space, i `elem_` is = mvInNote i : mvCite xs
122+ , x == Space, i `elem_` is = mvInNote i : mvCite xs
115 | i:xs <- inls, i `elem_` is
123 | i:xs <- inls, i `elem_` is
116− , startWithPunct xs = split i xs ++ mvCite (tailFirstInlineStr xs)
124+ , startWithPunct xs = switch i xs ++ mvCite (tailFirstInlineStr xs)
117− | i:xs <- inls, Note _ <- i = checkNt i : mvCite xs
125+ | i:xs <- inls, Note _ <- i = checkNt i : mvCite xs
118− | i:xs <- inls = i : mvCite xs
126+ | i:xs <- inls = i : mvCite xs
119 | otherwise = []
127 | otherwise = []
120− elem_ x xs = case x of Cite cs _ -> (Cite cs []) `elem` xs; _ -> False
128+ elem_ x xs = case x of Cite cs _ -> (Cite cs []) `elem` xs; _ -> False
121− split i xs = Str (headInline xs) : mvInNote i : []
129+ switch i xs = Str (headInline xs) : mvInNote i : []
122 mvInNote i
130 mvInNote i
123 | Cite t o <- i = Note [Para [Cite t $ sanitize o]]
131 | Cite t o <- i = Note [Para [Cite t $ sanitize o]]
124 | otherwise = Note [Para [i ]]
132 | otherwise = Note [Para [i ]]
125 sanitize i
133 sanitize i
126− | endWithPunct i = toCapital i
134+ | endWithPunct i = toCapital i
127− | otherwise = toCapital (i ++ [Str "."])
135+ | otherwise = toCapital (i ++ [Str "."])
128
136
129 checkPt i
137 checkPt i
130 | Cite c o : xs <- i
138 | Cite c o : xs <- i
@@ -142,10 +150,10 @@ setCitationNoteNum :: Int -> [Citation] -> [Citation]
142setCitationNoteNum i = map $ \c -> c { citationNoteNum = i}
150setCitationNoteNum i = map $ \c -> c { citationNoteNum = i}
143
151
144toCslCite :: Citation -> CSL.Cite
152toCslCite :: Citation -> CSL.Cite
145−toCslCite (Citation i p l cm nn _)
153+toCslCite (Citation i p l cm nn h)
146 = let (la,lo) = parseLocator l
154 = let (la,lo) = parseLocator l
147 citMode = case cm of
155 citMode = case cm of
148− AuthorOnly -> (True, False)
156+ AuthorInText -> (True, False)
149 SuppressAuthor -> (False,True )
157 SuppressAuthor -> (False,True )
150 NormalCitation -> (False,False)
158 NormalCitation -> (False,False)
151 in emptyCite { CSL.citeId = i
159 in emptyCite { CSL.citeId = i
@@ -153,6 +161,7 @@ toCslCite (Citation i p l cm nn _)
153 , CSL.citeLabel = la
161 , CSL.citeLabel = la
154 , CSL.citeLocator = lo
162 , CSL.citeLocator = lo
155 , CSL.citeNoteNumber = show nn
163 , CSL.citeNoteNumber = show nn
156− , CSL.authorOnly = fst citMode
164+ , CSL.authorInText = fst citMode
157 , CSL.suppressAuthor = snd citMode
165 , CSL.suppressAuthor = snd citMode
166+ , CSL.citeHash = h
158 }
167 }
src/Text/Pandoc/Readers/Markdown.hs+1−1
@@ -1345,6 +1345,6 @@ parseLabel = try $ do
1345 else (p , False)
1345 else (p , False)
1346 mode = case (na,o) of
1346 mode = case (na,o) of
1347 (True, False) -> SuppressAuthor
1347 (True, False) -> SuppressAuthor
1348− (False,True ) -> AuthorOnly
1348+ (False,True ) -> AuthorInText
1349 _ -> NormalCitation
1349 _ -> NormalCitation
1350 return $ Citation cit (trim p') (trim loc) mode 0 0
1350 return $ Citation cit (trim p') (trim loc) mode 0 0