Move citeKey
from Readers.Markdown to Parsing
The function can be used by other readers, so it is made accessible for all parsers.
This commit is contained in:
parent
9df589b9c5
commit
2423f9e6b1
2 changed files with 13 additions and 14 deletions
|
@ -94,6 +94,7 @@ module Text.Pandoc.Parsing ( (>>~),
|
|||
apostrophe,
|
||||
dash,
|
||||
nested,
|
||||
citeKey,
|
||||
macro,
|
||||
applyMacros',
|
||||
Parser,
|
||||
|
@ -1144,6 +1145,18 @@ nested p = do
|
|||
updateState $ \st -> st{ stateMaxNestingLevel = nestlevel }
|
||||
return res
|
||||
|
||||
citeKey :: HasLastStrPosition st => Parser [Char] st (Bool, String)
|
||||
citeKey = try $ do
|
||||
guard =<< notAfterString
|
||||
suppress_author <- option False (char '-' *> return True)
|
||||
char '@'
|
||||
firstChar <- letter <|> char '_'
|
||||
let regchar = satisfy (\c -> isAlphaNum c || c == '_')
|
||||
let internal p = try $ p <* lookAhead regchar
|
||||
rest <- many $ regchar <|> internal (oneOf ":.#$%&-+?<>~/")
|
||||
let key = firstChar:rest
|
||||
return (suppress_author, key)
|
||||
|
||||
--
|
||||
-- Macros
|
||||
--
|
||||
|
|
|
@ -1814,20 +1814,6 @@ normalCite = try $ do
|
|||
char ']'
|
||||
return citations
|
||||
|
||||
citeKey :: MarkdownParser (Bool, String)
|
||||
citeKey = try $ do
|
||||
-- make sure we're not right after an alphanumeric,
|
||||
-- since foo@bar.baz is probably an email address
|
||||
guard =<< notAfterString
|
||||
suppress_author <- option False (char '-' >> return True)
|
||||
char '@'
|
||||
first <- letter <|> char '_'
|
||||
let regchar = satisfy (\c -> isAlphaNum c || c == '_')
|
||||
let internal p = try $ p >>~ lookAhead regchar
|
||||
rest <- many $ regchar <|> internal (oneOf ":.#$%&-+?<>~/")
|
||||
let key = first:rest
|
||||
return (suppress_author, key)
|
||||
|
||||
suffix :: MarkdownParser (F Inlines)
|
||||
suffix = try $ do
|
||||
hasSpace <- option False (notFollowedBy nonspaceChar >> return True)
|
||||
|
|
Loading…
Add table
Reference in a new issue