MediaWiki reader: Implemented numbered external links.

This commit is contained in:
John MacFarlane
2012-09-13 15:24:05 -07:00
parent 8cc5625bd6
commit 017095f690
3 changed files with 15 additions and 8 deletions
+12 -8
View File
@@ -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
+1
View File
@@ -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"]]
+2
View File
@@ -143,6 +143,8 @@ Nother paragraph.
http://johnmacfarlane.net/pandoc/
[http://google.com] [http://yahoo.com]
== lists ==
* Start each line