@@ -52,6 +52,7 @@ import Data.List ( intersect, intercalate, isPrefixOf )
5252import Network.URI ( isURI )
5353import Control.Monad ( zipWithM )
5454import Control.Monad.State ( modify, State, get, gets, evalState )
55+import Control.Applicative ( (<$>) )
5556
5657data WriterState = WriterState {
5758 stNotes :: Bool -- True if there are notes
@@ -73,7 +74,7 @@ pandocToDokuWiki opts (Pandoc meta blocks) = do
7374 (inlineListToDokuWiki opts)
7475 meta
7576 body <- blockListToDokuWiki opts blocks
76− notesExist <- get >>= return . stNotes
77+ notesExist <- stNotes <$> get
7778 let notes = if notesExist
7879 then "" -- TODO Was "\n<references />" Check whether I can really remove this:
7980 -- if it is definitely to do with footnotes, can remove this whole bit
@@ -179,8 +180,8 @@ blockToDokuWiki opts (Table capt aligns _ headers rows') = do
179180 unlines body'
180181
181182blockToDokuWiki opts x@(BulletList items) = do
182− oldUseTags <- get >>= return . stUseTags
183− indent <- get >>= return . stIndent
183+ oldUseTags <- stUseTags <$> get
184+ indent <- stIndent <$> get
184185 let useTags = oldUseTags || not (isSimpleList x)
185186 if useTags
186187 then do
@@ -195,8 +196,8 @@ blockToDokuWiki opts x@(BulletList items) = do
195196 return $ vcat contents ++ if null indent then "\n" else ""
196197
197198blockToDokuWiki opts x@(OrderedList attribs items) = do
198− oldUseTags <- get >>= return . stUseTags
199− indent <- get >>= return . stIndent
199+ oldUseTags <- stUseTags <$> get
200+ indent <- stIndent <$> get
200201 let useTags = oldUseTags || not (isSimpleList x)
201202 if useTags
202203 then do
@@ -214,8 +215,8 @@ blockToDokuWiki opts x@(OrderedList attribs items) = do
214215-- is a specific representation of them.
215216-- TODO This creates double '; ; ' if there is a bullet or ordered list inside a definition list
216217blockToDokuWiki opts x@(DefinitionList items) = do
217− oldUseTags <- get >>= return . stUseTags
218− indent <- get >>= return . stIndent
218+ oldUseTags <- stUseTags <$> get
219+ indent <- stIndent <$> get
219220 let useTags = oldUseTags || not (isSimpleList x)
220221 if useTags
221222 then do
@@ -246,11 +247,11 @@ listAttribsToString (startnum, numstyle, _) =
246247listItemToDokuWiki :: WriterOptions -> [Block] -> State WriterState String
247248listItemToDokuWiki opts items = do
248249 contents <- blockListToDokuWiki opts items
249− useTags <- get >>= return . stUseTags
250+ useTags <- stUseTags <$> get
250251 if useTags
251252 then return $ "<HTML><li></HTML>" ++ contents ++ "<HTML></li></HTML>"
252253 else do
253− indent <- get >>= return . stIndent
254+ indent <- stIndent <$> get
254255 return $ indent ++ "* " ++ contents
255256
256257-- | Convert ordered list item (list of blocks) to DokuWiki.
@@ -258,11 +259,11 @@ listItemToDokuWiki opts items = do
258259orderedListItemToDokuWiki :: WriterOptions -> [Block] -> State WriterState String
259260orderedListItemToDokuWiki opts items = do
260261 contents <- blockListToDokuWiki opts items
261− useTags <- get >>= return . stUseTags
262+ useTags <- stUseTags <$> get
262263 if useTags
263264 then return $ "<HTML><li></HTML>" ++ contents ++ "<HTML></li></HTML>"
264265 else do
265− indent <- get >>= return . stIndent
266+ indent <- stIndent <$> get
266267 return $ indent ++ "- " ++ contents
267268
268269-- | Convert definition list item (label, list of blocks) to DokuWiki.
@@ -272,12 +273,12 @@ definitionListItemToDokuWiki :: WriterOptions
272273definitionListItemToDokuWiki opts (label, items) = do
273274 labelText <- inlineListToDokuWiki opts label
274275 contents <- mapM (blockListToDokuWiki opts) items
275− useTags <- get >>= return . stUseTags
276+ useTags <- stUseTags <$> get
276277 if useTags
277278 then return $ "<HTML><dt></HTML>" ++ labelText ++ "<HTML></dt></HTML>\n" ++
278279 (intercalate "\n" $ map (\d -> "<HTML><dd></HTML>" ++ d ++ "<HTML></dd></HTML>") contents)
279280 else do
280− indent <- get >>= return . stIndent
281+ indent <- stIndent <$> get
281282 return $ indent ++ "* **" ++ labelText ++ "** " ++ concat contents
282283
283284-- | True if the list can be handled by simple wiki markup, False if HTML tags will be needed.
@@ -334,8 +335,8 @@ tableHeaderToDokuWiki :: WriterOptions
334335 -> State WriterState String
335336tableHeaderToDokuWiki opts alignStrings rownum cols' = do
336337 let celltype = if rownum == 0 then "" else ""
337− cols'' <- sequence $ zipWith
338− (\alignment item -> tableItemToDokuWiki opts celltype alignment item)
338+ cols'' <- zipWithM
339+ (tableItemToDokuWiki opts celltype)
339340 alignStrings cols'
340341 return $ "^ " ++ "" ++ joinHeaders cols'' ++ " ^"
341342
@@ -346,8 +347,8 @@ tableRowToDokuWiki :: WriterOptions
346347 -> State WriterState String
347348tableRowToDokuWiki opts alignStrings rownum cols' = do
348349 let celltype = if rownum == 0 then "" else ""
349− cols'' <- sequence $ zipWith
350− (\alignment item -> tableItemToDokuWiki opts celltype alignment item)
350+ cols'' <- zipWithM
351+ (tableItemToDokuWiki opts celltype)
351352 alignStrings cols'
352353 return $ "| " ++ "" ++ joinColumns cols'' ++ " |"
353354
@@ -382,18 +383,18 @@ blockListToDokuWiki :: WriterOptions -- ^ Options
382383 -> [Block] -- ^ List of block elements
383384 -> State WriterState String
384385blockListToDokuWiki opts blocks =
385− mapM (blockToDokuWiki opts) blocks >>= return . vcat
386+ vcat <$> mapM (blockToDokuWiki opts) blocks
386387
387388-- | Convert list of Pandoc inline elements to DokuWiki.
388389inlineListToDokuWiki :: WriterOptions -> [Inline] -> State WriterState String
389−inlineListToDokuWiki opts lst = mapM (inlineToDokuWiki opts) lst >>= return . concat
390+inlineListToDokuWiki opts lst =
391+ concat <$> (mapM (inlineToDokuWiki opts) lst)
390392
391393-- | Convert Pandoc inline element to DokuWiki.
392394inlineToDokuWiki :: WriterOptions -> Inline -> State WriterState String
393395
394−inlineToDokuWiki opts (Span _attrs ils) = do
395− contents <- inlineListToDokuWiki opts ils
396− return contents
396+inlineToDokuWiki opts (Span _attrs ils) =
397+ inlineListToDokuWiki opts ils
397398
398399inlineToDokuWiki opts (Emph lst) = do
399400 contents <- inlineListToDokuWiki opts lst
@@ -466,11 +467,10 @@ inlineToDokuWiki opts (Link txt (src, _)) = do
466467 _ -> src -- link to a help page
467468inlineToDokuWiki opts (Image alt (source, tit)) = do
468469 alt' <- inlineListToDokuWiki opts alt
469− let txt = if (null tit)
470− then if null alt
471− then ""
472− else "|" ++ alt'
473− else "|" ++ tit
470+ let txt = case (tit, alt) of
471+ ("", []) -> ""
472+ ("", _ ) -> "|" ++ alt'
473+ (_ , _ ) -> "|" ++ tit
474474 return $ "{{:" ++ source ++ txt ++ "}}"
475475
476476inlineToDokuWiki opts (Note contents) = do