diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2013-06-27 19:32:28 -0700 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2013-06-27 19:32:28 -0700 |
commit | dd96213c055d72b65e0c70552d9b4e3a824ba3ee (patch) | |
tree | b7556b66e207257093a4f9653fa9f1c96a995844 /src/Text/Pandoc | |
parent | 82e46bf3852b776defab85f3347115260d332250 (diff) | |
download | pandoc-dd96213c055d72b65e0c70552d9b4e3a824ba3ee.tar.gz |
Man writer: give more fine-grained control in template.
Now the `title`, `section`, `header`, and `footer` can all be set
individually in metadata. The `description` variable has been
removed.
Quotes have been added so that spaces are allowed in the title.
If you have a title that begins
COMMAND(1) footer here | header here
pandoc will parse it as before into a title, section, header, and
footer. But you can also specify these elements explicitly.
Closes #885.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Writers/Man.hs | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Writers/Man.hs b/src/Text/Pandoc/Writers/Man.hs index b417565ce..31c044ba4 100644 --- a/src/Text/Pandoc/Writers/Man.hs +++ b/src/Text/Pandoc/Writers/Man.hs @@ -39,6 +39,7 @@ import Data.List ( isPrefixOf, intersperse, intercalate ) import Text.Pandoc.Pretty import Text.Pandoc.Builder (deleteMeta) import Control.Monad.State +import Data.Char ( isDigit ) type Notes = [[Block]] data WriterState = WriterState { stNotes :: Notes @@ -56,13 +57,20 @@ pandocToMan opts (Pandoc meta blocks) = do else Nothing let render' = render colwidth titleText <- inlineListToMan opts $ docTitle meta - let (cmdName, rest) = break (== ' ') $ render' titleText - let (title', section) = case reverse cmdName of - (')':d:'(':xs) | d `elem` ['0'..'9'] -> - (reverse xs, [d]) - xs -> (reverse xs, "\"\"") - let description = hsep $ - map (doubleQuotes . text . trim) $ splitBy (== '|') rest + let title' = render' titleText + let setFieldsFromTitle = + case break (== ' ') title' of + (cmdName, rest) -> case reverse cmdName of + (')':d:'(':xs) | isDigit d -> + setField "title" (reverse xs) . + setField "section" [d] . + case splitBy (=='|') rest of + (ft:hds) -> + setField "footer" (trim ft) . + setField "header" + (trim $ concat hds) + [] -> id + _ -> setField "title" title' metadata <- metaToJSON (fmap (render colwidth) . blockListToMan opts) (fmap (render colwidth) . inlineListToMan opts) @@ -73,9 +81,7 @@ pandocToMan opts (Pandoc meta blocks) = do let main = render' $ body $$ notes' $$ text "" hasTables <- liftM stHasTables get let context = setField "body" main - $ setField "title" title' - $ setField "section" section - $ setField "description" (render' description) + $ setFieldsFromTitle $ setField "has-tables" hasTables $ foldl (\acc (x,y) -> setField x y acc) metadata (writerVariables opts) |