@@ -34,7 +34,7 @@ Conversion of man to 'Pandoc' document.
3434module Text.Pandoc.Readers.Man (readMan) where
3535
3636import Prelude
37−import Control.Monad (liftM, void, mzero)
37+import Control.Monad (liftM, void, mzero, guard)
3838import Control.Monad.Except (throwError)
3939import Data.Char (isHexDigit, chr)
4040import Data.Default (Default)
@@ -506,35 +506,41 @@ parseHeader = do
506506 let lvl = if name == "SH" then 1 else 2
507507 return $ header lvl contents
508508
509−type ListBuilder = [Blocks] -> Blocks
509+data ListType = Ordered ListAttributes
510+ | Bullet
511+
512+listTypeMatches :: Maybe ListType -> ListType -> Bool
513+listTypeMatches Nothing _ = True
514+listTypeMatches (Just Bullet) Bullet = True
515+listTypeMatches (Just (Ordered (_,x,y))) (Ordered (_,x',y'))
516+ = x == x' && y == y'
517+listTypeMatches (Just _) _ = False
518+
519+listItem :: PandocMonad m => Maybe ListType -> ManParser m (ListType, Blocks)
520+listItem mbListType = try $ do
521+ (MMacro _ args) <- mmacro "IP"
522+ case args of
523+ [] -> mzero
524+ ((cs,_):_) -> do
525+ let cs' = if not ('.' `elem` cs || ')' `elem` cs) then cs ++ "." else cs
526+ let lt = case Parsec.runParser anyOrderedListMarker defaultParserState
527+ "list marker" cs' of
528+ Right (start, listtype, listdelim)
529+ | cs == cs' -> Ordered (start, listtype, listdelim)
530+ | otherwise -> Ordered (start, listtype, DefaultDelim)
531+ Left _ -> Bullet
532+ guard $ listTypeMatches mbListType lt
533+ inls <- parseInlines
534+ continuations <- mconcat <$> many continuation
535+ return $ (lt, para inls <> continuations)
510536
511537parseList :: PandocMonad m => ManParser m Blocks
512538parseList = try $ do
513− xx <- many1 items
514− let bls = map snd xx
515− let bldr = fst $ head xx
516− return $ bldr bls
517−
518− where
519−
520− listKind :: [RoffStr] -> ListBuilder
521− listKind ((cs, _):_:[]) =
522− let cs' = if not ('.' `elem` cs || ')' `elem` cs) then cs ++ "." else cs
523− in case Parsec.runParser anyOrderedListMarker defaultParserState
524− "list marker" cs' of
525− Right (start, listtype, listdelim)
526− | cs == cs' -> orderedListWith (start, listtype, listdelim)
527− | otherwise -> orderedListWith (start, listtype, DefaultDelim)
528− Left _ -> bulletList
529− listKind _ = bulletList
530−
531− items :: PandocMonad m => ManParser m (ListBuilder, Blocks)
532− items = do
533− (MMacro _ args) <- mmacro "IP"
534− let lbuilder = listKind args
535− inls <- parseInlines
536− continuations <- mconcat <$> many continuation
537− return $ (lbuilder, para inls <> continuations)
539+ (lt, x) <- listItem Nothing
540+ xs <- map snd <$> many (listItem (Just lt))
541+ return $ case lt of
542+ Bullet -> bulletList (x:xs)
543+ Ordered lattr -> orderedListWith lattr (x:xs)
538544
539545continuation :: PandocMonad m => ManParser m Blocks
540546continuation = do