summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README21
-rw-r--r--src/Text/Pandoc/Writers/Man.hs17
2 files changed, 24 insertions, 14 deletions
diff --git a/README b/README
index 409270163..c58818448 100644
--- a/README
+++ b/README
@@ -645,16 +645,25 @@ title block appears in the document, the title prefix will be used by
itself as the HTML title.
The man page writer extracts a title, man page section number, and
-other header and footer information from the title line. These should
-be separated by pipe characters (`|`), as follows:
+other header and footer information from the title line. The title
+is assumed to be the first word on the title line, which may optionally
+end with a (single-digit) section number in parentheses. (There should
+be no space between the title and the parentheses.) Anything after
+this is assumed to be additional footer and header text. A single pipe
+character (`|`) should be used to separate the footer text from the header
+text. Thus,
- % title | section number (1-9) | footer left | header center
+ % pandoc(1)
-For example,
+will yield a man page with the title `pandoc` and section 1.
- % pandoc | 1 | Pandoc User Manuals | Version 4.0
+ % pandoc(1) Pandoc User Manuals
-The middle of the man page footer is used for the date.
+will also have "Pandoc User Manuals" in the footer.
+
+ % pandoc(1) Pandoc User Manuals | Version 4.0
+
+will also have "Version 4.0" in the header.
Markdown in HTML blocks
-----------------------
diff --git a/src/Text/Pandoc/Writers/Man.hs b/src/Text/Pandoc/Writers/Man.hs
index f0cc3c707..318fb056a 100644
--- a/src/Text/Pandoc/Writers/Man.hs
+++ b/src/Text/Pandoc/Writers/Man.hs
@@ -69,15 +69,16 @@ metaToMan :: WriterOptions -- ^ Options, including Man header
-> Meta -- ^ Meta with bibliographic information
-> State WriterState (Doc, Doc)
metaToMan options (Meta title authors date) = do
- titleParts <- mapM (inlineListToMan options) $ map normalizeSpaces $
- splitBy (Str "|") title
- let titleParts' = map doubleQuotes titleParts
- let (title', section, rest) = case titleParts' of
- [] -> (text "\"\"", text "\"\"", [])
- [x] -> (x, text "\"\"", [])
- (x:y:zs) -> (x, y, zs)
+ titleText <- inlineListToMan options title
+ let (cmdName, rest) = break (== ' ') $ render titleText
+ let (title', section) = case reverse cmdName of
+ (')':d:'(':xs) | d `elem` ['0'..'9'] ->
+ (text (reverse xs), text [d])
+ xs -> (text (reverse xs), empty)
+ let extras = map (doubleQuotes . text . removeLeadingTrailingSpace) $
+ splitBy '|' rest
let head = (text ".TH") <+> title' <+> section <+>
- doubleQuotes (text date) <+> hsep rest
+ doubleQuotes (text date) <+> hsep extras
let foot = case length authors of
0 -> text $ ""
1 -> text $ ".SH AUTHOR\n" ++ joinWithSep ", " authors