aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2020-11-18 22:44:32 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2020-11-18 22:44:32 -0800
commit0962b30d8428ef875034c15ae7d9c67c62c2f177 (patch)
treee2cbb1b6986fa7ac2ef6fba02a3145870e57f9c9 /src/Text/Pandoc/Readers
parent3f278f580e82670999b2bc8e6f10001b792c574c (diff)
downloadpandoc-0962b30d8428ef875034c15ae7d9c67c62c2f177.tar.gz
Man reader: improve handling of .IP.
We now better handle `.IP` when it is used with non-bullet, non-numbered lists, creating a definition list. We also skip blank lines like groff itself. Closes #6858.
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r--src/Text/Pandoc/Readers/Man.hs24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Readers/Man.hs b/src/Text/Pandoc/Readers/Man.hs
index e87d07bd9..21b8feaab 100644
--- a/src/Text/Pandoc/Readers/Man.hs
+++ b/src/Text/Pandoc/Readers/Man.hs
@@ -407,12 +407,14 @@ parseBlockQuote = blockQuote <$> continuation
data ListType = Ordered ListAttributes
| Bullet
+ | Definition T.Text
listTypeMatches :: Maybe ListType -> ListType -> Bool
listTypeMatches Nothing _ = True
listTypeMatches (Just Bullet) Bullet = True
listTypeMatches (Just (Ordered (_,x,y))) (Ordered (_,x',y'))
= x == x' && y == y'
+listTypeMatches (Just (Definition _)) (Definition _) = True
listTypeMatches (Just _) _ = False
listItem :: PandocMonad m => Maybe ListType -> ManParser m (ListType, Blocks)
@@ -427,20 +429,28 @@ listItem mbListType = try $ do
Right (start, listtype, listdelim)
| cs == cs' -> Ordered (start, listtype, listdelim)
| otherwise -> Ordered (start, listtype, DefaultDelim)
- Left _ -> Bullet
+ Left _
+ | cs == "\183" || cs == "-" || cs == "*" || cs == "+"
+ -> Bullet
+ | otherwise -> Definition cs
guard $ listTypeMatches mbListType lt
+ skipMany memptyLine
inls <- option mempty parseInlines
+ skipMany memptyLine
continuations <- mconcat <$> many continuation
return (lt, para inls <> continuations)
[] -> mzero
parseList :: PandocMonad m => ManParser m Blocks
parseList = try $ do
- (lt, x) <- listItem Nothing
- xs <- map snd <$> many (listItem (Just lt))
+ x@(lt, _) <- listItem Nothing
+ xs <- many (listItem (Just lt))
+ let toDefItem (Definition t, bs) = (B.text t, [bs])
+ toDefItem _ = mempty
return $ case lt of
- Bullet -> bulletList (x:xs)
- Ordered lattr -> orderedListWith lattr (x:xs)
+ Bullet -> bulletList $ map snd (x:xs)
+ Ordered lattr -> orderedListWith lattr $ map snd (x:xs)
+ Definition _ -> definitionList $ map toDefItem (x:xs)
continuation :: PandocMonad m => ManParser m Blocks
continuation =
@@ -453,11 +463,15 @@ definitionListItem :: PandocMonad m
=> ManParser m (Inlines, [Blocks])
definitionListItem = try $ do
mmacro "TP" -- args specify indent level, can ignore
+ skipMany memptyLine
term <- parseInline
+ skipMany memptyLine
moreterms <- many $ try $ do
mmacro "TQ"
parseInline
+ skipMany memptyLine
inls <- option mempty parseInlines
+ skipMany memptyLine
continuations <- mconcat <$> many continuation
return ( mconcat (intersperse B.linebreak (term:moreterms))
, [para inls <> continuations])