summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohnMacFarlane <>2018-01-03 06:46:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2018-01-03 06:46:00 (GMT)
commit5b221ed16951be3c3215a4c71dea12e188acf45b (patch)
treece8485173bd31f946eed424d8bf8fc2eaee810b6
parentdc3aeaf5fd1bd2688ce64c3b0745edb472bf5f93 (diff)
version 0.12.2.40.12.2.4
-rw-r--r--changelog4
-rw-r--r--pandoc-citeproc.cabal2
-rw-r--r--src/Text/CSL/Eval/Date.hs71
-rw-r--r--tests/issue312.expected.native6
4 files changed, 48 insertions, 35 deletions
diff --git a/changelog b/changelog
index 36b67dd..822a10a 100644
--- a/changelog
+++ b/changelog
@@ -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
diff --git a/pandoc-citeproc.cabal b/pandoc-citeproc.cabal
index 76aca67..5ba139c 100644
--- a/pandoc-citeproc.cabal
+++ b/pandoc-citeproc.cabal
@@ -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
diff --git a/src/Text/CSL/Eval/Date.hs b/src/Text/CSL/Eval/Date.hs
index 3782001..a3822d3 100644
--- a/src/Text/CSL/Eval/Date.hs
+++ b/src/Text/CSL/Eval/Date.hs
@@ -26,7 +26,7 @@ import Text.CSL.Eval.Common
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 @@ getDate f = do
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,22 +87,35 @@ formatDate em k tm dp date
[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
@@ -111,27 +124,23 @@ formatDate em k tm dp date
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
| isSorting em
diff --git a/tests/issue312.expected.native b/tests/issue312.expected.native
index 9bffcfd..a2bf32f 100644
--- a/tests/issue312.expected.native
+++ b/tests/issue312.expected.native
@@ -2,8 +2,8 @@ Pandoc (Meta {unMeta = fromList [("csl",MetaInlines [Str "tests/apa.csl"]),("ref
[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)."]]]]