diff options
author | John MacFarlane <jgm@berkeley.edu> | 2018-10-18 23:52:38 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2018-10-18 23:54:13 -0700 |
commit | a49cd34983d9c1299dd7ae9c50d7c28e558d5bdb (patch) | |
tree | f16f518f8b22108e697414fd3bc5c3376d94b337 /src/Text/Pandoc | |
parent | b59ba39e1ad17d62f67b071a97b4dc820b447be5 (diff) | |
download | pandoc-a49cd34983d9c1299dd7ae9c50d7c28e558d5bdb.tar.gz |
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.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Readers/Man.hs | 33 |
1 files changed, 13 insertions, 20 deletions
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 |