aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2017-11-20 16:48:43 -0800
committerJohn MacFarlane <[email protected]>2017-11-20 16:48:43 -0800
commit04d9b9b6df55af0f64f8669f5b352b573d8ebcba (patch)
treee31b8d97ef75ad2902580a40905b2302256bb8c3
parent35ced1621df6b1dfe7de79e994343a539b624d8d (diff)
Allow URI as cite key.uri-cite-key
This affects Markdown and Org with `+citations`. Note that we had to constrain the type of the `citeKey` parser in `Text.Pandoc.Parsing` to accept `[Char]` instead of arbitrary streams.
-rw-r--r--MANUAL.txt5
-rw-r--r--src/Text/Pandoc/Parsing.hs20
-rw-r--r--test/Tests/Readers/Markdown.hs10
3 files changed, 25 insertions, 10 deletions
diff --git a/MANUAL.txt b/MANUAL.txt
index 934556c8a..53bab3265 100644
--- a/MANUAL.txt
+++ b/MANUAL.txt
@@ -3558,7 +3558,8 @@ 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, digit,
or `_`, and may contain alphanumerics, `_`, and internal punctuation
-characters (`:.#$%&-+?<>~/`). Here are some examples:
+characters (`:.#$%&-+?<>~/`). Alternatively, a URI may be used.
+Here are some examples:
Blah blah [see @doe99, pp. 33-35; also @smith04, chap. 1].
@@ -3566,6 +3567,8 @@ characters (`:.#$%&-+?<>~/`). Here are some examples:
Blah blah [@smith04; @doe99].
+ Blah blah [@https://example.com/refs?number=30553, chap. 1].
+
`pandoc-citeproc` detects locator terms in the [CSL locale files].
Either abbreviated or unabbreviated forms are accepted. In the `en-US`
locale, locator terms can be written in either singular or plural forms,
diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs
index c86f6718a..9475081c4 100644
--- a/src/Text/Pandoc/Parsing.hs
+++ b/src/Text/Pandoc/Parsing.hs
@@ -548,7 +548,7 @@ emailAddress = try $ toResult <$> mailbox <*> (char '@' *> domain)
sepby1 p sep = (:) <$> p <*> many (try $ sep >> p)
-uriScheme :: Stream s m Char => ParserT s st m String
+uriScheme :: (Monad m, Stream s m Char) => ParserT s st m String
uriScheme = oneOfStringsCI (Set.toList schemes)
-- | Parses a URI. Returns pair of original and URI-escaped version.
@@ -1388,18 +1388,20 @@ nested p = do
updateState $ \st -> st{ stateMaxNestingLevel = nestlevel }
return res
-citeKey :: (Stream s m Char, HasLastStrPosition st)
- => ParserT s st m (Bool, String)
+citeKey :: (Monad m, HasLastStrPosition st)
+ => ParserT [Char] st m (Bool, String)
citeKey = try $ do
guard =<< notAfterString
suppress_author <- option False (char '-' *> return True)
char '@'
- firstChar <- alphaNum <|> char '_' <|> char '*' -- @* for wildcard in nocite
- let regchar = satisfy (\c -> isAlphaNum c || c == '_')
- let internal p = try $ p <* lookAhead regchar
- rest <- many $ regchar <|> internal (oneOf ":.#$%&-+?<>~/") <|>
- try (oneOf ":/" <* lookAhead (char '/'))
- let key = firstChar:rest
+ key <- (fst <$> uri) <|>
+ do firstChar <- alphaNum <|> char '_' <|> char '*'
+ -- @* for wildcard in nocite
+ let regchar = satisfy (\c -> isAlphaNum c || c == '_')
+ let internal p = try $ p <* lookAhead regchar
+ rest <- many $ regchar <|> internal (oneOf ":.#$%&-+?<>~/") <|>
+ try (oneOf ":/" <* lookAhead (char '/'))
+ return (firstChar:rest)
return (suppress_author, key)
diff --git a/test/Tests/Readers/Markdown.hs b/test/Tests/Readers/Markdown.hs
index 1cd32b87d..393b0baa4 100644
--- a/test/Tests/Readers/Markdown.hs
+++ b/test/Tests/Readers/Markdown.hs
@@ -417,6 +417,16 @@ tests = [ testGroup "inline code"
, citationHash = 0
}
] "@1657:huyghens")
+ , "key is URI" =:
+ "@https://example.com/cgi-bin/ubb/forumdisplay.cgi?action=topics&number=527" =?> para (cite [
+ Citation{ citationId = "https://example.com/cgi-bin/ubb/forumdisplay.cgi?action=topics&number=527"
+ , citationPrefix = []
+ , citationSuffix = []
+ , citationMode = AuthorInText
+ , citationNoteNum = 0
+ , citationHash = 0
+ }
+ ] "@https://example.com/cgi-bin/ubb/forumdisplay.cgi?action=topics&number=527")
]
, let citation = cite [Citation "cita" [] [] AuthorInText 0 0] (str "@cita")
in testGroup "footnote/link following citation" -- issue #2083