@@ -35,7 +35,7 @@ import Text.Pandoc.Shared
35import Text.Pandoc.Readers.TeXMath
35import Text.Pandoc.Readers.TeXMath
36import Text.Printf ( printf )
36import Text.Printf ( printf )
37import Data.List ( isPrefixOf, intersperse, intercalate )
37import Data.List ( isPrefixOf, intersperse, intercalate )
38−import Text.PrettyPrint.HughesPJ hiding ( Str )
38+import Text.Pandoc.Pretty
39import Control.Monad.State
39import Control.Monad.State
41type Notes = [[Block]]
41type Notes = [[Block]]
@@ -52,27 +52,31 @@ pandocToMan opts (Pandoc (Meta title authors date) blocks) = do
52 titleText <- inlineListToMan opts title
52 titleText <- inlineListToMan opts title
53 authors' <- mapM (inlineListToMan opts) authors
53 authors' <- mapM (inlineListToMan opts) authors
54 date' <- inlineListToMan opts date
54 date' <- inlineListToMan opts date
55+ let colwidth = if writerWrapText opts
56+ then Just $ writerColumns opts
58+ let render' = render colwidth
55− let (cmdName, rest) = break (== ' ') $ render titleText
59+ let (cmdName, rest) = break (== ' ') $ render' titleText
56 let (title', section) = case reverse cmdName of
60 let (title', section) = case reverse cmdName of
57 (')':d:'(':xs) | d `elem` ['0'..'9'] ->
61 (')':d:'(':xs) | d `elem` ['0'..'9'] ->
58 (text (reverse xs), char d)
62 (text (reverse xs), char d)
59− xs -> (text (reverse xs), doubleQuotes empty)
63+ xs -> (text (reverse xs), doubleQuotes empty)
60 let description = hsep $
64 let description = hsep $
61 map (doubleQuotes . text . removeLeadingTrailingSpace) $
65 map (doubleQuotes . text . removeLeadingTrailingSpace) $
62 splitBy (== '|') rest
66 splitBy (== '|') rest
63 body <- blockListToMan opts blocks
67 body <- blockListToMan opts blocks
64 notes <- liftM stNotes get
68 notes <- liftM stNotes get
65 notes' <- notesToMan opts (reverse notes)
69 notes' <- notesToMan opts (reverse notes)
66− let main = render $ body $$ notes' $$ text ""
70+ let main = render' $ body $$ notes' $$ text ""
67 hasTables <- liftM stHasTables get
71 hasTables <- liftM stHasTables get
68 let context = writerVariables opts ++
72 let context = writerVariables opts ++
69 [ ("body", main)
73 [ ("body", main)
70− , ("title", render title')
74+ , ("title", render' title')
71− , ("section", render section)
75+ , ("section", render' section)
72− , ("date", render date')
76+ , ("date", render' date')
73− , ("description", render description) ] ++
77+ , ("description", render' description) ] ++
74 [ ("has-tables", "yes") | hasTables ] ++
78 [ ("has-tables", "yes") | hasTables ] ++
75− [ ("author", render a) | a <- authors' ]
79+ [ ("author", render' a) | a <- authors' ]
76 if writerStandalone opts
80 if writerStandalone opts
77 then return $ renderTemplate context $ writerTemplate opts
81 then return $ renderTemplate context $ writerTemplate opts
78 else return main
82 else return main
@@ -89,7 +93,7 @@ notesToMan opts notes =
89noteToMan :: WriterOptions -> Int -> [Block] -> State WriterState Doc
93noteToMan :: WriterOptions -> Int -> [Block] -> State WriterState Doc
90noteToMan opts num note = do
94noteToMan opts num note = do
91 contents <- blockListToMan opts note
95 contents <- blockListToMan opts note
92− let marker = text "\n.SS [" <> text (show num) <> char ']'
96+ let marker = cr <> text ".SS " <> brackets (text (show num))
93 return $ marker $$ contents
97 return $ marker $$ contents
95-- | Association list of characters to escape.
99-- | Association list of characters to escape.
@@ -136,14 +140,13 @@ blockToMan :: WriterOptions -- ^ Options
136 -> State WriterState Doc
140 -> State WriterState Doc
137blockToMan _ Null = return empty
141blockToMan _ Null = return empty
138blockToMan opts (Plain inlines) =
142blockToMan opts (Plain inlines) =
139− liftM vcat $ mapM (wrapIfNeeded opts (inlineListToMan opts)) $
143+ liftM vcat $ mapM (inlineListToMan opts) $ splitSentences inlines
140− splitSentences inlines
141blockToMan opts (Para inlines) = do
144blockToMan opts (Para inlines) = do
142− contents <- liftM vcat $ mapM (wrapIfNeeded opts (inlineListToMan opts)) $
145+ contents <- liftM vcat $ mapM (inlineListToMan opts) $
143 splitSentences inlines
146 splitSentences inlines
144 return $ text ".PP" $$ contents
147 return $ text ".PP" $$ contents
145blockToMan _ (RawHtml _) = return empty
148blockToMan _ (RawHtml _) = return empty
146−blockToMan _ HorizontalRule = return $ text $ ".PP\n * * * * *"
149+blockToMan _ HorizontalRule = return $ text ".PP" $$ text " * * * * *"
147blockToMan opts (Header level inlines) = do
150blockToMan opts (Header level inlines) = do
148 contents <- inlineListToMan opts inlines
151 contents <- inlineListToMan opts inlines
149 let heading = case level of
152 let heading = case level of
@@ -256,7 +259,7 @@ definitionListItemToMan opts (label, defs) = do
256 mapM (\item -> blockToMan opts item) rest
259 mapM (\item -> blockToMan opts item) rest
257 first' <- blockToMan opts first
260 first' <- blockToMan opts first
258 return $ first' $$ text ".RS" $$ rest' $$ text ".RE"
261 return $ first' $$ text ".RS" $$ rest' $$ text ".RE"
259− return $ text ".TP\n.B " <> labelText $+$ contents
262+ return $ text ".TP" $$ text ".B " <> labelText $$ contents
261-- | Convert list of Pandoc block elements to man.
264-- | Convert list of Pandoc block elements to man.
262blockListToMan :: WriterOptions -- ^ Options
265blockListToMan :: WriterOptions -- ^ Options
@@ -309,11 +312,12 @@ inlineToMan _ (Str str) = return $ text $ escapeString str
309inlineToMan opts (Math InlineMath str) = inlineListToMan opts $ readTeXMath str
312inlineToMan opts (Math InlineMath str) = inlineListToMan opts $ readTeXMath str
310inlineToMan opts (Math DisplayMath str) = do
313inlineToMan opts (Math DisplayMath str) = do
311 contents <- inlineListToMan opts $ readTeXMath str
314 contents <- inlineListToMan opts $ readTeXMath str
312− return $ text ".RS" $$ contents $$ text ".RE"
315+ return $ cr <> text ".RS" $$ contents $$ text ".RE"
313inlineToMan _ (TeX _) = return empty
316inlineToMan _ (TeX _) = return empty
314inlineToMan _ (HtmlInline _) = return empty
317inlineToMan _ (HtmlInline _) = return empty
315−inlineToMan _ (LineBreak) = return $ text "\n.PD 0\n.P\n.PD\n"
318+inlineToMan _ (LineBreak) = return $
319+ cr <> text ".PD 0" $$ text ".P" $$ text ".PD" <> cr
316−inlineToMan _ Space = return $ char ' '
320+inlineToMan _ Space = return space
317inlineToMan opts (Link txt (src, _)) = do
321inlineToMan opts (Link txt (src, _)) = do
318 linktext <- inlineListToMan opts txt
322 linktext <- inlineListToMan opts txt
319 let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
323 let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src