Groff reader: got \f[] working properly.

This commit is contained in:
John MacFarlane 2018-10-25 00:16:35 -07:00
parent 718a947f7d
commit 02e515cada
2 changed files with 8 additions and 4 deletions

View file

@ -105,7 +105,8 @@ singleTok :: ManToken -> ManTokens
singleTok t = ManTokens (Seq.singleton t)
data RoffState = RoffState { customMacros :: M.Map String ManTokens
, lastFont :: FontSpec
, prevFont :: FontSpec
, currentFont :: FontSpec
} deriving Show
instance Default RoffState where
@ -117,7 +118,8 @@ instance Default RoffState where
, ("lq", "\x201C")
, ("rq", "\x201D")
, ("R", "\x00AE") ]
, lastFont = defaultFontSpec
, prevFont = defaultFontSpec
, currentFont = defaultFontSpec
}
type ManLexer m = ParserT [Char] RoffState m
@ -261,7 +263,8 @@ escFont = do
, ($ defaultFontSpec) <$> letterFontKind
, lettersFont
]
modifyState $ \st -> st{ lastFont = font }
modifyState $ \st -> st{ prevFont = currentFont st
, currentFont = font }
return [Font font]
lettersFont :: PandocMonad m => ManLexer m FontSpec
@ -271,7 +274,7 @@ lettersFont = try $ do
skipMany letter
char ']'
if null fs
then lastFont <$> getState
then prevFont <$> getState
else return $ foldr ($) defaultFontSpec fs
letterFontKind :: PandocMonad m => ManLexer m (FontSpec -> FontSpec)

View file

@ -180,6 +180,7 @@ linePartsToInlines = go False
go :: Bool -> [LinePart] -> Inlines
go _ [] = mempty
go mono (MacroArg _:xs) = go mono xs -- shouldn't happen
go mono (RoffStr s : RoffStr t : xs) = go mono (RoffStr (s <> t):xs)
go mono (RoffStr s : xs)
| mono = code s <> go mono xs
| otherwise = text s <> go mono xs