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.
This commit is contained in:
John MacFarlane 2020-11-18 22:44:32 -08:00
parent 3f278f580e
commit 0962b30d84
2 changed files with 71 additions and 5 deletions

View file

@ -407,12 +407,14 @@ parseBlockQuote = blockQuote <$> continuation
data ListType = Ordered ListAttributes data ListType = Ordered ListAttributes
| Bullet | Bullet
| Definition T.Text
listTypeMatches :: Maybe ListType -> ListType -> Bool listTypeMatches :: Maybe ListType -> ListType -> Bool
listTypeMatches Nothing _ = True listTypeMatches Nothing _ = True
listTypeMatches (Just Bullet) Bullet = True listTypeMatches (Just Bullet) Bullet = True
listTypeMatches (Just (Ordered (_,x,y))) (Ordered (_,x',y')) listTypeMatches (Just (Ordered (_,x,y))) (Ordered (_,x',y'))
= x == x' && y == y' = x == x' && y == y'
listTypeMatches (Just (Definition _)) (Definition _) = True
listTypeMatches (Just _) _ = False listTypeMatches (Just _) _ = False
listItem :: PandocMonad m => Maybe ListType -> ManParser m (ListType, Blocks) listItem :: PandocMonad m => Maybe ListType -> ManParser m (ListType, Blocks)
@ -427,20 +429,28 @@ listItem mbListType = try $ do
Right (start, listtype, listdelim) Right (start, listtype, listdelim)
| cs == cs' -> Ordered (start, listtype, listdelim) | cs == cs' -> Ordered (start, listtype, listdelim)
| otherwise -> Ordered (start, listtype, DefaultDelim) | otherwise -> Ordered (start, listtype, DefaultDelim)
Left _ -> Bullet Left _
| cs == "\183" || cs == "-" || cs == "*" || cs == "+"
-> Bullet
| otherwise -> Definition cs
guard $ listTypeMatches mbListType lt guard $ listTypeMatches mbListType lt
skipMany memptyLine
inls <- option mempty parseInlines inls <- option mempty parseInlines
skipMany memptyLine
continuations <- mconcat <$> many continuation continuations <- mconcat <$> many continuation
return (lt, para inls <> continuations) return (lt, para inls <> continuations)
[] -> mzero [] -> mzero
parseList :: PandocMonad m => ManParser m Blocks parseList :: PandocMonad m => ManParser m Blocks
parseList = try $ do parseList = try $ do
(lt, x) <- listItem Nothing x@(lt, _) <- listItem Nothing
xs <- map snd <$> many (listItem (Just lt)) xs <- many (listItem (Just lt))
let toDefItem (Definition t, bs) = (B.text t, [bs])
toDefItem _ = mempty
return $ case lt of return $ case lt of
Bullet -> bulletList (x:xs) Bullet -> bulletList $ map snd (x:xs)
Ordered lattr -> orderedListWith lattr (x:xs) Ordered lattr -> orderedListWith lattr $ map snd (x:xs)
Definition _ -> definitionList $ map toDefItem (x:xs)
continuation :: PandocMonad m => ManParser m Blocks continuation :: PandocMonad m => ManParser m Blocks
continuation = continuation =
@ -453,11 +463,15 @@ definitionListItem :: PandocMonad m
=> ManParser m (Inlines, [Blocks]) => ManParser m (Inlines, [Blocks])
definitionListItem = try $ do definitionListItem = try $ do
mmacro "TP" -- args specify indent level, can ignore mmacro "TP" -- args specify indent level, can ignore
skipMany memptyLine
term <- parseInline term <- parseInline
skipMany memptyLine
moreterms <- many $ try $ do moreterms <- many $ try $ do
mmacro "TQ" mmacro "TQ"
parseInline parseInline
skipMany memptyLine
inls <- option mempty parseInlines inls <- option mempty parseInlines
skipMany memptyLine
continuations <- mconcat <$> many continuation continuations <- mconcat <$> many continuation
return ( mconcat (intersperse B.linebreak (term:moreterms)) return ( mconcat (intersperse B.linebreak (term:moreterms))
, [para inls <> continuations]) , [para inls <> continuations])

52
test/command/6858.md Normal file
View file

@ -0,0 +1,52 @@
```
% pandoc -t markdown -f man
.TH FvwmAnimate 1 "Date" Fvwm "Fvwm Modules"
.UC
.SH NAME
\fBFvwmAnimate\fP \- the fvwm animate module
.SH SYNOPSIS
Module FvwmAnimate [ModuleAlias]
.IP "*FvwmAnimate: Color \fBcolor\fP"
Tells \fBFvwmAnimate\fP what color to draw with.
The color is "XOR'ed" (exclusive ORed) onto the background.
.IP "*FvwmAnimate: Pixmap \fBpixmap\fP"
Tells \fBFvwmAnimate\fP to use \fBpixmap\fP to draw with. This can be useful
if \fB*FvwmAnimate: Color\fP gives poor results.
^D
# NAME
**FvwmAnimate** - the fvwm animate module
# SYNOPSIS
Module FvwmAnimate \[ModuleAlias\]
\*FvwmAnimate: Color color
: Tells **FvwmAnimate** what color to draw with. The color is
\"XOR\'ed\" (exclusive ORed) onto the background.
\*FvwmAnimate: Pixmap pixmap
: Tells **FvwmAnimate** to use **pixmap** to draw with. This can be
useful if **\*FvwmAnimate: Color** gives poor results.
```
```
% pandoc -t markdown -f man
.IP "\[bu]"
hi
.IP "\[bu]"
there
^D
- hi
- there
```