@@ -31,10 +31,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3131
3232Conversion of man to 'Pandoc' document.
3333-}
34−module Text.Pandoc.Readers.Man (readMan) where --testFile
34+module Text.Pandoc.Readers.Man (readMan) where
3535
3636import Prelude
37−import Control.Monad (liftM)
37+import Control.Monad (liftM, void)
3838import Control.Monad.Except (throwError)
3939import Data.Char (isDigit, isUpper, isLower)
4040import Data.Default (Default)
@@ -123,13 +123,11 @@ readMan :: PandocMonad m => ReaderOptions -> T.Text -> m Pandoc
123123readMan opts txt = do
124124 eithertokens <- readWithM lexMan def (T.unpack $ crFilter txt)
125125 case eithertokens of
126+ Left e -> throwError e
126127 Right tokenz -> do
127128 let state = def {stateOptions = opts} :: ParserState
128129 eitherdoc <- readWithMTokens parseMan state tokenz
129− case eitherdoc of
130− Right doc -> return doc
131− Left e -> throwError e
132− Left e -> throwError e
130+ either throwError return eitherdoc
133131
134132 where
135133
@@ -139,7 +137,8 @@ readMan opts txt = do
139137 -> [ManToken] -- ^ input
140138 -> m (Either PandocError a)
141139 readWithMTokens parser state input =
142− mapLeft (PandocParsecError . (intercalate "\n") $ show <$> input) `liftM` runParserT parser state "source" input
140+ let leftF = PandocParsecError . (intercalate "\n") $ show <$> input
141+ in mapLeft leftF `liftM` runParserT parser state "source" input
143142
144143 mapLeft :: (a -> c) -> Either a b -> Either c b
145144 mapLeft f (Left x) = Left $ f x
@@ -166,12 +165,12 @@ parseMan = do
166165 isNull _ = False
167166
168167eofline :: Stream s m Char => ParsecT s u m ()
169−eofline = (newline >> return ()) <|> eof
168+eofline = void newline <|> eof
170169
171170spacetab :: Stream s m Char => ParsecT s u m Char
172171spacetab = char ' ' <|> char '\t'
173172
174−-- TODO handle more cases
173+-- TODO add other sequences from man (7) groff
175174escapeLexer :: PandocMonad m => ManLexer m EscapeThing
176175escapeLexer = do
177176 char '\\'
@@ -225,9 +224,7 @@ escapeLexer = do
225224 return ENothing
226225
227226currentFont :: PandocMonad m => ManLexer m FontKind
228−currentFont = do
229− RoffState {fontKind = fk} <- getState
230− return fk
227+currentFont = fontKind <$> getState
231228
232229-- separate function from lexMacro since real man files sometimes do not follow the rules
233230lexComment :: PandocMonad m => ManLexer m ManToken