pandoc-citeproc 0.12.2.3 → 0.12.2.4
raw patch · 4 files changed
+48/−35 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- changelog +4/−0
- pandoc-citeproc.cabal +1/−1
- src/Text/CSL/Eval/Date.hs +40/−31
- tests/issue312.expected.native +3/−3
changelog view
@@ -1,3 +1,7 @@+pandoc-citeproc (0.12.2.4)++ * Properly fixed range delimiters. Closes #312.+ pandoc-citeproc (0.12.2.3) * Fix month range problems (#312). Months in a range were being
pandoc-citeproc.cabal view
@@ -1,5 +1,5 @@ name: pandoc-citeproc-version: 0.12.2.3+version: 0.12.2.4 cabal-version: >= 1.12 synopsis: Supports using pandoc with citeproc
src/Text/CSL/Eval/Date.hs view
@@ -26,7 +26,7 @@ import Text.CSL.Eval.Output import Text.CSL.Style import Text.CSL.Reference-import Text.CSL.Util ( readNum, toRead, init', last' )+import Text.CSL.Util ( readNum, toRead, last') import Text.Pandoc.Definition ( Inline (Str) ) evalDate :: Element -> State EvalState [Output]@@ -77,7 +77,7 @@ formatDate :: EvalMode -> String -> [CslTerm] -> [DatePart] -> [RefDate] -> [Output] formatDate em k tm dp date- | [d] <- date = concatMap (formatDatePart False d) dp+ | [d] <- date = concatMap (formatDatePart d) dp | (a:b:_) <- date = addODate . concat $ doRange a b | otherwise = [] where@@ -87,23 +87,36 @@ [x,y,z] -> (x,y,z) _ -> E.throw ErrorSplittingDate doRange a b = let (x,y,z) = splitDate a b in- map (formatDatePart False a) x ++- map (formatDatePart False a) (init' y) ++- map (formatDatePart True a) (last' y) ++- map (formatDatePart False b) y ++- map (formatDatePart False b) z- diff a b = filter (flip elem (diffDate a b) . dpName)- diffDate (RefDate ya ma sa da _ _)- (RefDate yb mb sb db _ _) = case () of- _ | ya /= yb -> ["year","month","day"]- | ma /= mb ->- if da == mempty && db == mempty- then ["month"]- else ["month","day"]- | da /= db -> ["day"]- | sa /= sb -> ["month"]- | otherwise -> ["year","month","day"]+ map (formatDatePart a) x +++ withDelim y+ (map (formatDatePart a) (rmSuffix y))+ (map (formatDatePart b) (rmPrefix y))+ +++ map (formatDatePart b) z+ -- the point of rmPrefix is to remove the blank space that otherwise+ -- gets added after the delimiter in a range: 24- 26.+ rmPrefix (dp':rest) = dp'{ dpFormatting =+ (dpFormatting dp') { prefix = "" } } : rest+ rmPrefix [] = []+ rmSuffix (dp':rest)+ | null rest = [dp'{ dpFormatting =+ (dpFormatting dp') { suffix = "" } }]+ | otherwise = dp':rmSuffix rest+ rmSuffix [] = [] + diff (RefDate ya ma sa da _ _)+ (RefDate yb mb sb db _ _)+ = filter (\x -> dpName x `elem` ns)+ where ns =+ case () of+ _ | ya /= yb -> ["year","month","day"]+ | ma /= mb || sa /= sb ->+ if da == mempty && db == mempty+ then ["month"]+ else ["month","day"]+ | da /= db -> ["day"]+ | otherwise -> ["year","month","day"]+ term f t = let f' = if f `elem` ["verb", "short", "verb-short", "symbol"] then read $ toRead f else Long@@ -111,26 +124,22 @@ addZero n = if length n == 1 then '0' : n else n addZeros = reverse . take 5 . flip (++) (repeat '0') . reverse- formatDatePart False (RefDate (Literal y) (Literal m)- (Literal e) (Literal d) _ _) (DatePart n f _ fm)+ formatDatePart (RefDate (Literal y) (Literal m)+ (Literal e) (Literal d) (Literal o) _) (DatePart n f _ fm) | "year" <- n, y /= mempty = return $ OYear (formatYear f y) k fm | "month" <- n, m /= mempty = output fm (formatMonth f fm m) | "day" <- n, d /= mempty = output fm (formatDay f m d) | "month" <- n, m == mempty , e /= mempty = output fm $ term f ("season-0" ++ e)-- formatDatePart True (RefDate (Literal y) (Literal m) (Literal e) (Literal d) _ _) (DatePart n f rd fm)- | "year" <- n, y /= mempty = OYear (formatYear f y) k (fm {suffix = []}) : formatDelim- | "month" <- n, m /= mempty = output (fm {suffix = []}) (formatMonth f fm m) ++ formatDelim- | "day" <- n, d /= mempty = output (fm {suffix = []}) (formatDay f m d) ++ formatDelim- | "month" <- n, m == mempty- , e /= mempty = output (fm {suffix = []}) (term f $ "season-0" ++ e) ++ formatDelim- where- formatDelim = if rd == "-" then [OPan [Str "\x2013"]] else [OPan [Str rd]]-- formatDatePart _ (RefDate _ _ _ _ (Literal o) _) (DatePart n _ _ fm) | "year" <- n, o /= mempty = output fm o | otherwise = []++ withDelim _ [[]] [[]] = []+ withDelim xs o1 o2 = o1 +++ (case dpRangeDelim <$> last' xs of+ ["-"] -> [[OPan [Str "\x2013"]]]+ [s] -> [[OPan [Str s]]]+ _ -> []) ++ o2 formatYear f y | "short" <- f = drop 2 y
tests/issue312.expected.native view
@@ -2,8 +2,8 @@ [Para [Cite [Citation {citationId = "item1", citationPrefix = [], citationSuffix = [], citationMode = AuthorInText, citationNoteNum = 0, citationHash = 1}] [Str "(",Str "\8220Title,\8221",Space,Str "12BC\8211\&12ADa)"],Str ";",Space,Cite [Citation {citationId = "item2", citationPrefix = [], citationSuffix = [], citationMode = AuthorInText, citationNoteNum = 0, citationHash = 2}] [Str "(",Str "\8220Title,\8221",Space,Str "2016\8211\&2017b)"],Str ";",Space,Cite [Citation {citationId = "item3", citationPrefix = [], citationSuffix = [], citationMode = AuthorInText, citationNoteNum = 0, citationHash = 3}] [Str "(",Str "\8220Title,\8221",Space,Str "2016\8211\&2017c)"]] ,Div ("refs",["references"],[]) [Div ("ref-item1",[],[])- [Para [Str "Title.",Space,Str "(12BC\8211\&12ADa,",Space,Str "January,",Space,Str "December)."]]+ [Para [Str "Title.",Space,Str "(12BC\8211\&12ADa,",Space,Str "January–December)."]] ,Div ("ref-item2",[],[])- [Para [Str "Title.",Space,Str "(2016\8211\&2017b,",Space,Str "November,",Space,Str "December)."]]+ [Para [Str "Title.",Space,Str "(2016\8211\&2017b,",Space,Str "November–December)."]] ,Div ("ref-item3",[],[])- [Para [Str "Title.",Space,Str "(2016\8211\&2017c,",Space,Str "Spring,",Space,Str "Summer)."]]]]+ [Para [Str "Title.",Space,Str "(2016\8211\&2017c,",Space,Str "Spring–Summer)."]]]]