aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2012-09-13 15:24:05 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2012-09-13 15:24:05 -0700
commit017095f690c6b2154e8fbeaecdcc1b99583c1924 (patch)
tree2a929c9420cd49a542423e2bf5ab7605b87ba59f /src
parent8cc5625bd6ef2bda13b156b381d238f21beb789e (diff)
downloadpandoc-017095f690c6b2154e8fbeaecdcc1b99583c1924.tar.gz
MediaWiki reader: Implemented numbered external links.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/MediaWiki.hs20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/Text/Pandoc/Readers/MediaWiki.hs b/src/Text/Pandoc/Readers/MediaWiki.hs
index 62660a1d2..73017b49c 100644
--- a/src/Text/Pandoc/Readers/MediaWiki.hs
+++ b/src/Text/Pandoc/Readers/MediaWiki.hs
@@ -60,13 +60,16 @@ readMediaWiki :: ReaderOptions -- ^ Reader options
-> String -- ^ String to parse (assuming @'\n'@ line endings)
-> Pandoc
readMediaWiki opts s =
- case runParser parseMediaWiki MWState{ mwOptions = opts, mwMaxNestingLevel = 4 }
+ case runParser parseMediaWiki MWState{ mwOptions = opts
+ , mwMaxNestingLevel = 4
+ , mwNextLinkNumber = 1 }
"source" (s ++ "\n") of
Left err' -> error $ "\nError:\n" ++ show err'
Right result -> result
-data MWState = MWState { mwOptions :: ReaderOptions
+data MWState = MWState { mwOptions :: ReaderOptions
, mwMaxNestingLevel :: Int
+ , mwNextLinkNumber :: Int
}
type MWParser = Parser [Char] MWState
@@ -369,12 +372,13 @@ externalLink :: MWParser Inlines
externalLink = try $ do
char '['
(_, src) <- uri
- skipMany1 spaceChar
- lab <- manyTill inline (char ']')
- let lab' = if null lab
- then [B.str "1"] -- TODO generate sequentially from state
- else lab
- return $ B.link src "" $ trimInlines $ mconcat lab'
+ lab <- try (trimInlines . mconcat <$>
+ (skipMany1 spaceChar *> manyTill inline (char ']')))
+ <|> do char ']'
+ num <- mwNextLinkNumber <$> getState
+ updateState $ \st -> st{ mwNextLinkNumber = num + 1 }
+ return $ B.str $ show num
+ return $ B.link src "" lab
url :: MWParser Inlines
url = do