git.iko.soy/typeable/pandoc
on master help sign in
RST reader: Partial support for labeled footnotes.
35cef01John MacFarlane
src/Text/Pandoc/Readers/RST.hs+20−7
@@ -34,7 +34,7 @@ import Text.Pandoc.Definition
34import Text.Pandoc.Shared
34import Text.Pandoc.Shared
35import Text.Pandoc.Parsing
35import Text.Pandoc.Parsing
36import Text.ParserCombinators.Parsec
36import Text.ParserCombinators.Parsec
37−import Control.Monad ( when )
37+import Control.Monad ( when, liftM )
38import Data.List ( findIndex, intercalate, transpose, sort, deleteFirstsBy )
38import Data.List ( findIndex, intercalate, transpose, sort, deleteFirstsBy )
39import qualified Data.Map as M
39import qualified Data.Map as M
40import Text.Printf ( printf )
40import Text.Printf ( printf )
@@ -540,9 +540,15 @@ noteBlock = try $ do
540 return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
540 return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
541
541
542noteMarker :: GenParser Char ParserState [Char]
542noteMarker :: GenParser Char ParserState [Char]
543+noteMarker = do
544+ char '['
545+ res <- many1 digit
546+ <|> (try $ char '#' >> liftM ('#':) simpleReferenceName')
543−noteMarker = char '[' >> (many1 digit <|> count 1 (oneOf "#*")) >>~ char ']'
547+ <|> count 1 (oneOf "#*")
548+ char ']'
549+ return res
544
550
545−--
551+--
546-- reference key
552-- reference key
547--
553--
548
554
@@ -557,13 +563,20 @@ unquotedReferenceName = try $ do
557 label' <- many1Till inline (lookAhead $ char ':')
563 label' <- many1Till inline (lookAhead $ char ':')
558 return label'
564 return label'
559
565
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.
560−isolated :: Char -> GenParser Char st Char
570+simpleReferenceName' :: GenParser Char st String
561−isolated ch = try $ char ch >>~ notFollowedBy (char ch)
571+simpleReferenceName' = do
572+ x <- alphaNum
573+ xs <- many $ alphaNum
574+ <|> (try $ oneOf "-_:+." >> lookAhead alphaNum)
575+ return (x:xs)
562
576
563simpleReferenceName :: GenParser Char st [Inline]
577simpleReferenceName :: GenParser Char st [Inline]
564simpleReferenceName = do
578simpleReferenceName = do
565− raw <- many1 (alphaNum <|> isolated '-' <|> isolated '.' <|>
579+ raw <- simpleReferenceName'
566− (try $ char '_' >>~ lookAhead alphaNum))
567 return [Str raw]
580 return [Str raw]
568
581
569referenceName :: GenParser Char ParserState [Inline]
582referenceName :: GenParser Char ParserState [Inline]