Man reader: improve treatment of .TH.

This should just add to metadata (title, date, section),
and not produce a level-1 header. (That might be done
in the template, depending on the output format.)
This commit is contained in:
John MacFarlane 2018-10-19 23:55:01 -07:00
parent eaef849536
commit c60ac7c9ab
2 changed files with 10 additions and 15 deletions

View file

@ -396,18 +396,14 @@ mcomment = msatisfy isMComment where
parseTitle :: PandocMonad m => ManParser m Blocks
parseTitle = do
(MMacro _ args) <- mmacro "TH"
if null args
then return mempty
else do
let mantitle = fst $ head args
modifyState (changeTitle mantitle)
return $ header 1 $ text mantitle
where
changeTitle title pst =
let meta = stateMeta pst
metaUp = Meta $ M.insert "title" (MetaString title) (unMeta meta)
in
pst {stateMeta = metaUp}
let adjustMeta =
case map fst args of
(x:y:z:_) -> setMeta "title" x . setMeta "section" y . setMeta "date" z
[x,y] -> setMeta "title" x . setMeta "section" y
[x] -> setMeta "title" x
[] -> id
modifyState $ \st -> st{ stateMeta = adjustMeta $ stateMeta st }
return mempty
parseSkippedContent :: PandocMonad m => ManParser m Blocks
parseSkippedContent = mempty <$ (mcomment <|> memptyLine)

View file

@ -1,6 +1,5 @@
Pandoc (Meta {unMeta = fromList [("title",MetaString "Pandoc Man tests")]})
[Header 1 ("",[],[]) [Str "Pandoc",Space,Str "Man",Space,Str "tests"]
,Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "set",Space,Str "of",Space,Str "tests",Space,Str "for",Space,Str "pandoc."]
Pandoc (Meta {unMeta = fromList [("date",MetaString "Oct 17, 2018"),("section",MetaString ""),("title",MetaString "Pandoc Man tests")]})
[Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "set",Space,Str "of",Space,Str "tests",Space,Str "for",Space,Str "pandoc."]
,Para [Str "*",Space,Str "*",Space,Str "*",Space,Str "*",Space,Str "*"]
,Header 1 ("",[],[]) [Str "Headers"]
,Header 1 ("",[],[]) [Str "Level",Space,Str "1"]