diff options
-rw-r--r-- | src/Text/Pandoc/Readers/MediaWiki.hs | 20 | ||||
-rw-r--r-- | tests/mediawiki-reader.native | 1 | ||||
-rw-r--r-- | tests/mediawiki-reader.wiki | 2 |
3 files changed, 15 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 diff --git a/tests/mediawiki-reader.native b/tests/mediawiki-reader.native index 8531ce963..3344b75ec 100644 --- a/tests/mediawiki-reader.native +++ b/tests/mediawiki-reader.native @@ -72,6 +72,7 @@ Pandoc (Meta {docTitle = [], docAuthors = [], docDate = []}) ,Header 2 [Str "external",Space,Str "links"] ,Para [Link [Emph [Str "Google"],Space,Str "search",Space,Str "engine"] ("http://google.com","")] ,Para [Link [Str "http://johnmacfarlane.net/pandoc/"] ("http://johnmacfarlane.net/pandoc/","")] +,Para [Link [Str "1"] ("http://google.com",""),Space,Link [Str "2"] ("http://yahoo.com","")] ,Header 2 [Str "lists"] ,BulletList [[Plain [Str "Start",Space,Str "each",Space,Str "line"]] diff --git a/tests/mediawiki-reader.wiki b/tests/mediawiki-reader.wiki index 1408ceb4d..0878e667d 100644 --- a/tests/mediawiki-reader.wiki +++ b/tests/mediawiki-reader.wiki @@ -143,6 +143,8 @@ Nother paragraph. http://johnmacfarlane.net/pandoc/ +[http://google.com] [http://yahoo.com] + == lists == * Start each line |