summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohnMacFarlane <>2017-12-29 05:12:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2017-12-29 05:12:00 (GMT)
commitad5fc828d22ae4d8ce4b9503b9463227139064fc (patch)
treec7a9d213f6081edfa6a9fd763d5d5915c749f8e0
parentf4f15e2c89f8b5072e0dc566ab8cdf75fce7ce18 (diff)
version 0.12.2.10.12.2.1
-rw-r--r--changelog7
-rw-r--r--pandoc-citeproc.cabal2
-rw-r--r--src/Text/CSL/Reference.hs24
3 files changed, 26 insertions, 7 deletions
diff --git a/changelog b/changelog
index c9239dd..5095726 100644
--- a/changelog
+++ b/changelog
@@ -1,3 +1,8 @@
+pandoc-citeproc (0.12.2.1)
+
+ * Handle pseudo-months in CSL date-range (see #103).
+ Month 13 = season 1, 14 = 2, also 21 = 1, 22 = 2, ...
+
pandoc-citeproc (0.12.2)
* Improved parsing of raw dates. First we attempt to parse them
@@ -19,7 +24,7 @@ pandoc-citeproc (0.12.2)
+ We now only parse 'raw' if `date-parts` is empty or missing.
+ Code for parsing raw dates moved from Text.CSL.Eval.Date to
Text.CSL.Reference.
- + Use `literal` field if we can't parse data.
+ + Use `other` field if we can't parse data.
* Support `all-names-with-initials` disambiguation.
diff --git a/pandoc-citeproc.cabal b/pandoc-citeproc.cabal
index 086f0bd..a16957e 100644
--- a/pandoc-citeproc.cabal
+++ b/pandoc-citeproc.cabal
@@ -1,5 +1,5 @@
name: pandoc-citeproc
-version: 0.12.2
+version: 0.12.2.1
cabal-version: >= 1.12
synopsis: Supports using pandoc with citeproc
diff --git a/src/Text/CSL/Reference.hs b/src/Text/CSL/Reference.hs
index c21d045..a534567 100644
--- a/src/Text/CSL/Reference.hs
+++ b/src/Text/CSL/Reference.hs
@@ -132,7 +132,7 @@ data RefDate =
} deriving ( Show, Read, Eq, Typeable, Data, Generic )
instance FromJSON RefDate where
- parseJSON (Array v) =
+ parseJSON (Array v) = handlePseudoMonths <$>
case fromJSON (Array v) of
Success [y] -> RefDate <$> parseJSON y <*>
pure "" <*> pure "" <*> pure "" <*> pure "" <*> pure False
@@ -142,6 +142,17 @@ instance FromJSON RefDate where
pure "" <*> parseJSON d <*> pure "" <*> pure False
Error e -> fail $ "Could not parse RefDate: " ++ e
_ -> fail "Could not parse RefDate"
+ where handlePseudoMonths r =
+ case unLiteral (month r) of
+ "13" -> r{ month = mempty, season = Literal "1" }
+ "14" -> r{ month = mempty, season = Literal "2" }
+ "15" -> r{ month = mempty, season = Literal "3" }
+ "16" -> r{ month = mempty, season = Literal "4" }
+ "21" -> r{ month = mempty, season = Literal "1" }
+ "22" -> r{ month = mempty, season = Literal "2" }
+ "23" -> r{ month = mempty, season = Literal "3" }
+ "24" -> r{ month = mempty, season = Literal "4" }
+ _ -> r
parseJSON (Object v) = RefDate <$>
v .:? "year" .!= "" <*>
v .:? "month" .!= "" <*>
@@ -178,11 +189,11 @@ instance OVERLAPS
raw' <- v .:? "raw"
dateParts <- v .:? "date-parts"
circa' <- (v .: "circa" >>= parseBool) <|> pure False
- season' <- (v .: "season") <|> pure mempty
+ season' <- v .:? "season"
case dateParts of
Just (Array xs) | not (isJust raw') && not (V.null xs)
-> mapM (fmap (setCirca circa' .
- setSeason season') . parseJSON)
+ maybe id setSeason season') . parseJSON)
$ V.toList xs
_ -> case raw' of
Nothing -> handleLiteral <$> parseJSON (Object v)
@@ -877,7 +888,10 @@ rawDateISO = do
isoDate :: P.Parser RefDate
isoDate = P.try $ do
- y <- P.many1 P.digit
+ y <- do
+ sign <- P.option "" (P.string "-")
+ rest <- P.count 4 P.digit
+ return $ sign ++ rest
m' <- P.option Nothing $ Just <$> P.try (P.char '-' >> P.many1 P.digit)
(m,s) <- case m' >>= safeRead of
Just (n::Int)
@@ -920,7 +934,7 @@ rawDateOld = do
Just (n::Int) | n >= 1 && n <= 31 -> return (show n)
_ -> fail "Improper day"
let pyear = P.many1 P.digit
- let sep = P.oneOf ['-',' ','/',','] >> P.spaces
+ let sep = P.oneOf [' ','/',','] >> P.spaces
let rangesep = P.try $ P.spaces >> P.char '-' >> P.spaces
let refDate = RefDate mempty mempty mempty mempty mempty False
let date = P.choice $ map P.try [