@@ -34,7 +34,7 @@ import Text.Pandoc.Definition
3434import Text.Pandoc.Shared
3535import Text.Pandoc.Parsing
3636import Text.ParserCombinators.Parsec
37−import Control.Monad ( when )
37+import Control.Monad ( when, liftM )
3838import Data.List ( findIndex, intercalate, transpose, sort, deleteFirstsBy )
3939import qualified Data.Map as M
4040import Text.Printf ( printf )
@@ -540,9 +540,15 @@ noteBlock = try $ do
540540 return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
541541
542542noteMarker :: GenParser Char ParserState [Char]
543−noteMarker = char '[' >> (many1 digit <|> count 1 (oneOf "#*")) >>~ char ']'
543+noteMarker = do
544+ char '['
545+ res <- many1 digit
546+ <|> (try $ char '#' >> liftM ('#':) simpleReferenceName')
547+ <|> count 1 (oneOf "#*")
548+ char ']'
549+ return res
544550
545−--
551+--
546552-- reference key
547553--
548554
@@ -557,13 +563,20 @@ unquotedReferenceName = try $ do
557563 label' <- many1Till inline (lookAhead $ char ':')
558564 return label'
559565
560−isolated :: Char -> GenParser Char st Char
561−isolated ch = try $ char ch >>~ notFollowedBy (char ch)
566+-- Simple reference names are single words consisting of alphanumerics
567+-- plus isolated (no two adjacent) internal hyphens, underscores,
568+-- periods, colons and plus signs; no whitespace or other characters
569+-- are allowed.
570+simpleReferenceName' :: GenParser Char st String
571+simpleReferenceName' = do
572+ x <- alphaNum
573+ xs <- many $ alphaNum
574+ <|> (try $ oneOf "-_:+." >> lookAhead alphaNum)
575+ return (x:xs)
562576
563577simpleReferenceName :: GenParser Char st [Inline]
564578simpleReferenceName = do
565− raw <- many1 (alphaNum <|> isolated '-' <|> isolated '.' <|>
566− (try $ char '_' >>~ lookAhead alphaNum))
579+ raw <- simpleReferenceName'
567580 return [Str raw]
568581
569582referenceName :: GenParser Char ParserState [Inline]