@@ -34,7 +34,7 @@ Conversion of 'Pandoc' documents to Emacs Org-Mode.
3434
3535Org-Mode: <http://orgmode.org>
3636-}
37−module Text.Pandoc.Writers.Org ( writeOrg) where
37+module Text.Pandoc.Writers.Org (writeOrg) where
3838import Control.Monad.State
3939import Data.Char (isAlphaNum, toLower)
4040import Data.List (intersect, intersperse, isPrefixOf, partition, transpose)
@@ -77,9 +77,9 @@ pandocToOrg (Pandoc meta blocks) = do
7777 body <- blockListToOrg blocks
7878 notes <- gets (reverse . stNotes) >>= notesToOrg
7979 hasMath <- gets stHasMath
80− let main = render colwidth $ foldl ($+$) empty $ [body, notes]
80+ let main = render colwidth . foldl ($+$) empty $ [body, notes]
8181 let context = defField "body" main
82− $ defField "math" hasMath
82+ . defField "math" hasMath
8383 $ metadata
8484 case writerTemplate opts of
8585 Nothing -> return main
@@ -88,8 +88,7 @@ pandocToOrg (Pandoc meta blocks) = do
8888-- | Return Org representation of notes.
8989notesToOrg :: PandocMonad m => [[Block]] -> Org m Doc
9090notesToOrg notes =
91− mapM (\(num, note) -> noteToOrg num note) (zip [1..] notes) >>=
92− return . vsep
91+ vsep <$> zipWithM noteToOrg [1..] notes
9392
9493-- | Return Org representation of a note.
9594noteToOrg :: PandocMonad m => Int -> [Block] -> Org m Doc
@@ -221,16 +220,16 @@ blockToOrg (Table caption' _ _ headers rows) = do
221220 -- FIXME: Org doesn't allow blocks with height more than 1.
222221 let hpipeBlocks blocks = hcat [beg, middle, end]
223222 where h = maximum (1 : map height blocks)
224− sep' = lblock 3 $ vcat (map text $ replicate h " | ")
225− beg = lblock 2 $ vcat (map text $ replicate h "| ")
226− end = lblock 2 $ vcat (map text $ replicate h " |")
223+ sep' = lblock 3 $ vcat (replicate h (text " | "))
224+ beg = lblock 2 $ vcat (replicate h (text "| "))
225+ end = lblock 2 $ vcat (replicate h (text " |"))
227226 middle = hcat $ intersperse sep' blocks
228227 let makeRow = hpipeBlocks . zipWith lblock widthsInChars
229228 let head' = makeRow headers'
230229 rows' <- mapM (\row -> do cols <- mapM blockListToOrg row
231230 return $ makeRow cols) rows
232231 let border ch = char '|' <> char ch <>
233− (hcat $ intersperse (char ch <> char '+' <> char ch) $
232+ (hcat . intersperse (char ch <> char '+' <> char ch) $
234233 map (\l -> text $ replicate l ch) widthsInChars) <>
235234 char ch <> char '|'
236235 let body = vcat rows'
@@ -251,8 +250,7 @@ blockToOrg (OrderedList (start, _, delim) items) = do
251250 let maxMarkerLength = maximum $ map length markers
252251 let markers' = map (\m -> let s = maxMarkerLength - length m
253252 in m ++ replicate s ' ') markers
254− contents <- mapM (\(item, num) -> orderedListItemToOrg item num) $
255− zip markers' items
253+ contents <- zipWithM orderedListItemToOrg markers' items
256254 -- ensure that sublists have preceding blank line
257255 return $ blankline $$ vcat contents $$ blankline
258256blockToOrg (DefinitionList items) = do
@@ -279,8 +277,8 @@ definitionListItemToOrg :: PandocMonad m
279277 => ([Inline], [[Block]]) -> Org m Doc
280278definitionListItemToOrg (label, defs) = do
281279 label' <- inlineListToOrg label
282− contents <- liftM vcat $ mapM blockListToOrg defs
283− return $ hang 2 "- " $ label' <> " :: " <> (contents <> cr)
280+ contents <- vcat <$> mapM blockListToOrg defs
281+ return . hang 2 "- " $ label' <> " :: " <> (contents <> cr)
284282
285283-- | Convert list of key/value pairs to Org :PROPERTIES: drawer.
286284propertiesDrawer :: Attr -> Doc
@@ -312,13 +310,13 @@ attrHtml (ident, classes, kvs) =
312310blockListToOrg :: PandocMonad m
313311 => [Block] -- ^ List of block elements
314312 -> Org m Doc
315−blockListToOrg blocks = mapM blockToOrg blocks >>= return . vcat
313+blockListToOrg blocks = vcat <$> mapM blockToOrg blocks
316314
317315-- | Convert list of Pandoc inline elements to Org.
318316inlineListToOrg :: PandocMonad m
319317 => [Inline]
320318 -> Org m Doc
321−inlineListToOrg lst = mapM inlineToOrg lst >>= return . hcat
319+inlineListToOrg lst = hcat <$> mapM inlineToOrg lst
322320
323321-- | Convert Pandoc inline element to Org.
324322inlineToOrg :: PandocMonad m => Inline -> Org m Doc
@@ -350,7 +348,7 @@ inlineToOrg (Quoted DoubleQuote lst) = do
350348 return $ "\"" <> contents <> "\""
351349inlineToOrg (Cite _ lst) = inlineListToOrg lst
352350inlineToOrg (Code _ str) = return $ "=" <> text str <> "="
353−inlineToOrg (Str str) = return $ text $ escapeString str
351+inlineToOrg (Str str) = return . text $ escapeString str
354352inlineToOrg (Math t str) = do
355353 modify $ \st -> st{ stHasMath = True }
356354 return $ if t == InlineMath