From dccd408a9c22e9120dcf50f1c107bff71778ee45 Mon Sep 17 00:00:00 2001
From: "Matthias C. M. Troffaes" <matthias.troffaes@gmail.com>
Date: Wed, 18 Feb 2015 13:54:25 +0000
Subject: [PATCH] Allow digit as first character of a citation key.

* Update parser to recognize citation keys starting with a digit.
* Update documentation accordingly.
* Test case added.

See https://github.com/jgm/pandoc-citeproc/issues/97
---
 README                          |  2 +-
 src/Text/Pandoc/Parsing.hs      |  2 +-
 tests/Tests/Readers/Markdown.hs | 22 ++++++++++++++++++++++
 3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/README b/README
index 160fc539e..418a3ff52 100644
--- a/README
+++ b/README
@@ -2616,7 +2616,7 @@ can be found at <https://github.com/citation-style-language/styles>.  See also
 Citations go inside square brackets and are separated by semicolons.
 Each citation must have a key, composed of '@' + the citation
 identifier from the database, and may optionally have a prefix,
-a locator, and a suffix.  The citation key must begin with a letter
+a locator, and a suffix.  The citation key must begin with a letter, digit,
 or `_`, and may contain alphanumerics, `_`, and internal punctuation
 characters (`:.#$%&-+?<>~/`).  Here are some examples:
 
diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs
index 28ea2bd2f..facf4d3b9 100644
--- a/src/Text/Pandoc/Parsing.hs
+++ b/src/Text/Pandoc/Parsing.hs
@@ -1212,7 +1212,7 @@ citeKey = try $ do
   guard =<< notAfterString
   suppress_author <- option False (char '-' *> return True)
   char '@'
-  firstChar <- letter <|> char '_'
+  firstChar <- alphaNum <|> char '_'
   let regchar = satisfy (\c -> isAlphaNum c || c == '_')
   let internal p = try $ p <* lookAhead regchar
   rest <- many $ regchar <|> internal (oneOf ":.#$%&-+?<>~/")
diff --git a/tests/Tests/Readers/Markdown.hs b/tests/Tests/Readers/Markdown.hs
index fdb1a7417..b8d118d78 100644
--- a/tests/Tests/Readers/Markdown.hs
+++ b/tests/Tests/Readers/Markdown.hs
@@ -289,4 +289,26 @@ tests = [ testGroup "inline code"
                          , plain "b"
                          , plain "c" <> bulletList [plain "d"] ]
           ]
+        , testGroup "citations"
+          [ "simple" =:
+            "@item1" =?> para (cite [
+                Citation{ citationId      = "item1"
+                        , citationPrefix  = []
+                        , citationSuffix  = []
+                        , citationMode    = AuthorInText
+                        , citationNoteNum = 0
+                        , citationHash    = 0
+                        }
+                ] "@item1")
+          , "key starts with digit" =:
+            "@1657:huyghens" =?> para (cite [
+                Citation{ citationId      = "1657:huyghens"
+                        , citationPrefix  = []
+                        , citationSuffix  = []
+                        , citationMode    = AuthorInText
+                        , citationNoteNum = 0
+                        , citationHash    = 0
+                        }
+                ] "@1657:huyghens")
+          ]
         ]