From a49cd34983d9c1299dd7ae9c50d7c28e558d5bdb Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 18 Oct 2018 23:52:38 -0700 Subject: Man reader: improve list parsing. We now handle all kinds of ordered list markers. We also avoid having an extra bullet character in bullet list contents. --- src/Text/Pandoc/Readers/Man.hs | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/Man.hs b/src/Text/Pandoc/Readers/Man.hs index f10546839..533c50eef 100644 --- a/src/Text/Pandoc/Readers/Man.hs +++ b/src/Text/Pandoc/Readers/Man.hs @@ -561,32 +561,25 @@ parseList = do where - macroIPInl :: [RoffStr] -> Inlines - macroIPInl (x:_:[]) = strToInlines x <> B.space - macroIPInl _ = mempty - - listKind :: [RoffStr] -> Maybe ListBuilder - listKind (((c:_), _):_:[]) = - let params style = orderedListWith (1, style, DefaultDelim) - in case c of - _ | isDigit c -> Just $ params Decimal - _ | isUpper c -> Just $ params UpperAlpha - _ | isLower c -> Just $ params LowerAlpha - _ -> Nothing - - listKind _ = Nothing + listKind :: [RoffStr] -> ListBuilder + listKind ((cs, _):_:[]) = + let cs' = if not ('.' `elem` cs || ')' `elem` cs) then cs ++ "." else cs + in case Parsec.runParser anyOrderedListMarker defaultParserState + "list marker" cs' of + Right (start, listtype, listdelim) + | cs == cs' -> orderedListWith (start, listtype, listdelim) + | otherwise -> orderedListWith (start, listtype, DefaultDelim) + Left _ -> bulletList + listKind _ = bulletList paras :: PandocMonad m => ManParser m (ListBuilder, Blocks) paras = do (MMacro _ args) <- mmacro KTab - let lbuilderOpt = listKind args - lbuilder = fromMaybe bulletList lbuilderOpt - macroinl = macroIPInl args + let lbuilder = listKind args inls <- parseInlines - let parainls = if isNothing lbuilderOpt then macroinl <> inls else inls subls <- mconcat <$> many sublist - return $ (lbuilder, plain parainls <> subls) - + return $ (lbuilder, plain inls <> subls) + sublist :: PandocMonad m => ManParser m Blocks sublist = do mmacro KSubTab -- cgit v1.2.3